blyon1995 Copilot commited on
Commit
5955ca5
·
1 Parent(s): 3e0294c

fix: inline code and code blocks render empty (marked v12 API)

Browse files

marked 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>

Files changed (1) hide show
  1. 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.code = function (token) {
64
- const code = token.text || '';
65
- const lang = (token.lang || '').split(/[\s.]/)[0].toLowerCase();
 
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 (token) {
81
- const text = token.text || '';
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) {