Skip to content

Commit

Permalink
Merge pull request #380 from dkasak/fenced-code-block-additional-tag
Browse files Browse the repository at this point in the history
When rendering fenced code blocks, add `language-LANG` class as well.
  • Loading branch information
nicholasserra authored Dec 18, 2020
2 parents b9e3ec7 + de877aa commit cf9c53d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit cf9c53d

Please sign in to comment.