fix: inline code and code blocks render empty (marked v12 API)
Browse filesmarked v12 uses the legacy renderer function signature:
code(code, lang, escaped) — three string/bool args
codespan(code) — one string arg
The previous code treated the first argument as a token object and
accessed .text / .lang properties, which are undefined on a string,
causing both inline code and fenced code blocks to render as empty
elements (visible capsule/box with no text content).
Fixed both renderers to use the correct positional arguments.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- src/markdown.js +6 -6
src/markdown.js
CHANGED
|
@@ -60,9 +60,10 @@ hljs.registerLanguage('yml', langYaml);
|
|
| 60 |
|
| 61 |
const renderer = new marked.Renderer();
|
| 62 |
|
| 63 |
-
renderer
|
| 64 |
-
|
| 65 |
-
|
|
|
|
| 66 |
let highlighted;
|
| 67 |
try {
|
| 68 |
if (lang && hljs.getLanguage(lang)) {
|
|
@@ -77,9 +78,8 @@ renderer.code = function (token) {
|
|
| 77 |
return `<div class="code-block-wrapper">${langLabel}<button class="copy-btn" aria-label="Copy code">Copy</button><pre><code class="hljs language-${lang || 'plaintext'}">${highlighted}</code></pre></div>`;
|
| 78 |
};
|
| 79 |
|
| 80 |
-
renderer.codespan = function (
|
| 81 |
-
|
| 82 |
-
return `<code>${escapeHtml(text)}</code>`;
|
| 83 |
};
|
| 84 |
|
| 85 |
function escapeHtml(str) {
|
|
|
|
| 60 |
|
| 61 |
const renderer = new marked.Renderer();
|
| 62 |
|
| 63 |
+
// marked v12 uses the legacy renderer API: code(code, lang, escaped) and codespan(code)
|
| 64 |
+
renderer.code = function (code, lang, _escaped) {
|
| 65 |
+
code = code || '';
|
| 66 |
+
lang = ((lang || '').split(/[\s.]/)[0] || '').toLowerCase();
|
| 67 |
let highlighted;
|
| 68 |
try {
|
| 69 |
if (lang && hljs.getLanguage(lang)) {
|
|
|
|
| 78 |
return `<div class="code-block-wrapper">${langLabel}<button class="copy-btn" aria-label="Copy code">Copy</button><pre><code class="hljs language-${lang || 'plaintext'}">${highlighted}</code></pre></div>`;
|
| 79 |
};
|
| 80 |
|
| 81 |
+
renderer.codespan = function (code) {
|
| 82 |
+
return `<code>${escapeHtml(code || '')}</code>`;
|
|
|
|
| 83 |
};
|
| 84 |
|
| 85 |
function escapeHtml(str) {
|