`;
md.renderer.rules.footnote_anchor=(ts,i,o,e)=>` ↩`;
md.core.ruler.disable(['replacements','smartquotes']);
// Separate typographic symbols from text just as Kramdown's AST does.
// This matters when its GitHub-reference plugin wraps one text node in a span.
const typographyBoundary='\uE000';
md.renderer.rules.text=(ts,i)=>escape(ts[i].content).replaceAll(typographyBoundary,'');
md.core.ruler.after('inline','kramdown_typography',state=>{
const symbol=s=>typographyBoundary+s+typographyBoundary;
function visit(tokens){for(const token of tokens){
if(token.type==='text')token.content=token.content.replace(/\.\.\./g,()=>symbol('…')).replace(/---/g,()=>symbol('—')).replace(/--/g,()=>symbol('–')).replace(/["']/g,(q,i,s)=>{
const prev=s[i-1]||'',next=s[i+1]||'';
const close=(prev&&!/[\s\\\[{(\-]/.test(prev))||!next||/\s/.test(next)||next==='s'&&!/\w/.test(s[i+2]||'');
return symbol(q==='"'?(close?'”':'“'):(close?'’':'‘'));
});
if(token.children)visit(token.children);
}}visit(state.tokens);
});
// Kramdown accepts emphasis delimiters next to CJK/punctuation where CommonMark differs.
md.inline.ruler.before('emphasis','kramdown_emphasis',(state,silent)=>{
if(state.src[state.pos]!=='*')return false;
const width=state.src[state.pos+1]==='*'?2:1,marker='*'.repeat(width),start=state.pos+width;
if(/\s/.test(state.src[start]||' '))return false;
let end=state.src.indexOf(marker,start);
while(end>=0&&(/\s/.test(state.src[end-1])||(width===1&&(state.src[end+1]==='*'||state.src[end-1]==='*'))))end=state.src.indexOf(marker,end+width);
if(end<0)return false;
if(!silent){const tag=width===2?'strong':'em';state.push(tag+'_open',tag,1);state.md.inline.parse(state.src.slice(start,end),state.md,state.env,state.tokens);state.push(tag+'_close',tag,-1);}
state.pos=end+width;return true;
});
md.renderer.rules.code_inline=(ts,i)=>`${escape(ts[i].content)}`;
md.renderer.rules.fence=(ts,i)=>{
const t=ts[i],lang=t.info.trim().split(/\s/)[0]||'plaintext';
const key=lang+':'+crypto.createHash('sha256').update(t.content).digest('hex');
let content=codeCache[key]??escape(t.content);
if(!Object.hasOwn(codeCache,key)&&hljs.getLanguage(lang)&&lang!=='plaintext')content=hljs.highlight(t.content,{language:lang,ignoreIllegals:true}).value.replace(/class="hljs-([^" ]+)(?: [^"]*)?"/g,(_,name)=>`class="${({keyword:'k',built_in:'nb',type:'kt',literal:'kc',number:'mi',string:'s',comment:'c',title:'nf',attr:'na',variable:'nv',meta:'cp',params:'n',symbol:'ss',regexp:'sr',punctuation:'p',operator:'o'})[name]||'n'}"`);
return `
${content}
\n`;
};
function relative(input){
if(typeof input!=='string')return input;
const match=input.match(/^([^?#]*)([?#][\s\S]*)?$/),base=match[1];
return (model.urlMap.get(base)||base)+(match[2]||'');
}
function render(source){
let tocInline=false;
source=String(source??'').replace(//g,'').replace(/^(\s*\d+)\)/gm,'$1\\)').replace(/\* This will become a table of contents[\s\S]*?\{:\s*toc\s*\}/g,()=>{tocInline=true;return '';});
source=source.replace(/^(\d+\. [^\n]*\n)(```[^\n]*\n[\s\S]*?\n```)/gm,(_,item,code)=>item+code.replace(/\n/,' hmcl-tight-li\n').split('\n').map(line=>' '+line).join('\n'));
// Kramdown block attribute lists attach to the preceding block.
source=source.replace(/^\{:\s*([^}]+)\}\s*$/gm,(_,a)=>`\n\n`);
let result=md.render(source);
const $=html(result,null,false),ids=new Map();
$('table[data-hmcl-table]').removeAttr('data-hmcl-table').find('td').each((_,e)=>{if(!$(e).contents().length)$(e).html(' ');});
$('h1[id=""],h2[id=""],h3[id=""],h4[id=""],h5[id=""],h6[id=""]').removeAttr('id');
$('li > p:first-child').each((_,e)=>{const p=$(e);if(p.siblings('[data-hmcl-tight-list]').length&&p.parent().children('p').length===1)p.replaceWith(p.html());});
$('[data-hmcl-tight-list]').removeAttr('data-hmcl-tight-list');
if(/