@mdit/plugin-stylize
Version:
stylize plugin for MarkdownIt
3 lines (2 loc) • 717 B
JavaScript
const p=(n,r,g=[])=>{for(let t=1,i=n.length;t<i-1;t++){const s=n[t],{content:o,type:a}=s;if(a!=="text"||g.includes(o))continue;const f=r.find(({matcher:e})=>typeof e=="string"?e===o:e.test(o)),c=n[t-1],l=n[t+1];if(f&&c.tag===l.tag&&c.nesting===1&&l.nesting===-1){const e=f.replacer({tag:c.tag,content:s.content,attrs:Object.fromEntries(c.attrs??[])});e&&(c.tag=l.tag=e.tag,c.attrs=Object.entries(e.attrs),s.content=e.content),t+=2}}},h=(n,r={})=>{if(r.config?.length==0)return;const g=({env:t,tokens:i})=>{const s=r.localConfigGetter?.(t)??[];i.forEach(({type:o,children:a})=>{o==="inline"&&a&&p(a,[...s,...r.config??[]])})};n.core.ruler.push("stylize_tag",g)};export{h as stylize};
//# sourceMappingURL=index.js.map