@helping-ai-workflow/md2doc 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/md2doc.js +13 -5
- package/package.json +1 -1
package/lib/md2doc.js
CHANGED
|
@@ -315,13 +315,11 @@ ${itemsHtml}
|
|
|
315
315
|
const r = spawnSync('dot', ['-Tsvg'], { input: code, encoding: 'utf8', timeout: 10000 });
|
|
316
316
|
if (r.status === 0) {
|
|
317
317
|
// Strip XML declaration / DOCTYPE; keep only the <svg> element.
|
|
318
|
-
//
|
|
319
|
-
//
|
|
318
|
+
// Keep intrinsic width/height so small diagrams render at their natural
|
|
319
|
+
// size; max-width:100% in CSS still shrinks oversized ones to container.
|
|
320
320
|
const svg = r.stdout
|
|
321
321
|
.replace(/<\?xml[^>]*\?>/g, '')
|
|
322
322
|
.replace(/<!DOCTYPE[^>]*>/g, '')
|
|
323
|
-
.replace(/(<svg\b[^>]*?)\s+width="[^"]*"/i, '$1')
|
|
324
|
-
.replace(/(<svg\b[^>]*?)\s+height="[^"]*"/i, '$1')
|
|
325
323
|
.trim();
|
|
326
324
|
return `\n<div class="graphviz">${svg}</div>\n`;
|
|
327
325
|
}
|
|
@@ -414,9 +412,19 @@ ${itemsHtml}
|
|
|
414
412
|
marked.setOptions({ gfm: true, breaks: false, renderer });
|
|
415
413
|
|
|
416
414
|
// Pre-process non-standard inline syntax before marked parses
|
|
415
|
+
const escAttr = (s) => String(s)
|
|
416
|
+
.replace(/&/g, '&')
|
|
417
|
+
.replace(/</g, '<')
|
|
418
|
+
.replace(/>/g, '>')
|
|
419
|
+
.replace(/"/g, '"');
|
|
417
420
|
const mdPre = md
|
|
418
421
|
.replace(/\^([^^]+)\^/g, '<sup>$1</sup>') // ^a^ → <sup>a</sup>
|
|
419
|
-
.replace(/~([^~]+)~/g, '<sub>$1</sub>')
|
|
422
|
+
.replace(/~([^~]+)~/g, '<sub>$1</sub>') // ~a~ → <sub>a</sub>
|
|
423
|
+
.replace(/\[\[([^\]\n]+)\]\]/g, (_, inner) => { // [[ref-id, §sub]] → clickable citation
|
|
424
|
+
const body = inner.trim();
|
|
425
|
+
const slug = body.split(',', 1)[0].trim();
|
|
426
|
+
return `<a href="#${escAttr(slug)}">[${escAttr(body)}]</a>`;
|
|
427
|
+
});
|
|
420
428
|
|
|
421
429
|
bodyHtml = marked.parse(mdPre);
|
|
422
430
|
serializedSections = JSON.stringify(
|