Skip to content

Commit 96fe78a

Browse files
authored
Merge pull request #4006 from ralfhandl/build-script/improved-code-blocks
Build script: improved code blocks
2 parents 0f0f3ee + 2838d3e commit 96fe78a

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

scripts/md2html/md2html.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ const md = require('markdown-it')({
3636
highlight: function (str, lang) {
3737
if (lang && hljs.getLanguage(lang)) {
3838
try {
39-
return '<pre class="nohighlight"><code>' +
39+
return '<pre class="nohighlight" tabindex="0"><code>' +
4040
hljs.highlight(str, { language: lang }).value +
4141
'</code></pre>';
4242
} catch (__) { }
4343
}
4444

45-
return '<pre class="highlight '+lang+'"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
45+
return '<pre class="highlight '+lang+'" tabindex="0"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
4646
}
4747
});
4848

@@ -216,7 +216,6 @@ for (let l in lines) {
216216
// recognize code blocks
217217
if (line.startsWith('```')) {
218218
inCodeBlock = !inCodeBlock;
219-
line += '\n'; // fixes formatting of first line of syntax-highlighted blocks
220219
}
221220

222221
if (line.indexOf('<a name="')>=0) {

tests/md2html/fixtures/basic-new.html

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
<p>Text for first section</p>
88
<section><h2>Heading 3</h2>
99
<p>Text for first subsection</p>
10-
<pre class="nohighlight"><code>
11-
<span class="hljs-punctuation">{</span>
10+
<pre class="nohighlight" tabindex="0"><code><span class="hljs-punctuation">{</span>
1211
<span class="hljs-attr">&quot;foo&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span>
1312
<span class="hljs-punctuation">}</span>
1413
</code></pre>
15-
<pre class="nohighlight"><code>
16-
text/plain
14+
<pre class="nohighlight" tabindex="0"><code>text/plain
1715
</code></pre>
18-
<pre class="highlight "><code>
19-
no language
16+
<pre class="highlight " tabindex="0"><code>no language
2017
</code></pre>
2118
<table>
2219
<thead>

0 commit comments

Comments
 (0)