Skip to content

Commit cf9c53d

Browse files
Merge pull request #380 from dkasak/fenced-code-block-additional-tag
When rendering fenced code blocks, add `language-LANG` class as well.
2 parents b9e3ec7 + de877aa commit cf9c53d

File tree

5 files changed

+7
-19
lines changed

5 files changed

+7
-19
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## python-markdown2 2.4.0 (not yet released)
44

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

78

89
## python-markdown2 2.3.10

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ Gareth Simpson (github.com/xurble)
4747
Kat Hagan (github.com/codebykat)
4848
Stɑrry Shivɑm (github.com/starry69)
4949
André Nasturas (github.com/andrenasturas)
50+
Denis Kasak (github.com/dkasak)

lib/markdown2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ def unhash_code(codeblock):
18841884
pre_class_str = self._html_class_str_from_tag("pre")
18851885

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

test/tm-cases/highlightjs_lang.html

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
<pre><code class="cpp">here is some cpp code
1+
<pre><code class="cpp language-cpp">here is some cpp code
22
</code></pre>
33

4-
<pre><code class="lang-cpp">some lang-cpp code
5-
</code></pre>
6-
7-
<pre><code class="language-cpp">and some language-cpp code
8-
</code></pre>
9-
10-
<pre><code class="nohighlight">some code without highlighting
4+
<pre><code class="nohighlight language-nohighlight">some code without highlighting
115
</code></pre>
126

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

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

17-
<pre><code class="cpp">
11+
<pre><code class="cpp language-cpp">
1812
</code></pre>
1913

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

22-
<pre><code class="cpp"> is indentation maintained?
16+
<pre><code class="cpp language-cpp"> is indentation maintained?
2317
</code></pre>

test/tm-cases/highlightjs_lang.text

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22
here is some cpp code
33
```
44

5-
```lang-cpp
6-
some lang-cpp code
7-
```
8-
9-
```language-cpp
10-
and some language-cpp code
11-
```
12-
135
```nohighlight
146
some code without highlighting
157
```

0 commit comments

Comments
 (0)