Skip to content

Commit

Permalink
Html renderer: don't add language- to code block class...
Browse files Browse the repository at this point in the history
if the info string already starts with `language-`.
Closes #277.
  • Loading branch information
jgm committed Jan 22, 2024
1 parent 9f548fe commit c7aef33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/render/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ function code_block(node) {
var info_words = node.info ? node.info.split(/\s+/) : [],
attrs = this.attrs(node);
if (info_words.length > 0 && info_words[0].length > 0) {
attrs.push(["class", "language-" + this.esc(info_words[0])]);
var cls = this.esc(info_words[0]);
if (!/^language-/.exec(cls)) {
cls = "language-" + cls;
}
attrs.push(["class", cls]);
}
this.cr();
this.tag("pre");
Expand Down
16 changes: 16 additions & 0 deletions test/regression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -455,3 +455,19 @@ _*xx-_-
<p><em>*__-</em>-</p>
<p><em>*xx-</em>-</p>
````````````````````````````````

#277:
```````````````````````````````` example
```language-r
x <- 1
```

```r
x <- 1
```
.
<pre><code class="language-r">x &lt;- 1
</code></pre>
<pre><code class="language-r">x &lt;- 1
</code></pre>
````````````````````````````````

0 comments on commit c7aef33

Please sign in to comment.