Fix ordered list bullets and implement footnotes
- CSS: global reset `ul, ol { list-style: none }` was killing all bullets
and numbers. Add list-style: disc/decimal back on .lt-markdown ul/ol.
Remove duplicate ol rules.
- Footnotes: implement [^label] / [^label]: syntax. Uses placeholder
approach (like code blocks) so <sup> tags aren't HTML-escaped. Renders
inline superscript refs + numbered footnote block at bottom with
back-links.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,23 @@
|
||||
function parseMarkdown(markdown) {
|
||||
if (!markdown) return '';
|
||||
|
||||
// Footnotes — collect definitions and mark references with placeholders
|
||||
// (must happen before HTML escaping so <sup> tags don't get escaped)
|
||||
const footnotes = {};
|
||||
const footnoteOrder = [];
|
||||
const fnRefs = [];
|
||||
markdown = markdown.replace(/^\[\^([^\]]+)\]:\s+(.+)$/gm, function(_, label, text) {
|
||||
footnotes[label] = text;
|
||||
return '';
|
||||
});
|
||||
markdown = markdown.replace(/\[\^([^\]]+)\]/g, function(_, label) {
|
||||
if (!footnotes[label]) return '[^' + label + ']';
|
||||
if (!footnoteOrder.includes(label)) footnoteOrder.push(label);
|
||||
const n = footnoteOrder.indexOf(label) + 1;
|
||||
fnRefs.push({ label, n });
|
||||
return '%%FNREF' + (fnRefs.length - 1) + '%%';
|
||||
});
|
||||
|
||||
let html = markdown;
|
||||
|
||||
// Escape HTML first to prevent XSS
|
||||
@@ -122,11 +139,28 @@ function parseMarkdown(markdown) {
|
||||
html = html.replace('%%INLINECODE' + i + '%%', code);
|
||||
});
|
||||
|
||||
// Restore footnote reference placeholders
|
||||
fnRefs.forEach(function(ref, i) {
|
||||
html = html.replace('%%FNREF' + i + '%%',
|
||||
'<sup class="fn-ref"><a href="#fn-' + ref.label + '" id="fnref-' + ref.label + '">[' + ref.n + ']</a></sup>');
|
||||
});
|
||||
|
||||
// Wrap in paragraph if not already wrapped
|
||||
if (!html.startsWith('<')) {
|
||||
html = '<p>' + html + '</p>';
|
||||
}
|
||||
|
||||
// Append footnote definitions block
|
||||
if (footnoteOrder.length) {
|
||||
html += '<hr class="fn-hr"><ol class="fn-list">';
|
||||
footnoteOrder.forEach(function(label, i) {
|
||||
html += '<li id="fn-' + label + '" class="fn-item">' +
|
||||
parseMarkdown(footnotes[label]).replace(/<\/?p>/g, '') +
|
||||
' <a href="#fnref-' + label + '" class="fn-back">↩</a></li>';
|
||||
});
|
||||
html += '</ol>';
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user