Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When rendering fenced code blocks, add language-LANG class as well. #380

Merged
merged 2 commits into from Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -3,6 +3,7 @@
## python-markdown2 2.4.0 (not yet released)

- [pull #377] Fixed bug breaking strings elements in metadata lists
- [pull #380] When rendering fenced code blocks, also add the `language-LANG` class


## python-markdown2 2.3.10
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -47,3 +47,4 @@ Gareth Simpson (github.com/xurble)
Kat Hagan (github.com/codebykat)
Stɑrry Shivɑm (github.com/starry69)
André Nasturas (github.com/andrenasturas)
Denis Kasak (github.com/dkasak)
2 changes: 1 addition & 1 deletion lib/markdown2.py
Expand Up @@ -1884,7 +1884,7 @@ def unhash_code(codeblock):
pre_class_str = self._html_class_str_from_tag("pre")

if "highlightjs-lang" in self.extras and lexer_name:
code_class_str = ' class="%s"' % lexer_name
code_class_str = ' class="%s language-%s"' % (lexer_name, lexer_name)
else:
code_class_str = self._html_class_str_from_tag("code")

Expand Down
14 changes: 4 additions & 10 deletions test/tm-cases/highlightjs_lang.html
@@ -1,23 +1,17 @@
<pre><code class="cpp">here is some cpp code
<pre><code class="cpp language-cpp">here is some cpp code
</code></pre>

<pre><code class="lang-cpp">some lang-cpp code
</code></pre>

<pre><code class="language-cpp">and some language-cpp code
</code></pre>

<pre><code class="nohighlight">some code without highlighting
<pre><code class="nohighlight language-nohighlight">some code without highlighting
</code></pre>

<p>That's using the <em>fenced-code-blocks</em> and <em>highlightjs-lang</em> extra.</p>

<p>Here is an empty one (just to check):</p>

<pre><code class="cpp">
<pre><code class="cpp language-cpp">
</code></pre>

<p>Here is one at the end of the file:</p>

<pre><code class="cpp"> is indentation maintained?
<pre><code class="cpp language-cpp"> is indentation maintained?
</code></pre>
8 changes: 0 additions & 8 deletions test/tm-cases/highlightjs_lang.text
Expand Up @@ -2,14 +2,6 @@
here is some cpp code
```

```lang-cpp
some lang-cpp code
```

```language-cpp
and some language-cpp code
```

```nohighlight
some code without highlighting
```
Expand Down