fuc-new/doc/node_modules/@mdit/plugin-figure/lib/index.js
hellcat 6adbc04d4b 1
2025-10-03 17:17:08 +08:00

3 lines
1.1 KiB
JavaScript

const u=(t,l)=>{t.attrs=t.attrs?.filter(([o])=>o!==l)??null},d=t=>{const l=t.attrs?.find(([o])=>o==="title")?.[1];return l?(u(t,"title"),l):t.content},k=(t,l={})=>{const o=n=>{for(let i=1,{length:s}=n.tokens;i<s-1;i++){const e=n.tokens[i];if(e.type!=="inline"||!e.children||e.children.length!==1&&e.children.length!==3||e.children.length===1&&e.children[0].type!=="image")continue;if(e.children.length===3){const[a,g,f]=e.children;if(a.type!=="link_open"||g.type!=="image"||f.type!=="link_close")continue}if(n.tokens[i-1].type!=="paragraph_open"||n.tokens[i+1].type!=="paragraph_close")continue;const r=n.tokens[i-1];r.type="figure_open",r.tag="figure",n.tokens[i+1].type="figure_close",n.tokens[i+1].tag="figure";const c=e.children.length===1?e.children[0]:e.children[1],h=d(c),[p]=t.parseInline(h,n.env);e.children.push(new n.Token("figcaption_open","figcaption",1)),e.children.push(...p.children??[]),e.children.push(new n.Token("figcaption_close","figcaption",-1)),l.focusable!==!1&&c.attrPush(["tabindex","0"])}};t.core.ruler.before("linkify","figure",o)};export{k as figure};
//# sourceMappingURL=index.js.map