Skip to content

Commit

Permalink
Merge pull request #4006 from ralfhandl/build-script/improved-code-bl…
Browse files Browse the repository at this point in the history
…ocks

Build script: improved code blocks
  • Loading branch information
ralfhandl committed Aug 15, 2024
2 parents 0f0f3ee + 2838d3e commit 96fe78a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 2 additions & 3 deletions scripts/md2html/md2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ const md = require('markdown-it')({
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return '<pre class="nohighlight"><code>' +
return '<pre class="nohighlight" tabindex="0"><code>' +
hljs.highlight(str, { language: lang }).value +
'</code></pre>';
} catch (__) { }
}

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

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

if (line.indexOf('<a name="')>=0) {
Expand Down
9 changes: 3 additions & 6 deletions tests/md2html/fixtures/basic-new.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
<p>Text for first section</p>
<section><h2>Heading 3</h2>
<p>Text for first subsection</p>
<pre class="nohighlight"><code>
<span class="hljs-punctuation">{</span>
<pre class="nohighlight" tabindex="0"><code><span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;foo&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span>
<span class="hljs-punctuation">}</span>
</code></pre>
<pre class="nohighlight"><code>
text/plain
<pre class="nohighlight" tabindex="0"><code>text/plain
</code></pre>
<pre class="highlight "><code>
no language
<pre class="highlight " tabindex="0"><code>no language
</code></pre>
<table>
<thead>
Expand Down

0 comments on commit 96fe78a

Please sign in to comment.