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

3 lines
1.4 KiB
JavaScript

const R=(p,u)=>{if(typeof u!="object"||!u.name)throw new Error("[@mdit/plugin-container]: 'name' option is required.");const{name:n,marker:c=":",validate:$=e=>e.trim().split(" ",2)[0]===n,openRender:g=(e,t,l,k,a)=>(e[t].attrJoin("class",n),a.renderToken(e,t,l)),closeRender:C=(e,t,l,k,a)=>a.renderToken(e,t,l)}=u,M=c[0],i=c.length,I=(e,t,l,k)=>{const a=e.bMarks[t]+e.tShift[t],_=e.eMarks[t],d=e.sCount[t];if(M!==e.src[a])return!1;let r=a+1;for(;r<=_&&c[(r-a)%i]===e.src[r];)r++;const b=Math.floor((r-a)/i);if(b<3)return!1;r-=(r-a)%i;const m=c.repeat(b),T=e.src.slice(r,_);if(!$(T,m))return!1;if(k)return!0;let o=t+1,x=!1;for(;o<l;o++){const s=e.bMarks[o]+e.tShift[o],h=e.eMarks[o];if(s<h&&e.sCount[o]<d)break;if(e.sCount[o]===d&&M===e.src[s]){for(r=s+1;r<=h&&c[(r-s)%i]===e.src[r];r++);if(Math.floor((r-s)/i)>=b&&(r-=(r-s)%i,r=e.skipSpaces(r),r>=h)){x=!0;break}}}const S=e.parentType,v=e.lineMax,w=e.blkIndent;e.parentType="container",e.lineMax=o,e.blkIndent=d;const f=e.push(`container_${n}_open`,"div",1);f.markup=m,f.block=!0,f.info=T,f.map=[t,o],e.md.block.tokenize(e,t+1,o);const y=e.push(`container_${n}_close`,"div",-1);return y.markup=m,y.block=!0,e.parentType=S,e.lineMax=v,e.blkIndent=w,e.line=o+(x?1:0),!0};p.block.ruler.before("fence",`container_${n}`,I,{alt:["paragraph","reference","blockquote","list"]}),p.renderer.rules[`container_${n}_open`]=g,p.renderer.rules[`container_${n}_close`]=C};export{R as container};
//# sourceMappingURL=index.js.map