Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build script: improved code blocks #4006

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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