@mdit/plugin-attrs 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/browser.js CHANGED
@@ -1,3 +1,3 @@
1
- const u=(e,t)=>{t&&e.forEach(([s,n])=>{switch(s){case"class":t.attrJoin("class",n);break;case"css-module":t.attrJoin("css-module",n);break;default:t.attrPush([s,n])}})},_=".",x="#",v=/[^\t\n\f />"'=]/,O=" ",E="=",d=(e,t,{left:s,right:n,allowed:o})=>{let i="",l="",r=!0,c=!1;const f=[];for(let h=t+s.length;h<e.length;h++){if(e.slice(h,h+n.length)===n){i!==""&&f.push([i,l]);break}const a=e.charAt(h);if(a===E&&r){r=!1;continue}if(a===_&&i===""){e.charAt(h+1)===_?(i="css-module",h++):i="class",r=!1;continue}if(a===x&&i===""){i="id",r=!1;continue}if(a==='"'&&l===""&&!c){c=!0;continue}if(a==='"'&&c){c=!1;continue}if(a===O&&!c){if(i==="")continue;f.push([i,l]),i="",l="",r=!0;continue}if(!(r&&a.search(v)===-1)){if(r){i+=a;continue}l+=a}}return o.length?f.filter(([h])=>o.some(a=>a instanceof RegExp?a.test(h):a===h)):f},y=({left:e,right:t},s)=>{if(!["start","end","only"].includes(s))throw new Error(`Invalid 'where' parameter: ${s}. Expected 'start', 'end', or 'only'.`);return n=>{const o=e.length,i=t.length,l=o+1+i,r=o+1;if(!n||typeof n!="string"||n.length<l)return!1;const c=p=>[_,x].includes(p.charAt(o))?p.length>=l+1:p.length>=l;let f,h,a,m;return s==="start"?(a=n.slice(0,o),f=a===e?0:-1,h=f===-1?-1:n.indexOf(t,r),m=n.charAt(h+i),m&&t.includes(m)&&(h=-1)):s==="end"?(f=n.lastIndexOf(e),h=f===-1?-1:n.indexOf(t,f+r),h=h===n.length-i?h:-1):(a=n.slice(0,o),f=a===e?0:-1,a=n.slice(n.length-i),h=a===t?n.length-i:-1),f!==-1&&h!==-1&&c(n.substring(f,h+i))}},g=(e,t)=>{const s=e[t];if(s.type==="softbreak")return null;if(s.nesting===0)return s;const n=s.level,o=s.type.replace("_close","_open");for(;t>=0;){const i=e[t];if(i.type===o&&i.level===n)return i;t--}/* istanbul ignore next -- @preserve */return null},b=e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),w=(e,t,s)=>{const n=b(t),o=b(s),i=e.search(new RegExp(`[ \\n]?${n}[^${n}${o}]+${o}$`));return i!==-1?e.slice(0,i):e},$=(e,t)=>t>=0?e[t]:e[e.length+t],C=e=>Array.isArray(e)&&!!e.length&&e.every(t=>typeof t=="function"),I=e=>Array.isArray(e)&&!!e.length&&e.every(t=>typeof t=="object"),k=(e,t,s)=>{const n={match:!1,position:null},o=s.shift!==void 0?t+s.shift:s.position;if(s.shift!==void 0&&o<0)return n;const i=$(e,o);if(!i)return n;for(const l of Object.keys(s)){if(l==="shift"||l==="position")continue;if(i[l]===void 0)return n;if(l==="children"&&I(s.children)){if(i.children?.length===0)return n;let c;const f=s.children,h=i.children;if(f.every(a=>a.position!==void 0)){if(c=f.every(a=>k(h,a.position,a).match),c){const a=f[f.length-1]?.position??0;n.position=a>=0?a:h.length+a}}else for(let a=0;a<h.length;a++)if(c=f.every(m=>k(h,a,m).match),c){n.position=a;break}if(c===!1)return n;continue}const r=s[l];switch(typeof r){case"boolean":case"number":case"string":{if(i[l]!==r)return n;break}case"function":{if(!r(i[l]))return n;break}default:{if(C(r)){if(!r.every(c=>c(i[l])))return n;break}throw new Error(`Unknown type of pattern test (key: ${l}). Test should be of type boolean, number, string, function or array of functions.`)}}}return n.match=!0,n},S=e=>({name:"end of block",tests:[{shift:0,type:"inline",children:[{position:-1,content:y(e,"end"),type:t=>t!=="code_inline"&&t!=="math_inline"}]}],transform:(t,s,n)=>{const o=t[s].children[n],{content:i}=o,l=i.lastIndexOf(e.left),r=d(i,l,e);let c=s+1;for(;t[c+1]&&t[c+1].nesting===-1;)c++;const f=g(t,c);u(r,f);const h=i.slice(0,l),a=h[h.length-1]===" ";o.content=a?h.slice(0,-1):h}}),T=e=>({name:"code-block",tests:[{shift:0,block:!0,info:y(e,"end")}],transform:(t,s)=>{const n=t[s];let o="";const i=/{(?:[\d,-]+)}/.exec(n.info);i&&(n.info=n.info.replace(i[0],""),o=i[0]);const l=n.info.lastIndexOf(e.left),r=d(n.info,l,e);u(r,n);const c=w(n.info,e.left,e.right);n.info=`${c} ${o}`.trim()}}),D=e=>[{name:"inline nesting self-close",tests:[{shift:0,type:"inline",children:[{shift:-1,type:t=>t==="image"||t==="code_inline"},{shift:0,type:"text",content:y(e,"start")}]}],transform:(t,s,n)=>{const o=e.right.length,i=t[s].children[n],l=i.content.indexOf(e.right),r=t[s].children[n-1],c=d(i.content,0,e);u(c,r),i.content.length===l+o?t[s].children.splice(n,1):i.content=i.content.slice(l+o)}},{name:"inline attributes",tests:[{shift:0,type:"inline",children:[{shift:-1,nesting:-1},{shift:0,type:"text",content:y(e,"start")}]}],transform:(t,s,n)=>{const o=t[s].children[n],{content:i}=o,l=d(i,0,e),r=g(t[s].children,n-1);u(l,r);const c=i.indexOf(e.right)+e.right.length;o.content=i.slice(c)}}],K=e=>[{name:"list softbreak",tests:[{shift:-2,type:"list_item_open"},{shift:0,type:"inline",children:[{position:-2,type:"softbreak"},{position:-1,type:"text",content:y(e,"only")}]}],transform:(t,s,n)=>{const o=t[s].children[n],i=d(o.content,0,e);let l=s-2;for(;t[l-1]&&t[l-1].type!=="ordered_list_open"&&t[l-1].type!=="bullet_list_open";)l--;u(i,t[l-1]),t[s].children=t[s].children.slice(0,-2)}},{name:"list double softbreak",tests:[{shift:0,type:t=>t==="bullet_list_close"||t==="ordered_list_close"},{shift:1,type:"paragraph_open"},{shift:2,type:"inline",content:y(e,"only"),children:t=>t.length===1},{shift:3,type:"paragraph_close"}],transform:(t,s)=>{const n=t[s+2],o=d(n.content,0,e),i=g(t,s);u(o,i),t.splice(s+1,3)}},{name:"list item end",tests:[{shift:-2,type:"list_item_open"},{shift:0,type:"inline",children:[{position:-1,type:"text",content:y(e,"end")}]}],transform:(t,s,n)=>{const o=t[s].children[n],{content:i}=o,l=i.lastIndexOf(e.left),r=d(i,l,e);u(r,t[s-2]);const c=i.slice(0,l),f=c[c.length-1]===" ";o.content=f?c.slice(0,-1):c}}],L=e=>({name:`
2
- {.a} softbreak then curly in start`,tests:[{shift:0,type:"inline",children:[{position:-2,type:"softbreak"},{position:-1,type:"text",content:y(e,"only")}]}],transform:(t,s,n)=>{const o=t[s].children[n],i=d(o.content,0,e);let l=s+1;for(;t[l+1]&&t[l+1].nesting===-1;)l++;const r=g(t,l);u(i,r),t[s].children=t[s].children.slice(0,-2)}}),M=e=>({name:"horizontal rule",tests:[{shift:0,type:"paragraph_open"},{shift:1,type:"inline",children:t=>t.length===1,content:t=>new RegExp(`^ {0,3}[-*_]{3,} ?${b(e.left)}[^${b(e.right)}]`).test(t)},{shift:2,type:"paragraph_close"}],transform:(t,s)=>{const n=t[s];n.type="hr",n.tag="hr",n.nesting=0;const o=t[s+1],{content:i}=o,l=i.lastIndexOf(e.left),r=d(i,l,e);u(r,n),n.markup=i,t.splice(s+1,2)}}),A=e=>{e.hidden=!0,e.children?.forEach(t=>{t.content="",A(t)})},P=(e,t,s,n,o,i)=>{let l=n-(o>0?o:1);for(let r=t,c=i;r<s&&c>1;r++)if(e[r].type==="tr_open"){const f=e[r];f.meta??={},f.meta.columnCount&&(l-=1),f.meta.columnCount=l,c--}},j=(e,t,s)=>{const n=e[t].meta?.columnCount;if(n)for(let o=t,i=0;o<s;o++){const l=e[o];if(l.type==="td_open")i+=1;else if(l.type==="tr_close")break;i>n&&!l.hidden&&A(l)}},N=(e,t,s,n,o,i)=>{const l=[],r=e[t];let c=t+3,f=n;for(let p=t;p>i;p--)if(e[p].type==="tr_open"){f=e[p].meta?.columnCount??f;break}else e[p].type==="td_open"&&l.unshift(p);for(let p=t+2;p<s;p++)if(e[p].type==="tr_close"){c=p;break}else e[p].type==="td_open"&&l.push(p);const h=l.indexOf(t),a=Math.min(o,f-h);o>a&&r.attrSet("colspan",a.toString());const m=l.slice(f+1-n-a)[0];for(let p=m;p<c;p++)e[p].hidden||A(e[p])},B=e=>[{name:"table",tests:[{shift:0,type:"table_close"},{shift:1,type:"paragraph_open"},{shift:2,type:"inline",content:y(e,"only")}],transform:(t,s)=>{const n=t[s+2],o=g(t,s),i=d(n.content,0,e);u(i,o),t.splice(s+1,3)}},{name:"table cell attributes",tests:[{shift:-1,type:t=>t==="td_open"||t==="th_open"},{shift:0,type:"inline",children:[{shift:0,type:"text",content:y(e,"end")}]}],transform:(t,s,n)=>{const o=t[s].children[n],i=t[s-1],{content:l}=o,r=l.lastIndexOf(e.left),c=d(l,r,e);u(c,i),o.content=l.substring(0,r).trim()}},{name:"table thead metadata",tests:[{shift:0,type:"tr_close"},{shift:1,type:"thead_close"},{shift:2,type:"tbody_open"}],transform:(t,s)=>{const n=g(t,s),o=t[s-1];let i=0,l=s-1;for(;l>0;){const c=t[l];if(c===n){const f=t[l-1];f.meta={...f.meta,columnCount:i};break}c.level===o.level&&c.type===o.type&&i++,l--}const r=t[s+2];r.meta={...r.meta,columnCount:i}}},{name:"table tbody calculate",tests:[{shift:0,type:"tbody_close",hidden:!1}],transform:(t,s)=>{let n=s-2;for(;n>0&&(n--,t[n].type!=="tbody_open"););const o=Number(t[n].meta?.columnCount??0);if(o<2)return;const i=t[s].level+2;for(let l=n;l<s;l++){if(t[l].level>i)continue;const r=t[l],c=r.hidden?0:Number(r.attrGet("rowspan")),f=r.hidden?0:Number(r.attrGet("colspan"));c>1&&P(t,l,s,o,f,c),r.type==="tr_open"&&j(t,l,s),f>1&&N(t,l,s,o,f,n)}}}],R=["fence","inline","table","list","hr","softbreak","block"],F=e=>{const t=e.rule===!1?[]:Array.isArray(e.rule)?e.rule.filter(n=>R.includes(n)):R,s=[];return t.includes("fence")&&s.push(T(e)),t.includes("inline")&&s.push(...D(e)),t.includes("table")&&s.push(...B(e)),t.includes("list")&&s.push(...K(e)),t.includes("softbreak")&&s.push(L(e)),t.includes("hr")&&s.push(M(e)),t.includes("block")&&s.push(S(e)),s},G=(e,{left:t="{",right:s="}",allowed:n=[],rule:o="all"}={})=>{const i=F({left:t,right:s,allowed:n,rule:o}),l=({tokens:r})=>{for(let c=0;c<r.length;c++)for(let f=0;f<i.length;f++){const h=i[f];let a=null;h.tests.every(m=>{const p=k(r,c,m);return p.position!==null&&({position:a}=p),p.match})&&(h.transform(r,c,a),(h.name==="inline attributes"||h.name==="inline nesting self-close")&&f--)}};e.core.ruler.before("linkify","attrs",l)};export{G as attrs};
1
+ const Q=46,W=35,B=32,G=61,H=34,C=e=>!(e===9||e===10||e===12||e===32||e===47||e===62||e===34||e===39||e===61),E=(e,t,n)=>{let l="",i="",o=!0,s=!1;const r=[];for(let a=t[0];a<t[1];a++){const c=e.charCodeAt(a);if(c===61&&o){o=!1;continue}if(c===46&&l===""){e.charCodeAt(a+1)===46?(l="css-module",a++):l="class",o=!1;continue}if(c===35&&l===""){l="id",o=!1;continue}if(c===34&&i===""&&!s){s=!0;continue}if(c===34&&s){s=!1;continue}if(c===32&&!s){if(l==="")continue;r.push([l,i]),l="",i="",o=!0;continue}if(!(o&&!C(c))){if(o){l+=String.fromCharCode(c);continue}i+=String.fromCharCode(c)}}return l!==""&&r.push([l,i]),n.length?r.filter(([a])=>n.some(c=>c instanceof RegExp?c.test(a):c===a)):r},p=(e,t,n,l)=>{e&&E(t,n,l).forEach(([i,o])=>{switch(i){case"class":e.attrJoin("class",o);break;case"css-module":e.attrJoin("css-module",o);break;default:e.attrPush([i,o])}})},d=({left:e,right:t},n)=>{if(!["start","end","only"].includes(n))throw new Error(`Invalid 'where' parameter: ${n}. Expected 'start', 'end', or 'only'.`);const l=e.length,i=t.length,o=l+1+i;return s=>{if(typeof s!="string"||s.length<o)return!1;let r,a;if(n==="start"){if(!s.startsWith(e)||(r=l,a=s.indexOf(t,l+1),a===-1))return!1;const u=a+i;if(u<s.length&&t.includes(s.charAt(u)))return!1}else if(n==="end"){if(r=s.lastIndexOf(e),r===-1||(a=s.indexOf(t,r+l+1),r+=l,a===-1||a+i!==s.length))return!1}else{if(!s.startsWith(e)||!s.endsWith(t))return!1;r=l,a=s.length-i}const c=s.charCodeAt(r),h=a-r;return(c===46||c===35?h>=2:h>=1)?[r,a]:!1}},y=(e,t)=>{const n=e[t];if(n.type==="softbreak")return null;if(n.nesting===0)return n;const l=n.level,i=n.type.replace("_close","_open");for(;t>=0;){const o=e[t];if(o.type===i&&o.level===l)return o;t--}/* istanbul ignore next -- @preserve */return null},w=(e,t)=>t>=0?e[t]:e[e.length+t],A=(e,t,n)=>{const l={match:!1,position:null,range:null},i=n.shift!==void 0,o=i?t+n.shift:n.position;if(i&&o<0)return l;const s=w(e,o);if(!s)return l;for(const r of Object.keys(n)){if(r==="shift"||r==="position")continue;if(s[r]==null)return l;if(r==="children"&&Array.isArray(n.children)){if(!s.children?.length)return l;const c=n.children,h=s.children;let u,m=null;if(c.every(f=>f.position!=null)){if(u=c.every(f=>{const g=A(h,f.position,f);return g.match?(g.range&&(m=g.range),!0):!1}),u){const{position:f}=c[c.length-1];l.position=f>=0?f:h.length+f,l.range=m}}else for(let f=0;f<h.length;f++)if(u=c.every(g=>{const b=A(h,f,g);return b.match?(b.range&&(m=b.range),!0):!1}),u){l.position=f,m&&(l.range=m);break}if(u===!1)return l;continue}const a=n[r];switch(typeof a){case"boolean":case"number":case"string":{if(s[r]!==a)return l;break}case"function":{const c=a(s[r]);if(!c)return l;Array.isArray(c)&&(l.range=c);break}default:throw new Error(`Unknown type of pattern test (key: ${r}). Test should be of type boolean, number, string or function.`)}}return l.match=!0,l};function _(e){switch(e){case 9:case 32:return!0}return!1}const S=e=>({name:"end of block",tests:[{shift:0,type:"inline",children:[{position:-1,content:d(e,"end"),type:t=>t!=="code_inline"&&t!=="math_inline"}]}],transform:(t,n,l,i)=>{const o=i[0]-e.left.length,s=t[n].children[l],{content:r}=s,a=_(r.charCodeAt(o-1));let c=n+1;for(;t[c+1]&&t[c+1].nesting===-1;)c++;const h=y(t,c);p(h,r,i,e.allowed),s.content=r.slice(0,a?o-1:o)}}),x=e=>({name:"code-block",tests:[{shift:0,block:!0,info:d(e,"end")}],transform:(t,n,l,i)=>{const o=i[0]-e.left.length,s=t[n],{info:r}=s,a=_(r.charCodeAt(o-1));p(s,r,i,e.allowed),s.info=r.slice(0,a?o-1:o)}}),O=e=>({name:"end of block",tests:[{shift:-1,type:"heading_open"},{shift:0,type:"inline",children:[{position:-1,content:d(e,"end"),type:t=>t!=="code_inline"&&t!=="math_inline"}]}],transform:(t,n,l,i)=>{const o=i[0]-e.left.length,s=t[n].children[l],{content:r}=s,a=_(r.charCodeAt(o-1));let c=n+1;for(;t[c+1]&&t[c+1].nesting===-1;)c++;const h=y(t,c);p(h,r,i,e.allowed),s.content=r.slice(0,a?o-1:o)}}),v=e=>[{name:"inline nesting self-close",tests:[{shift:0,type:"inline",children:[{shift:-1,type:t=>t==="image"||t==="code_inline"},{shift:0,type:"text",content:d(e,"start")}]}],transform:(t,n,l,i)=>{const o=t[n].children,s=o[l],r=o[l-1],a=e.right.length+i[1];p(r,s.content,i,e.allowed),s.content.length===a?o.splice(l,1):s.content=s.content.slice(a)}},{name:"inline attributes",tests:[{shift:0,type:"inline",children:[{shift:-1,nesting:-1},{shift:0,type:"text",content:d(e,"start")}]}],transform:(t,n,l,i)=>{const o=t[n].children,s=o[l],{content:r}=s,a=e.right.length+i[1],c=y(o,l-1);p(c,r,i,e.allowed),s.content=r.slice(a)}}],K=e=>[{name:"list softbreak",tests:[{shift:-2,type:"list_item_open"},{shift:0,type:"inline",children:[{position:-2,type:"softbreak"},{position:-1,type:"text",content:d(e,"only")}]}],transform:(t,n,l,i)=>{const o=t[n].children,s=o[l];let r=n-2;for(;t[r-1]&&t[r-1].type!=="ordered_list_open"&&t[r-1].type!=="bullet_list_open";)r--;p(t[r-1],s.content,i,e.allowed),t[n].children=o.slice(0,-2)}},{name:"list double softbreak",tests:[{shift:0,type:t=>t==="bullet_list_close"||t==="ordered_list_close"},{shift:1,type:"paragraph_open"},{shift:2,type:"inline",content:d(e,"only"),children:t=>t.length===1},{shift:3,type:"paragraph_close"}],transform:(t,n,l,i)=>{const o=t[n+2],s=y(t,n);p(s,o.content,i,e.allowed),t.splice(n+1,3)}},{name:"list item end",tests:[{shift:-2,type:"list_item_open"},{shift:0,type:"inline",children:[{position:-1,type:"text",content:d(e,"end")}]}],transform:(t,n,l,i)=>{const o=t[n].children[l],{content:s}=o,r=i[0]-e.left.length,a=_(s.charCodeAt(r-1));p(t[n-2],s,i,e.allowed),o.content=s.slice(0,a?r-1:r)}}],M=e=>({name:`
2
+ {.a} softbreak then curly in start`,tests:[{shift:0,type:"inline",children:[{position:-2,type:"softbreak"},{position:-1,type:"text",content:d(e,"only")}]}],transform:(t,n,l,i)=>{const o=t[n].children,s=o[l];let r=n+1;for(;t[r+1]&&t[r+1].nesting===-1;)r++;p(y(t,r),s.content,i,e.allowed),t[n].children=o.slice(0,-2)}}),T=e=>({name:"horizontal rule",tests:[{shift:0,type:"paragraph_open"},{shift:1,type:"inline",children:t=>t.length===1,content:t=>{let n=0,l,i=0;for(;n<t.length;)if(l=t.charCodeAt(n++),l===32)i++;else if(l===9)i+=4-i%4;else break;if(i>3)return!1;const o=t.charCodeAt(n-1);if(o!==45&&o!==42&&o!==95)return!1;let s=1;for(;n<t.length&&(l=t.charCodeAt(n++),l===o);)s++;return s<3?!1:(_(t.charCodeAt(n-1))||n--,d(e,"end")(t))}},{shift:2,type:"paragraph_close"}],transform:(t,n,l,i)=>{const o=t[n],s=t[n+1],{content:r}=s;o.type="hr",o.tag="hr",o.nesting=0,p(o,r,i,e.allowed),o.markup=r,t.splice(n+1,2)}}),R=e=>{e.hidden=!0,e.children?.forEach(t=>{t.content="",R(t)})},I=(e,t,n,l,i,o)=>{let s=l-(i>0?i:1);for(let r=t,a=o;r<n&&a>1;r++)if(e[r].type==="tr_open"){const c=e[r];c.meta??={},c.meta.columnCount&&(s-=1),c.meta.columnCount=s,a--}},P=(e,t,n)=>{const l=e[t].meta?.columnCount;if(l)for(let i=t,o=0;i<n;i++){const s=e[i];if(s.type==="tr_close")break;s.type==="td_open"&&(o+=1),o>l&&!s.hidden&&R(s)}},L=(e,t,n,l,i,o)=>{const s=[],r=e[t];let a=t+3,c=l;for(let f=t;f>o;f--)if(e[f].type==="tr_open"){c=e[f].meta?.columnCount??c;break}else e[f].type==="td_open"&&s.unshift(f);for(let f=t+2;f<n;f++)if(e[f].type==="tr_close"){a=f;break}else e[f].type==="td_open"&&s.push(f);const h=s.indexOf(t),u=Math.min(i,c-h);i>u&&r.attrSet("colspan",u.toString());const m=s.slice(c+1-l-u)[0];for(let f=m;f<a;f++)e[f].hidden||R(e[f])},D=e=>[{name:"table",tests:[{shift:0,type:"table_close"},{shift:1,type:"paragraph_open"},{shift:2,type:"inline",content:d(e,"only")}],transform:(t,n,l,i)=>{const o=t[n+2],s=y(t,n);p(s,o.content,i,e.allowed),t.splice(n+1,3)}},{name:"table cell attributes",tests:[{shift:-1,type:t=>t==="td_open"||t==="th_open"},{shift:0,type:"inline",children:[{shift:0,type:"text",content:d(e,"end")}]}],transform:(t,n,l,i)=>{const o=i[0]-e.left.length,s=t[n].children[l],r=t[n-1],{content:a}=s,c=_(a.charCodeAt(o-1));p(r,a,i,e.allowed),s.content=a.slice(0,c?o-1:o)}},{name:"table thead metadata",tests:[{shift:0,type:"tr_close"},{shift:1,type:"thead_close"},{shift:2,type:"tbody_open"}],transform:(t,n)=>{const l=y(t,n),i=t[n-1];let o=0,s=n-1;for(;s>0;){const a=t[s];if(a===l){const c=t[s-1];c.meta={...c.meta,columnCount:o};break}a.level===i.level&&a.type===i.type&&o++,s--}const r=t[n+2];r.meta={...r.meta,columnCount:o}}},{name:"table tbody calculate",tests:[{shift:0,type:"tbody_close",hidden:!1}],transform:(t,n)=>{let l=n-2;for(;l>0&&(l--,t[l].type!=="tbody_open"););const i=Number(t[l].meta?.columnCount??0);if(i<2)return;const o=t[n].level+2;for(let s=l;s<n;s++){if(t[s].level>o)continue;const r=t[s],a=r.hidden?0:Number(r.attrGet("rowspan")),c=r.hidden?0:Number(r.attrGet("colspan"));a>1&&I(t,s,n,i,c,a),r.type==="tr_open"&&P(t,s,n),c>1&&L(t,s,n,i,c,l)}}}],k=["fence","inline","table","list","heading","hr","softbreak","block"],U=e=>{const t=e.rule===!1?[]:Array.isArray(e.rule)?e.rule.filter(l=>k.includes(l)):k,n=[];return t.includes("fence")&&n.push(x(e)),t.includes("inline")&&n.push(...v(e)),t.includes("table")&&n.push(...D(e)),t.includes("list")&&n.push(...K(e)),t.includes("softbreak")&&n.push(M(e)),t.includes("hr")&&n.push(T(e)),t.includes("block")?n.push(S(e)):t.includes("heading")&&n.push(O(e)),n},N=(e,{left:t="{",right:n="}",allowed:l=[],rule:i="all"}={})=>{const o=U({left:t,right:n,allowed:l,rule:i}),s=({tokens:r})=>{for(let a=0;a<r.length;a++)for(let c=0;c<o.length;c++){const h=o[c];let u=null,m=null;h.tests.every(f=>{const g=A(r,a,f);return g.position!==null&&({position:u}=g),g.range&&(m=g.range),g.match})&&(h.transform(r,a,u,m),(h.name==="inline attributes"||h.name==="inline nesting self-close")&&c--)}};e.core.ruler.before("linkify","attrs",s)};export{N as attrs};
3
3
  //# sourceMappingURL=browser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser.js","sources":["../src/helper/addAttrs.ts","../src/helper/constants.ts","../src/helper/getAttrs.ts","../src/helper/getDelimiterChecker.ts","../src/helper/getMatchingOpeningToken.ts","../../helper/lib/index.js","../src/helper/removeDelimiter.ts","../src/utils.ts","../src/helper/testRule.ts","../src/rules/block.ts","../src/rules/fence.ts","../src/rules/inline.ts","../src/rules/list.ts","../src/rules/softbreak.ts","../src/rules/hr.ts","../src/rules/table.ts","../src/rules/rules.ts","../src/plugin.ts"],"sourcesContent":["import type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { Attr } from \"./types.js\";\n\nexport const addAttrs = (attrs: Attr[], token: Token | null): void => {\n if (!token) return;\n\n attrs.forEach(([key, value]) => {\n switch (key) {\n case \"class\":\n token.attrJoin(\"class\", value);\n break;\n case \"css-module\":\n token.attrJoin(\"css-module\", value);\n break;\n default:\n token.attrPush([key, value]);\n }\n });\n};\n","export const CLASS_MARKER = \".\";\nexport const ID_MARKER = \"#\";\nexport const ALLOWED_KEY_CHARS = /[^\\t\\n\\f />\"'=]/;\nexport const PAIR_SEPARATOR = \" \";\nexport const KEY_SEPARATOR = \"=\";\n","import {\n ALLOWED_KEY_CHARS,\n CLASS_MARKER,\n ID_MARKER,\n KEY_SEPARATOR,\n PAIR_SEPARATOR,\n} from \"./constants.js\";\nimport type { Attr, DelimiterConfig } from \"./types.js\";\n\nexport const getAttrs = (\n str: string,\n start: number,\n { left, right, allowed }: DelimiterConfig,\n): Attr[] => {\n let key = \"\";\n let value = \"\";\n let parsingKey = true;\n let valueInsideQuotes = false;\n\n const attrs: Attr[] = [];\n\n // read inside {}\n // start + left delimiter length to avoid beginning {\n // breaks when } is found or end of string\n for (let index = start + left.length; index < str.length; index++) {\n if (str.slice(index, index + right.length) === right) {\n if (key !== \"\") attrs.push([key, value]);\n break;\n }\n\n const char = str.charAt(index);\n\n // switch to reading value if equal sign\n if (char === KEY_SEPARATOR && parsingKey) {\n parsingKey = false;\n continue;\n }\n\n // {.class} {..css-module}\n if (char === CLASS_MARKER && key === \"\") {\n if (str.charAt(index + 1) === CLASS_MARKER) {\n key = \"css-module\";\n index++;\n } else {\n key = \"class\";\n }\n\n parsingKey = false;\n continue;\n }\n\n // {#id}\n if (char === ID_MARKER && key === \"\") {\n key = \"id\";\n parsingKey = false;\n continue;\n }\n\n // {value=\"inside quotes\"}\n if (char === '\"' && value === \"\" && !valueInsideQuotes) {\n valueInsideQuotes = true;\n continue;\n }\n\n if (char === '\"' && valueInsideQuotes) {\n valueInsideQuotes = false;\n continue;\n }\n\n // read next key/value pair\n if (char === PAIR_SEPARATOR && !valueInsideQuotes) {\n if (key === \"\")\n // beginning or ending space: { .red } vs {.red}\n continue;\n\n attrs.push([key, value]);\n key = \"\";\n value = \"\";\n parsingKey = true;\n\n continue;\n }\n\n // continue if character not allowed\n if (parsingKey && char.search(ALLOWED_KEY_CHARS) === -1) continue;\n\n // no other conditions met; append to key/value\n if (parsingKey) {\n key += char;\n continue;\n }\n\n value += char;\n }\n\n return allowed.length\n ? attrs.filter(([attr]) =>\n allowed.some((item) =>\n item instanceof RegExp ? item.test(attr) : item === attr,\n ),\n )\n : attrs;\n};\n","import { CLASS_MARKER, ID_MARKER } from \"./constants.js\";\nimport type { DelimiterConfig } from \"./types.js\";\n\nexport type DelimiterChecker = (content: string) => boolean;\n\nexport const getDelimiterChecker = (\n { left, right }: Required<DelimiterConfig>,\n where: \"start\" | \"end\" | \"only\",\n): DelimiterChecker => {\n if (![\"start\", \"end\", \"only\"].includes(where)) {\n throw new Error(\n `Invalid 'where' parameter: ${where}. Expected 'start', 'end', or 'only'.`,\n );\n }\n\n return (content: string): boolean => {\n const leftLength = left.length;\n const rightLength = right.length;\n // we need minimum three chars, for example {b}\n const minCurlyLength = leftLength + 1 + rightLength;\n const rightDelimiterMinimumShift = leftLength + 1;\n\n // perform a quick check\n if (\n !content ||\n typeof content !== \"string\" ||\n content.length < minCurlyLength\n )\n return false;\n\n const validCurlyLength = (curly: string): boolean =>\n [CLASS_MARKER, ID_MARKER].includes(curly.charAt(leftLength))\n ? curly.length >= minCurlyLength + 1\n : curly.length >= minCurlyLength;\n\n let start: number;\n let end: number;\n let slice: string;\n let nextChar: string;\n\n if (where === \"start\") {\n // first char should be {, } found in char 2 or more\n slice = content.slice(0, leftLength);\n start = slice === left ? 0 : -1;\n end =\n start === -1 ? -1 : content.indexOf(right, rightDelimiterMinimumShift);\n // check if next character is not one of the delimiters\n nextChar = content.charAt(end + rightLength);\n if (nextChar && right.includes(nextChar)) end = -1;\n } else if (where === \"end\") {\n // last char should be }\n start = content.lastIndexOf(left);\n end =\n start === -1\n ? -1\n : content.indexOf(right, start + rightDelimiterMinimumShift);\n end = end === content.length - rightLength ? end : -1;\n } else {\n // '{.a}'\n slice = content.slice(0, leftLength);\n start = slice === left ? 0 : -1;\n slice = content.slice(content.length - rightLength);\n end = slice === right ? content.length - rightLength : -1;\n }\n\n return (\n start !== -1 &&\n end !== -1 &&\n validCurlyLength(content.substring(start, end + rightLength))\n );\n };\n};\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nexport const getMatchingOpeningToken = (\n tokens: Token[],\n index: number,\n): Token | null => {\n const token = tokens[index];\n\n if (token.type === \"softbreak\") return null;\n\n // non closing blocks, example img\n if (token.nesting === 0) return token;\n\n const level = token.level;\n const type = token.type.replace(\"_close\", \"_open\");\n\n while (index >= 0) {\n const currentToken = tokens[index];\n\n if (currentToken.type === type && currentToken.level === level)\n return currentToken;\n\n index--;\n }\n\n /* istanbul ignore next -- @preserve */\n return null;\n};\n","const l=e=>{const n=e.split(`\n`),p=n.reduce((r,c)=>{for(let t=0;t<c.length;t++)if(c[t]!==\" \"&&c[t]!==\"\t\")return Math.min(t,r);return r},1/0);return p<1/0?n.map(r=>r.slice(p)).join(`\n`):e},a=e=>e.replace(/&/gu,\"&amp;\").replace(/</gu,\"&lt;\").replace(/>/gu,\"&gt;\").replace(/\"/gu,\"&quot;\").replace(/'/gu,\"&#39;\"),g=e=>e.replace(/[-/\\\\^$*+?.()|[\\]{}]/g,\"\\\\$&\"),u=/\\r\\n?|\\n/g,s=/\\\\([ \\\\!\"#$%&'()*+,./:;<=>?@[\\]^_`{|}~-])/gu;export{u as NEWLINE_RE,s as UNESCAPE_RE,l as dedent,a as escapeHtml,g as escapeRegExp};\n//# sourceMappingURL=index.js.map\n","import { escapeRegExp } from \"@mdit/helper\";\n\nexport const removeDelimiter = (\n str: string,\n left: string,\n right: string,\n): string => {\n const start = escapeRegExp(left);\n const end = escapeRegExp(right);\n const pos = str.search(\n new RegExp(`[ \\\\n]?${start}[^${start}${end}]+${end}$`),\n );\n\n return pos !== -1 ? str.slice(0, pos) : str;\n};\n","/**\n * Get index item of array. Supports negative index, where -1 is last\n * element in array.\n */\nexport const getArrayItem = <T>(arr: T[], index: number): T =>\n index >= 0 ? arr[index] : arr[arr.length + index];\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const isArrayOfFunctions = (arr: unknown): arr is Function[] =>\n Array.isArray(arr) &&\n Boolean(arr.length) &&\n arr.every((item) => typeof item === \"function\");\n\nexport const isArrayOfObjects = (arr: unknown): arr is object[] =>\n Array.isArray(arr) &&\n Boolean(arr.length) &&\n arr.every((item) => typeof item === \"object\");\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { AttrRuleSet, TestFunction } from \"../rules/types.js\";\nimport {\n getArrayItem,\n isArrayOfFunctions,\n isArrayOfObjects,\n} from \"../utils.js\";\n\nexport interface TestRuleResult {\n /** whether rule matches token stream */\n match: boolean;\n /** position of token */\n position: null | number;\n}\n\n/**\n * Test if rule matches token stream.\n *\n */\nexport const testRule = (\n tokens: Token[],\n index: number,\n rule: AttrRuleSet,\n): TestRuleResult => {\n const result: TestRuleResult = {\n match: false,\n position: null,\n };\n\n const tokenIndex =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n rule.shift !== undefined ? index + rule.shift : rule.position!;\n\n // we should never shift to negative indexes (rolling around to back of array)\n if (rule.shift !== undefined && tokenIndex < 0) return result;\n\n const token = getArrayItem(tokens, tokenIndex);\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!token) return result;\n\n for (const key of Object.keys(rule) as (keyof typeof rule)[]) {\n if (key === \"shift\" || key === \"position\") continue;\n\n if (token[key as keyof Token] === undefined) return result;\n\n if (key === \"children\" && isArrayOfObjects(rule.children)) {\n if (token.children?.length === 0) return result;\n\n let match;\n const childTests = rule.children;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const children = token.children!;\n\n if (childTests.every((childTest) => childTest.position !== undefined)) {\n // positions instead of shifts, do not loop all children\n match = childTests.every(\n (childTest) =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n testRule(children, childTest.position!, childTest).match,\n );\n\n if (match) {\n // we may need position of child in transform\n const position = childTests[childTests.length - 1]?.position ?? 0;\n\n result.position =\n position >= 0 ? position : children.length + position;\n }\n } else {\n for (let token = 0; token < children.length; token++) {\n match = childTests.every(\n (childTest) => testRule(children, token, childTest).match,\n );\n\n if (match) {\n result.position = token;\n // all tests true, continue with next key of pattern t\n break;\n }\n }\n }\n\n if (match === false) return result;\n\n continue;\n }\n\n const ruleDetail = rule[key];\n\n switch (typeof ruleDetail) {\n case \"boolean\":\n case \"number\":\n case \"string\": {\n if (token[key] !== ruleDetail) return result;\n\n break;\n }\n\n case \"function\": {\n if (!(ruleDetail as TestFunction)(token[key])) return result;\n\n break;\n }\n\n // fall through for objects !== arrays of functions\n default: {\n if (isArrayOfFunctions(ruleDetail)) {\n if (\n !(ruleDetail as TestFunction[]).every((ruleItem) =>\n ruleItem(token[key]),\n )\n )\n return result;\n\n break;\n }\n\n throw new Error(\n `Unknown type of pattern test (key: ${key}). Test should be of type boolean, number, string, function or array of functions.`,\n );\n }\n }\n }\n\n // no tests returned false -> all tests returns true\n result.match = true;\n\n return result;\n};\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getBlockRule = (options: Required<DelimiterConfig>): AttrRule =>\n /**\n * end of {.block}\n */\n ({\n name: \"end of block\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n content: getDelimiterChecker(options, \"end\"),\n type: (type) => type !== \"code_inline\" && type !== \"math_inline\",\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n\n // Extract attributes from the content\n const attrStartIndex = content.lastIndexOf(options.left);\n const attrs = getAttrs(content, attrStartIndex, options);\n\n // Find the closing token by skipping all nested closing tokens\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Get the corresponding opening token\n const openingToken = getMatchingOpeningToken(tokens, closingTokenIndex);\n\n // Apply attributes to the opening token\n addAttrs(attrs, openingToken);\n\n // Remove the attribute syntax from content\n const contentWithoutAttributes = content.slice(0, attrStartIndex);\n const hasTrailingSpace =\n contentWithoutAttributes[contentWithoutAttributes.length - 1] === \" \";\n\n token.content = hasTrailingSpace\n ? contentWithoutAttributes.slice(0, -1)\n : contentWithoutAttributes;\n },\n });\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n removeDelimiter,\n} from \"../helper/index.js\";\n\nexport const getFenceRule = (options: Required<DelimiterConfig>): AttrRule =>\n /**\n * fenced code blocks\n *\n * ```python {.cls}\n * for i in range(10):\n * print(i)\n * ```\n */\n ({\n name: \"code-block\",\n tests: [\n {\n shift: 0,\n block: true,\n info: getDelimiterChecker(options, \"end\"),\n },\n ],\n transform: (tokens, index): void => {\n const token = tokens[index];\n let lineNumbers = \"\";\n\n // Special handler for VuePress line numbers syntax\n const lineNumberMatch = /{(?:[\\d,-]+)}/.exec(token.info);\n\n if (lineNumberMatch) {\n token.info = token.info.replace(lineNumberMatch[0], \"\");\n lineNumbers = lineNumberMatch[0];\n }\n\n // Extract attributes from the token info\n const attributeStartIndex = token.info.lastIndexOf(options.left);\n const attributes = getAttrs(token.info, attributeStartIndex, options);\n\n // Apply attributes to the current token\n addAttrs(attributes, token);\n\n // Remove attribute syntax from info and restore line numbers\n const infoWithoutAttributes = removeDelimiter(\n token.info,\n options.left,\n options.right,\n );\n\n token.info = `${infoWithoutAttributes} ${lineNumbers}`.trim();\n },\n });\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getInlineRules = (\n options: Required<DelimiterConfig>,\n): AttrRule[] => [\n /**\n * bla `click()`{.c} ![](img.png){.d}\n *\n * differs from 'inline attributes' as it does\n * not have a closing tag (nesting: -1)\n */\n {\n name: \"inline nesting self-close\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: -1,\n type: (str) => str === \"image\" || str === \"code_inline\",\n },\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"start\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n const rightDelimiterLength = options.right.length;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n\n const attrEndIndex = token.content.indexOf(options.right);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const targetToken = tokens[index].children![childIndex - 1];\n const attrs = getAttrs(token.content, 0, options);\n\n // Apply attributes to the target token\n addAttrs(attrs, targetToken);\n\n // Remove or update token content based on remaining content\n if (token.content.length === attrEndIndex + rightDelimiterLength) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n tokens[index].children!.splice(childIndex, 1);\n } else {\n token.content = token.content.slice(\n attrEndIndex + rightDelimiterLength,\n );\n }\n },\n },\n\n /**\n * *emphasis*{.with attrs=1}\n */\n {\n name: \"inline attributes\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: -1,\n nesting: -1, // closing inline tag, </em>{.a}\n },\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"start\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentToken = tokens[index].children![childIndex];\n const { content } = currentToken;\n\n // Extract attributes from the content\n const attributes = getAttrs(content, 0, options);\n\n // Find the corresponding opening token\n const openingToken = getMatchingOpeningToken(\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n tokens[index].children!,\n childIndex - 1,\n );\n\n // Apply attributes to the opening token\n addAttrs(attributes, openingToken);\n\n // Remove attribute syntax from content\n const attributeEndIndex =\n content.indexOf(options.right) + options.right.length;\n\n currentToken.content = content.slice(attributeEndIndex);\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getListRules = (\n options: Required<DelimiterConfig>,\n): AttrRule[] => [\n /**\n * - item\n * {.a}\n */\n {\n name: \"list softbreak\",\n tests: [\n {\n shift: -2,\n type: \"list_item_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -2,\n type: \"softbreak\",\n },\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const attrs = getAttrs(token.content, 0, options);\n let listOpenIndex = index - 2;\n\n // Find the list opening token\n while (\n tokens[listOpenIndex - 1] &&\n tokens[listOpenIndex - 1].type !== \"ordered_list_open\" &&\n tokens[listOpenIndex - 1].type !== \"bullet_list_open\"\n ) {\n listOpenIndex--;\n }\n\n // Apply attributes to the list opening token\n addAttrs(attrs, tokens[listOpenIndex - 1]);\n\n // Remove the attribute tokens from children\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n tokens[index].children = tokens[index].children!.slice(0, -2);\n },\n },\n\n /**\n * - nested list\n * - with double \\n\n * {.a} <-- apply to nested ul\n *\n * {.b} <-- apply to root <ul>\n */\n {\n name: \"list double softbreak\",\n tests: [\n {\n // let this token be i = 0 so that we can erase\n // the <p>{.a}</p> tokens below\n shift: 0,\n type: (type) =>\n type === \"bullet_list_close\" || type === \"ordered_list_close\",\n },\n {\n shift: 1,\n type: \"paragraph_open\",\n },\n {\n shift: 2,\n type: \"inline\",\n content: getDelimiterChecker(options, \"only\"),\n children: (children) => children.length === 1,\n },\n {\n shift: 3,\n type: \"paragraph_close\",\n },\n ],\n transform: (tokens, index): void => {\n const token = tokens[index + 2];\n const attrs = getAttrs(token.content, 0, options);\n const openingToken = getMatchingOpeningToken(tokens, index);\n\n // Apply attributes to the opening token\n addAttrs(attrs, openingToken);\n\n // Remove the paragraph tokens containing the attributes\n tokens.splice(index + 1, 3);\n },\n },\n\n /**\n * - end of {.list-item}\n */\n {\n name: \"list item end\",\n tests: [\n {\n shift: -2,\n type: \"list_item_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"end\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n\n // Extract attributes from the content\n const attrStartIndex = content.lastIndexOf(options.left);\n const attrs = getAttrs(content, attrStartIndex, options);\n\n // Apply attributes to the list item opening token\n addAttrs(attrs, tokens[index - 2]);\n\n // Remove attribute syntax from content\n const contentWithoutAttributes = content.slice(0, attrStartIndex);\n const hasTrailingSpace =\n contentWithoutAttributes[contentWithoutAttributes.length - 1] === \" \";\n\n token.content = hasTrailingSpace\n ? contentWithoutAttributes.slice(0, -1)\n : contentWithoutAttributes;\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getSoftBreakRule = (\n options: Required<DelimiterConfig>,\n): AttrRule => ({\n /**\n * something with softbreak\n * {.cls}\n */\n\n name: \"\\n{.a} softbreak then curly in start\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -2,\n type: \"softbreak\",\n },\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const attrs = getAttrs(token.content, 0, options);\n\n // Find the last closing tag by searching forward\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Get the corresponding opening token\n const openingToken = getMatchingOpeningToken(tokens, closingTokenIndex);\n\n // Apply attributes to the opening token\n addAttrs(attrs, openingToken);\n\n // Remove the softbreak and attribute tokens\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n tokens[index].children = tokens[index].children!.slice(0, -2);\n },\n});\n","import { escapeRegExp } from \"@mdit/helper\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport { addAttrs, getAttrs } from \"../helper/index.js\";\n\nexport const getHrRule = (options: Required<DelimiterConfig>): AttrRule => ({\n /**\n * horizontal rule --- {#id}\n */\n name: \"horizontal rule\",\n tests: [\n {\n shift: 0,\n type: \"paragraph_open\",\n },\n {\n shift: 1,\n type: \"inline\",\n children: (children) => children.length === 1,\n content: (content) =>\n new RegExp(\n `^ {0,3}[-*_]{3,} ?${escapeRegExp(options.left)}[^${escapeRegExp(\n options.right,\n )}]`,\n ).test(content),\n },\n {\n shift: 2,\n type: \"paragraph_close\",\n },\n ],\n transform: (tokens, index): void => {\n const token = tokens[index];\n\n token.type = \"hr\";\n token.tag = \"hr\";\n token.nesting = 0;\n\n // Extract attributes from the inline content\n const inlineToken = tokens[index + 1];\n const { content } = inlineToken;\n const attributeStartIndex = content.lastIndexOf(options.left);\n const attributes = getAttrs(content, attributeStartIndex, options);\n\n // Apply attributes to the hr token\n addAttrs(attributes, token);\n token.markup = content;\n\n // Remove the inline and closing paragraph tokens\n tokens.splice(index + 1, 2);\n },\n});\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\ninterface TokenWithColumnCount extends Token {\n meta:\n | {\n columnCount?: number;\n [key: string]: unknown;\n }\n | undefined;\n}\n\n/**\n * Hidden table's cells and them inline children,\n * specially cast inline's content as empty\n * to prevent that escapes the table's box model\n */\nconst hideTokenContent = (token: Token): void => {\n token.hidden = true;\n token.children?.forEach((childToken) => {\n childToken.content = \"\";\n hideTokenContent(childToken);\n });\n};\n\n/**\n * Handle rowspan logic for table cells\n */\nconst handleRowspan = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n columnCount: number,\n colspan: number,\n rowspan: number,\n): void => {\n let adjustedColumnCount = columnCount - (colspan > 0 ? colspan : 1);\n\n for (\n let tokenIndex = startIndex, remainingRows = rowspan;\n tokenIndex < endIndex && remainingRows > 1;\n tokenIndex++\n ) {\n if (tokens[tokenIndex].type === \"tr_open\") {\n const trOpenToken = tokens[tokenIndex] as TokenWithColumnCount;\n\n trOpenToken.meta ??= {};\n\n if (trOpenToken.meta.columnCount) {\n adjustedColumnCount -= 1;\n }\n\n trOpenToken.meta.columnCount = adjustedColumnCount;\n remainingRows--;\n }\n }\n};\n\n/**\n * Handle table row processing\n */\nconst handleTableRow = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n): void => {\n const token = tokens[startIndex] as TokenWithColumnCount;\n const expectedColumnCount = token.meta?.columnCount;\n\n if (!expectedColumnCount) return;\n\n // hide extra table cells in the row\n for (let index = startIndex, cellCount = 0; index < endIndex; index++) {\n const currentToken = tokens[index];\n\n // Count table cells in the row\n if (currentToken.type === \"td_open\") {\n cellCount += 1;\n }\n // break at end of table row\n else if (currentToken.type === \"tr_close\") {\n break;\n }\n\n // hide extra table cells\n if (cellCount > expectedColumnCount && !currentToken.hidden) {\n hideTokenContent(currentToken);\n }\n }\n};\n\n/**\n * Handle colspan logic for table cells\n */\nconst handleColspan = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n columnCount: number,\n colspan: number,\n tbodyOpenIndex: number,\n): void => {\n const cellIndices: number[] = [];\n const startToken = tokens[startIndex];\n\n let end = startIndex + 3;\n let colspanNum = columnCount;\n\n // Find previous row children indices\n for (let tokenIndex = startIndex; tokenIndex > tbodyOpenIndex; tokenIndex--) {\n if (tokens[tokenIndex].type === \"tr_open\") {\n colspanNum =\n (tokens[tokenIndex] as TokenWithColumnCount).meta?.columnCount ??\n colspanNum;\n break;\n } else if (tokens[tokenIndex].type === \"td_open\") {\n cellIndices.unshift(tokenIndex);\n }\n }\n\n // Find current row children indices\n for (let index = startIndex + 2; index < endIndex; index++) {\n if (tokens[index].type === \"tr_close\") {\n end = index;\n break;\n } else if (tokens[index].type === \"td_open\") {\n cellIndices.push(index);\n }\n }\n\n const cellOffset = cellIndices.indexOf(startIndex);\n\n const realColspan = Math.min(colspan, colspanNum - cellOffset);\n\n if (colspan > realColspan) {\n startToken.attrSet(\"colspan\", realColspan.toString());\n }\n\n const hiddenStartIndex = cellIndices.slice(\n colspanNum + 1 - columnCount - realColspan,\n )[0];\n\n for (let index = hiddenStartIndex; index < end; index++) {\n if (!tokens[index].hidden) hideTokenContent(tokens[index]);\n }\n};\n\nexport const getTableRules = (\n options: Required<DelimiterConfig>,\n): AttrRule[] => [\n {\n /**\n * | h1 |\n * | -- |\n * | c1 |\n *\n * {.c}\n */\n name: \"table\",\n tests: [\n {\n // let this token be i, such that for-loop continues at\n // next token after tokens.splice\n shift: 0,\n type: \"table_close\",\n },\n {\n shift: 1,\n type: \"paragraph_open\",\n },\n {\n shift: 2,\n type: \"inline\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n transform: (tokens, index): void => {\n const token = tokens[index + 2];\n const tableOpeningToken = getMatchingOpeningToken(tokens, index);\n const attrs = getAttrs(token.content, 0, options);\n\n // Apply attributes to the table opening token\n addAttrs(attrs, tableOpeningToken);\n\n // Remove the paragraph tokens containing the attributes\n tokens.splice(index + 1, 3);\n },\n },\n /**\n * Handle table cell attributes: title {.class}\n * This rule processes attributes within table cell text content\n */\n {\n name: \"table cell attributes\",\n tests: [\n {\n shift: -1,\n type: (type) => type === \"td_open\" || type === \"th_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"end\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const cellOpenToken = tokens[index - 1];\n const { content } = token;\n\n // Find last attribute syntax in the content\n const attrStartIndex = content.lastIndexOf(options.left);\n\n // Extract attributes from the content\n const attributes = getAttrs(content, attrStartIndex, options);\n\n // Apply attributes to the table cell token\n addAttrs(attributes, cellOpenToken);\n\n // Remove attribute syntax from content\n token.content = content.substring(0, attrStartIndex).trim();\n },\n },\n {\n /**\n * | A | B |\n * | -- | -- |\n * | 1 | 2 |\n *\n * | C | D |\n * | -- | -- |\n *\n * only `| A | B |` sets the columnCount metadata\n */\n name: \"table thead metadata\",\n tests: [\n {\n shift: 0,\n type: \"tr_close\",\n },\n {\n shift: 1,\n type: \"thead_close\",\n },\n {\n shift: 2,\n type: \"tbody_open\",\n },\n ],\n\n transform: (tokens, index): void => {\n const trOpenToken = getMatchingOpeningToken(tokens, index);\n const thCloseToken = tokens[index - 1];\n let columnCount = 0;\n let currentIndex = index - 1;\n\n // Find the matching tr_open token and count columns\n while (currentIndex > 0) {\n const currentToken = tokens[currentIndex];\n\n if (currentToken === trOpenToken) {\n const tHeadOpenToken = tokens[\n currentIndex - 1\n ] as TokenWithColumnCount;\n\n tHeadOpenToken.meta = {\n ...tHeadOpenToken.meta,\n columnCount,\n };\n break;\n }\n\n // Count th_close tokens at the same level\n if (\n currentToken.level === thCloseToken.level &&\n currentToken.type === thCloseToken.type\n ) {\n columnCount++;\n }\n\n currentIndex--;\n }\n\n // Apply metadata to tbody_open token\n const tbodyOpenToken = tokens[index + 2] as TokenWithColumnCount;\n\n tbodyOpenToken.meta = {\n ...tbodyOpenToken.meta,\n columnCount,\n };\n },\n },\n {\n /**\n * | A | B | C | D |\n * | -- | -- | -- | -- |\n * | 1 | 11 | 111 | 1111 {rowspan=3} |\n * | 2 {colspan=2 rowspan=2} | 22 | 222 | 2222 |\n * | 3 | 33 | 333 | 3333 |\n */\n name: \"table tbody calculate\",\n tests: [\n {\n shift: 0,\n type: \"tbody_close\",\n hidden: false,\n },\n ],\n transform: (tokens, index): void => {\n // Find the tbody_open token index\n let tbodyOpenIndex = index - 2;\n\n while (tbodyOpenIndex > 0) {\n tbodyOpenIndex--;\n if (tokens[tbodyOpenIndex].type === \"tbody_open\") break;\n }\n\n const columnCount = Number(\n (tokens[tbodyOpenIndex] as TokenWithColumnCount).meta?.columnCount ?? 0,\n );\n\n if (columnCount < 2) return;\n\n const maxLevel = tokens[index].level + 2;\n\n for (\n let currentIndex = tbodyOpenIndex;\n currentIndex < index;\n currentIndex++\n ) {\n if (tokens[currentIndex].level > maxLevel) continue;\n\n const token = tokens[currentIndex];\n const rowspan = token.hidden ? 0 : Number(token.attrGet(\"rowspan\"));\n const colspan = token.hidden ? 0 : Number(token.attrGet(\"colspan\"));\n\n if (rowspan > 1) {\n handleRowspan(\n tokens,\n currentIndex,\n index,\n columnCount,\n colspan,\n rowspan,\n );\n }\n\n if (token.type === \"tr_open\") {\n handleTableRow(tokens, currentIndex, index);\n }\n\n if (colspan > 1) {\n handleColspan(\n tokens,\n currentIndex,\n index,\n columnCount,\n colspan,\n tbodyOpenIndex,\n );\n }\n }\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type {\n MarkdownItAttrRuleName,\n MarkdownItAttrsOptions,\n} from \"../options.js\";\nimport { getBlockRule } from \"./block.js\";\nimport { getFenceRule } from \"./fence.js\";\nimport { getHrRule } from \"./hr.js\";\nimport { getInlineRules } from \"./inline.js\";\nimport { getListRules } from \"./list.js\";\nimport { getSoftBreakRule } from \"./softbreak.js\";\nimport { getTableRules } from \"./table.js\";\n\nconst AVAILABLE_RULES: MarkdownItAttrRuleName[] = [\n \"fence\",\n \"inline\",\n \"table\",\n \"list\",\n \"hr\",\n \"softbreak\",\n \"block\",\n];\n\nexport const getRules = (\n options: Required<MarkdownItAttrsOptions>,\n): AttrRule[] => {\n const enabledRules =\n // disable\n options.rule === false\n ? []\n : Array.isArray(options.rule)\n ? // user specific rules\n options.rule.filter((item) => AVAILABLE_RULES.includes(item))\n : AVAILABLE_RULES;\n\n const rules: AttrRule[] = [];\n\n if (enabledRules.includes(\"fence\")) rules.push(getFenceRule(options));\n if (enabledRules.includes(\"inline\")) rules.push(...getInlineRules(options));\n if (enabledRules.includes(\"table\")) rules.push(...getTableRules(options));\n if (enabledRules.includes(\"list\")) rules.push(...getListRules(options));\n if (enabledRules.includes(\"softbreak\")) rules.push(getSoftBreakRule(options));\n if (enabledRules.includes(\"hr\")) rules.push(getHrRule(options));\n if (enabledRules.includes(\"block\")) rules.push(getBlockRule(options));\n\n return rules;\n};\n","/**\n * Forked and modified from https://github.com/arve0/markdown-it-attrs/\n */\n\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type { RuleCore } from \"markdown-it/lib/parser_core.mjs\";\n\nimport { testRule } from \"./helper/index.js\";\nimport type { MarkdownItAttrsOptions } from \"./options.js\";\nimport { getRules } from \"./rules/index.js\";\n\nexport const attrs: PluginWithOptions<MarkdownItAttrsOptions> = (\n md,\n { left = \"{\", right = \"}\", allowed = [], rule = \"all\" } = {},\n) => {\n const rules = getRules({\n left,\n right,\n allowed,\n rule,\n });\n\n const attrsRule: RuleCore = ({ tokens }) => {\n for (let index = 0; index < tokens.length; index++)\n for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex++) {\n const pattern = rules[ruleIndex];\n // position of child with offset 0\n let position: null | number = null;\n\n const match = pattern.tests.every((t) => {\n const result = testRule(tokens, index, t);\n\n if (result.position !== null) ({ position } = result);\n\n return result.match;\n });\n\n if (match) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n pattern.transform(tokens, index, position!);\n\n if (\n pattern.name === \"inline attributes\" ||\n pattern.name === \"inline nesting self-close\"\n )\n // retry, may be several inline attributes\n ruleIndex--;\n }\n }\n };\n\n md.core.ruler.before(\"linkify\", \"attrs\", attrsRule);\n};\n"],"names":["addAttrs","attrs","token","key","value","CLASS_MARKER","ID_MARKER","ALLOWED_KEY_CHARS","PAIR_SEPARATOR","KEY_SEPARATOR","getAttrs","str","start","left","right","allowed","parsingKey","valueInsideQuotes","index","char","attr","item","getDelimiterChecker","where","content","leftLength","rightLength","minCurlyLength","rightDelimiterMinimumShift","validCurlyLength","curly","end","slice","nextChar","getMatchingOpeningToken","tokens","level","type","currentToken","g","removeDelimiter","escapeRegExp","pos","getArrayItem","arr","isArrayOfFunctions","isArrayOfObjects","testRule","rule","result","tokenIndex","match","childTests","children","childTest","position","ruleDetail","ruleItem","getBlockRule","options","childIndex","attrStartIndex","closingTokenIndex","openingToken","contentWithoutAttributes","hasTrailingSpace","getFenceRule","lineNumbers","lineNumberMatch","attributeStartIndex","attributes","infoWithoutAttributes","getInlineRules","rightDelimiterLength","attrEndIndex","targetToken","attributeEndIndex","getListRules","listOpenIndex","getSoftBreakRule","getHrRule","inlineToken","hideTokenContent","childToken","handleRowspan","startIndex","endIndex","columnCount","colspan","rowspan","adjustedColumnCount","remainingRows","trOpenToken","handleTableRow","expectedColumnCount","cellCount","handleColspan","tbodyOpenIndex","cellIndices","startToken","colspanNum","cellOffset","realColspan","hiddenStartIndex","getTableRules","tableOpeningToken","cellOpenToken","thCloseToken","currentIndex","tHeadOpenToken","tbodyOpenToken","maxLevel","AVAILABLE_RULES","getRules","enabledRules","rules","md","attrsRule","ruleIndex","pattern","t"],"mappings":"AAIO,MAAMA,EAAW,CAACC,EA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":3,"file":"browser.js","sources":["../src/helper/constants.ts","../src/helper/getAttrs.ts","../src/helper/addAttrs.ts","../src/helper/getDelimiterChecker.ts","../src/helper/getMatchingOpeningToken.ts","../src/utils.ts","../src/helper/testRule.ts","../../../node_modules/.pnpm/markdown-it@14.1.0/node_modules/markdown-it/lib/common/utils.mjs","../src/rules/block.ts","../src/rules/fence.ts","../src/rules/heading.ts","../src/rules/inline.ts","../src/rules/list.ts","../src/rules/softbreak.ts","../src/rules/hr.ts","../src/rules/table.ts","../src/rules/rules.ts","../src/plugin.ts"],"sourcesContent":["/** . */\nexport const CLASS_MARKER = 46;\n/** # */\nexport const ID_MARKER = 35;\n/** space */\nexport const PAIR_SEPARATOR = 32;\n/** = */\nexport const KEY_SEPARATOR = 61;\n/** \" */\nexport const QUOTE_MARKER = 34;\n","import {\n CLASS_MARKER,\n ID_MARKER,\n KEY_SEPARATOR,\n PAIR_SEPARATOR,\n QUOTE_MARKER,\n} from \"./constants.js\";\nimport type { Attr } from \"./types.js\";\nimport type { DelimiterRange } from \"../rules/types.js\";\n\nconst isAllowedKeyChar = (charCode: number): boolean =>\n !(\n charCode === 9 /* \\t */ ||\n charCode === 10 /* \\n */ ||\n charCode === 12 /* \\f */ ||\n charCode === 32 /* 空格 */ ||\n charCode === 47 /* / */ ||\n charCode === 62 /* > */ ||\n charCode === 34 /* \" */ ||\n charCode === 39 /* ' */ ||\n charCode === 61 /* = */\n );\n\nexport const getAttrs = (\n str: string,\n range: DelimiterRange,\n allowed: (string | RegExp)[],\n): Attr[] => {\n let key = \"\";\n let value = \"\";\n let parsingKey = true;\n let valueInsideQuotes = false;\n\n const attrs: Attr[] = [];\n\n // read inside marker\n // start + left delimiter length to avoid beginning marker\n // breaks when ending marker is found or end of string\n for (let index = range[0]; index < range[1]; index++) {\n const charCode = str.charCodeAt(index);\n\n // switch to reading value if equal sign\n if (charCode === KEY_SEPARATOR && parsingKey) {\n parsingKey = false;\n continue;\n }\n\n // {.class} {..css-module}\n if (charCode === CLASS_MARKER && key === \"\") {\n if (str.charCodeAt(index + 1) === CLASS_MARKER) {\n key = \"css-module\";\n index++;\n } else {\n key = \"class\";\n }\n\n parsingKey = false;\n continue;\n }\n\n // {#id}\n if (charCode === ID_MARKER && key === \"\") {\n key = \"id\";\n parsingKey = false;\n continue;\n }\n\n // {value=\"inside quotes\"}\n if (charCode === QUOTE_MARKER && value === \"\" && !valueInsideQuotes) {\n valueInsideQuotes = true;\n continue;\n }\n\n if (charCode === QUOTE_MARKER && valueInsideQuotes) {\n valueInsideQuotes = false;\n continue;\n }\n\n // read next key/value pair\n if (charCode === PAIR_SEPARATOR && !valueInsideQuotes) {\n if (key === \"\")\n // beginning or ending space: { .red } vs {.red}\n continue;\n\n attrs.push([key, value]);\n key = \"\";\n value = \"\";\n parsingKey = true;\n\n continue;\n }\n\n // continue if character not allowed\n if (parsingKey && !isAllowedKeyChar(charCode)) continue;\n\n // no other conditions met; append to key/value\n if (parsingKey) {\n key += String.fromCharCode(charCode);\n continue;\n }\n\n value += String.fromCharCode(charCode);\n }\n\n // append last key/value pair\n if (key !== \"\") attrs.push([key, value]);\n\n return allowed.length\n ? attrs.filter(([attr]) =>\n allowed.some((item) =>\n item instanceof RegExp ? item.test(attr) : item === attr,\n ),\n )\n : attrs;\n};\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nimport { getAttrs } from \"./getAttrs.js\";\nimport type { DelimiterRange } from \"../rules/types.js\";\n\nexport const addAttrs = (\n token: Token | null,\n content: string,\n range: DelimiterRange,\n allowed: (string | RegExp)[],\n): void => {\n if (!token) return;\n\n getAttrs(content, range, allowed).forEach(([key, value]) => {\n switch (key) {\n case \"class\":\n token.attrJoin(\"class\", value);\n break;\n case \"css-module\":\n token.attrJoin(\"css-module\", value);\n break;\n default:\n token.attrPush([key, value]);\n }\n });\n};\n","import { CLASS_MARKER, ID_MARKER } from \"./constants.js\";\nimport type { DelimiterConfig } from \"./types.js\";\nimport type { DelimiterChecker } from \"../rules/types.js\";\n\n/**\n * Get a function to check if a string matches the delimiter pattern\n * 获取一个函数来检查字符串是否匹配分隔符模式\n *\n * @param options - Delimiter configuration / 分隔符配置\n * @param where - Position for matching: start, end, or only / 匹配位置:开始、结束或仅匹配\n * @returns A function that checks if content matches the delimiter pattern / 检查内容是否匹配分隔符模式的函数\n */\nexport const getDelimiterChecker = (\n { left, right }: DelimiterConfig,\n where: \"start\" | \"end\" | \"only\",\n): DelimiterChecker => {\n if (![\"start\", \"end\", \"only\"].includes(where)) {\n throw new Error(\n `Invalid 'where' parameter: ${where}. Expected 'start', 'end', or 'only'.`,\n );\n }\n\n // Cache frequently used values\n const leftLength = left.length;\n const rightLength = right.length;\n const minContentLength = leftLength + 1 + rightLength;\n\n return (content) => {\n // Quick check for minimum length requirements\n if (typeof content !== \"string\" || content.length < minContentLength)\n return false;\n\n let start: number;\n let end: number;\n\n if (where === \"start\") {\n // Check if content starts with left delimiter\n if (!content.startsWith(left)) return false;\n\n start = leftLength;\n end = content.indexOf(right, leftLength + 1);\n\n if (end === -1) return false;\n\n // Check if next character is not part of right delimiter\n const nextCharPos = end + rightLength;\n\n if (\n nextCharPos < content.length &&\n right.includes(content.charAt(nextCharPos))\n ) {\n return false;\n }\n } else if (where === \"end\") {\n // Check if content ends with right delimiter\n start = content.lastIndexOf(left);\n\n if (start === -1) {\n return false;\n }\n\n end = content.indexOf(right, start + leftLength + 1);\n start += leftLength;\n\n if (end === -1 || end + rightLength !== content.length) {\n return false;\n }\n } else {\n // Check if content is wrapped by delimiters ('{.a}')\n if (!content.startsWith(left) || !content.endsWith(right)) return false;\n\n start = leftLength;\n end = content.length - rightLength;\n }\n\n // Check if content between delimiters is valid\n const firstCharCode = content.charCodeAt(start);\n const length = end - start;\n\n const isValid =\n firstCharCode === CLASS_MARKER || firstCharCode === ID_MARKER\n ? length >= 2\n : length >= 1;\n\n if (!isValid) return false;\n\n return [start, end];\n };\n};\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nexport const getMatchingOpeningToken = (\n tokens: Token[],\n index: number,\n): Token | null => {\n const token = tokens[index];\n\n if (token.type === \"softbreak\") return null;\n\n // non closing blocks, example img\n if (token.nesting === 0) return token;\n\n const level = token.level;\n const type = token.type.replace(\"_close\", \"_open\");\n\n while (index >= 0) {\n const currentToken = tokens[index];\n\n if (currentToken.type === type && currentToken.level === level)\n return currentToken;\n\n index--;\n }\n\n /* istanbul ignore next -- @preserve */\n return null;\n};\n","/**\n * Get index item of array. Supports negative index, where -1 is last element in array.\n *\n * 获取数组中的索引项。支持负索引,其中 -1 是数组的最后一个元素。\n *\n * @param arr - Array to get item from / 要获取项的数组\n * @param index - Index of item / 项的索引\n * @returns Array item / 数组项\n */\nexport const getArrayItem = <T>(arr: T[], index: number): T =>\n index >= 0 ? arr[index] : arr[arr.length + index];\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { AttrRuleSet } from \"../rules/types.js\";\nimport { getArrayItem } from \"../utils.js\";\n\nexport interface TestRuleResult {\n /** whether rule matches token stream */\n match: boolean;\n /** position of token */\n position: null | number;\n range: [start: number, end: number] | null;\n}\n\n/**\n * Test if rule matches token stream.\n *\n */\nexport const testRule = (\n tokens: Token[],\n index: number,\n rule: AttrRuleSet,\n): TestRuleResult => {\n const testResult: TestRuleResult = {\n match: false,\n position: null,\n range: null,\n };\n const isShift = rule.shift !== undefined;\n\n const tokenIndex = isShift ? index + rule.shift : rule.position;\n\n // we should never shift to negative indexes (rolling around to back of array)\n if (isShift && tokenIndex < 0) return testResult;\n\n const token = getArrayItem(tokens, tokenIndex);\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!token) return testResult;\n\n for (const key of Object.keys(rule) as (keyof typeof rule)[]) {\n if (key === \"shift\" || key === \"position\") continue;\n\n if (token[key as keyof Token] == undefined) return testResult;\n\n if (key === \"children\" && Array.isArray(rule.children)) {\n if (!token.children?.length) return testResult;\n\n const childTests = rule.children;\n const children = token.children;\n let match;\n let range: [start: number, end: number] | null = null;\n\n if (childTests.every((childTest) => childTest.position != undefined)) {\n // positions instead of shifts, do not loop all children\n match = childTests.every((childTest) => {\n const result = testRule(children, childTest.position, childTest);\n\n if (!result.match) return false;\n\n if (result.range) range = result.range;\n\n return true;\n });\n\n if (match) {\n // get position of child\n const { position } = childTests[childTests.length - 1];\n\n testResult.position =\n position >= 0 ? position : children.length + position;\n\n // set pos data\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n testResult.range = range!;\n }\n } else {\n for (let childIndex = 0; childIndex < children.length; childIndex++) {\n match = childTests.every((childTest) => {\n const result = testRule(children, childIndex, childTest);\n\n if (!result.match) return false;\n\n if (result.range) range = result.range;\n\n return true;\n });\n\n if (match) {\n testResult.position = childIndex;\n // set pos data\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (range) testResult.range = range;\n // all tests passes. so the check is successful\n break;\n }\n }\n }\n\n if (match === false) return testResult;\n\n continue;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const ruleDetail = rule[key];\n\n switch (typeof ruleDetail) {\n case \"boolean\":\n case \"number\":\n case \"string\": {\n if (token[key] !== ruleDetail) return testResult;\n\n break;\n }\n\n case \"function\": {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n const result = ruleDetail(token[key]) as\n | boolean\n | [start: number, end: number];\n\n if (!result) return testResult;\n\n if (Array.isArray(result)) testResult.range = result;\n\n break;\n }\n\n // fall through for objects !== arrays of functions\n default: {\n throw new Error(\n `Unknown type of pattern test (key: ${key}). Test should be of type boolean, number, string or function.`,\n );\n }\n }\n }\n\n // no tests returned false -> all tests returns true\n testResult.match = true;\n\n return testResult;\n};\n","// Utilities\n//\n\nimport * as mdurl from 'mdurl'\nimport * as ucmicro from 'uc.micro'\nimport { decodeHTML } from 'entities'\n\nfunction _class (obj) { return Object.prototype.toString.call(obj) }\n\nfunction isString (obj) { return _class(obj) === '[object String]' }\n\nconst _hasOwnProperty = Object.prototype.hasOwnProperty\n\nfunction has (object, key) {\n return _hasOwnProperty.call(object, key)\n}\n\n// Merge objects\n//\nfunction assign (obj /* from1, from2, from3, ... */) {\n const sources = Array.prototype.slice.call(arguments, 1)\n\n sources.forEach(function (source) {\n if (!source) { return }\n\n if (typeof source !== 'object') {\n throw new TypeError(source + 'must be object')\n }\n\n Object.keys(source).forEach(function (key) {\n obj[key] = source[key]\n })\n })\n\n return obj\n}\n\n// Remove element from array and put another array at those position.\n// Useful for some operations with tokens\nfunction arrayReplaceAt (src, pos, newElements) {\n return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1))\n}\n\nfunction isValidEntityCode (c) {\n /* eslint no-bitwise:0 */\n // broken sequence\n if (c >= 0xD800 && c <= 0xDFFF) { return false }\n // never used\n if (c >= 0xFDD0 && c <= 0xFDEF) { return false }\n if ((c & 0xFFFF) === 0xFFFF || (c & 0xFFFF) === 0xFFFE) { return false }\n // control codes\n if (c >= 0x00 && c <= 0x08) { return false }\n if (c === 0x0B) { return false }\n if (c >= 0x0E && c <= 0x1F) { return false }\n if (c >= 0x7F && c <= 0x9F) { return false }\n // out of range\n if (c > 0x10FFFF) { return false }\n return true\n}\n\nfunction fromCodePoint (c) {\n /* eslint no-bitwise:0 */\n if (c > 0xffff) {\n c -= 0x10000\n const surrogate1 = 0xd800 + (c >> 10)\n const surrogate2 = 0xdc00 + (c & 0x3ff)\n\n return String.fromCharCode(surrogate1, surrogate2)\n }\n return String.fromCharCode(c)\n}\n\nconst UNESCAPE_MD_RE = /\\\\([!\"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_`{|}~])/g\nconst ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi\nconst UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.source, 'gi')\n\nconst DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i\n\nfunction replaceEntityPattern (match, name) {\n if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) {\n const code = name[1].toLowerCase() === 'x'\n ? parseInt(name.slice(2), 16)\n : parseInt(name.slice(1), 10)\n\n if (isValidEntityCode(code)) {\n return fromCodePoint(code)\n }\n\n return match\n }\n\n const decoded = decodeHTML(match)\n if (decoded !== match) {\n return decoded\n }\n\n return match\n}\n\n/* function replaceEntities(str) {\n if (str.indexOf('&') < 0) { return str; }\n\n return str.replace(ENTITY_RE, replaceEntityPattern);\n} */\n\nfunction unescapeMd (str) {\n if (str.indexOf('\\\\') < 0) { return str }\n return str.replace(UNESCAPE_MD_RE, '$1')\n}\n\nfunction unescapeAll (str) {\n if (str.indexOf('\\\\') < 0 && str.indexOf('&') < 0) { return str }\n\n return str.replace(UNESCAPE_ALL_RE, function (match, escaped, entity) {\n if (escaped) { return escaped }\n return replaceEntityPattern(match, entity)\n })\n}\n\nconst HTML_ESCAPE_TEST_RE = /[&<>\"]/\nconst HTML_ESCAPE_REPLACE_RE = /[&<>\"]/g\nconst HTML_REPLACEMENTS = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;'\n}\n\nfunction replaceUnsafeChar (ch) {\n return HTML_REPLACEMENTS[ch]\n}\n\nfunction escapeHtml (str) {\n if (HTML_ESCAPE_TEST_RE.test(str)) {\n return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar)\n }\n return str\n}\n\nconst REGEXP_ESCAPE_RE = /[.?*+^$[\\]\\\\(){}|-]/g\n\nfunction escapeRE (str) {\n return str.replace(REGEXP_ESCAPE_RE, '\\\\$&')\n}\n\nfunction isSpace (code) {\n switch (code) {\n case 0x09:\n case 0x20:\n return true\n }\n return false\n}\n\n// Zs (unicode class) || [\\t\\f\\v\\r\\n]\nfunction isWhiteSpace (code) {\n if (code >= 0x2000 && code <= 0x200A) { return true }\n switch (code) {\n case 0x09: // \\t\n case 0x0A: // \\n\n case 0x0B: // \\v\n case 0x0C: // \\f\n case 0x0D: // \\r\n case 0x20:\n case 0xA0:\n case 0x1680:\n case 0x202F:\n case 0x205F:\n case 0x3000:\n return true\n }\n return false\n}\n\n/* eslint-disable max-len */\n\n// Currently without astral characters support.\nfunction isPunctChar (ch) {\n return ucmicro.P.test(ch) || ucmicro.S.test(ch)\n}\n\n// Markdown ASCII punctuation characters.\n//\n// !, \", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \\, ], ^, _, `, {, |, }, or ~\n// http://spec.commonmark.org/0.15/#ascii-punctuation-character\n//\n// Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.\n//\nfunction isMdAsciiPunct (ch) {\n switch (ch) {\n case 0x21/* ! */:\n case 0x22/* \" */:\n case 0x23/* # */:\n case 0x24/* $ */:\n case 0x25/* % */:\n case 0x26/* & */:\n case 0x27/* ' */:\n case 0x28/* ( */:\n case 0x29/* ) */:\n case 0x2A/* * */:\n case 0x2B/* + */:\n case 0x2C/* , */:\n case 0x2D/* - */:\n case 0x2E/* . */:\n case 0x2F/* / */:\n case 0x3A/* : */:\n case 0x3B/* ; */:\n case 0x3C/* < */:\n case 0x3D/* = */:\n case 0x3E/* > */:\n case 0x3F/* ? */:\n case 0x40/* @ */:\n case 0x5B/* [ */:\n case 0x5C/* \\ */:\n case 0x5D/* ] */:\n case 0x5E/* ^ */:\n case 0x5F/* _ */:\n case 0x60/* ` */:\n case 0x7B/* { */:\n case 0x7C/* | */:\n case 0x7D/* } */:\n case 0x7E/* ~ */:\n return true\n default:\n return false\n }\n}\n\n// Hepler to unify [reference labels].\n//\nfunction normalizeReference (str) {\n // Trim and collapse whitespace\n //\n str = str.trim().replace(/\\s+/g, ' ')\n\n // In node v10 'ẞ'.toLowerCase() === 'Ṿ', which is presumed to be a bug\n // fixed in v12 (couldn't find any details).\n //\n // So treat this one as a special case\n // (remove this when node v10 is no longer supported).\n //\n if ('ẞ'.toLowerCase() === 'Ṿ') {\n str = str.replace(/ẞ/g, 'ß')\n }\n\n // .toLowerCase().toUpperCase() should get rid of all differences\n // between letter variants.\n //\n // Simple .toLowerCase() doesn't normalize 125 code points correctly,\n // and .toUpperCase doesn't normalize 6 of them (list of exceptions:\n // İ, ϴ, ẞ, Ω, K, Å - those are already uppercased, but have differently\n // uppercased versions).\n //\n // Here's an example showing how it happens. Lets take greek letter omega:\n // uppercase U+0398 (Θ), U+03f4 (ϴ) and lowercase U+03b8 (θ), U+03d1 (ϑ)\n //\n // Unicode entries:\n // 0398;GREEK CAPITAL LETTER THETA;Lu;0;L;;;;;N;;;;03B8;\n // 03B8;GREEK SMALL LETTER THETA;Ll;0;L;;;;;N;;;0398;;0398\n // 03D1;GREEK THETA SYMBOL;Ll;0;L;<compat> 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398\n // 03F4;GREEK CAPITAL THETA SYMBOL;Lu;0;L;<compat> 0398;;;;N;;;;03B8;\n //\n // Case-insensitive comparison should treat all of them as equivalent.\n //\n // But .toLowerCase() doesn't change ϑ (it's already lowercase),\n // and .toUpperCase() doesn't change ϴ (already uppercase).\n //\n // Applying first lower then upper case normalizes any character:\n // '\\u0398\\u03f4\\u03b8\\u03d1'.toLowerCase().toUpperCase() === '\\u0398\\u0398\\u0398\\u0398'\n //\n // Note: this is equivalent to unicode case folding; unicode normalization\n // is a different step that is not required here.\n //\n // Final result should be uppercased, because it's later stored in an object\n // (this avoid a conflict with Object.prototype members,\n // most notably, `__proto__`)\n //\n return str.toLowerCase().toUpperCase()\n}\n\n// Re-export libraries commonly used in both markdown-it and its plugins,\n// so plugins won't have to depend on them explicitly, which reduces their\n// bundled size (e.g. a browser build).\n//\nconst lib = { mdurl, ucmicro }\n\nexport {\n lib,\n assign,\n isString,\n has,\n unescapeMd,\n unescapeAll,\n isValidEntityCode,\n fromCodePoint,\n escapeHtml,\n arrayReplaceAt,\n isSpace,\n isWhiteSpace,\n isMdAsciiPunct,\n isPunctChar,\n escapeRE,\n normalizeReference\n}\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getBlockRule = (options: DelimiterConfig): AttrRule =>\n /**\n * end of {.block}\n */\n ({\n name: \"end of block\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n content: getDelimiterChecker(options, \"end\"),\n type: (type) => type !== \"code_inline\" && type !== \"math_inline\",\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n const attrStartIndex = range[0] - options.left.length;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n const hasTrailingSpace = isSpace(content.charCodeAt(attrStartIndex - 1));\n\n // Find the closing token by skipping all nested closing tokens\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Get the corresponding opening token\n const openingToken = getMatchingOpeningToken(tokens, closingTokenIndex);\n\n // Apply attributes to the opening token\n addAttrs(openingToken, content, range, options.allowed);\n\n // Remove the attribute syntax from content\n token.content = content.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n });\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport { addAttrs, getDelimiterChecker } from \"../helper/index.js\";\n\nexport const getFenceRule = (options: DelimiterConfig): AttrRule =>\n /**\n * fenced code blocks\n *\n * ```python {.cls}\n * for i in range(10):\n * print(i)\n * ```\n */\n ({\n name: \"code-block\",\n tests: [\n {\n shift: 0,\n block: true,\n info: getDelimiterChecker(options, \"end\"),\n },\n ],\n transform: (tokens, index, _, range): void => {\n const attrStartIndex = range[0] - options.left.length;\n const token = tokens[index];\n const { info } = token;\n const hasTrailingSpace = isSpace(info.charCodeAt(attrStartIndex - 1));\n\n // Apply attributes to the current token\n addAttrs(token, info, range, options.allowed);\n\n // Remove the attribute syntax from info\n token.info = info.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n });\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getHeadingRule = (options: DelimiterConfig): AttrRule =>\n /**\n * ## end of {#heading}\n */\n ({\n name: \"end of block\",\n tests: [\n {\n shift: -1,\n type: \"heading_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n content: getDelimiterChecker(options, \"end\"),\n type: (type) => type !== \"code_inline\" && type !== \"math_inline\",\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n const attrStartIndex = range[0] - options.left.length;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n const hasTrailingSpace = isSpace(content.charCodeAt(attrStartIndex - 1));\n\n // Find the closing token by skipping all nested closing tokens\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Get the corresponding opening token\n const openingToken = getMatchingOpeningToken(tokens, closingTokenIndex);\n\n // Apply attributes to the opening token\n addAttrs(openingToken, content, range, options.allowed);\n\n // Remove the attribute syntax from content\n token.content = content.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n });\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getInlineRules = (options: DelimiterConfig): AttrRule[] => [\n /**\n * bla `click()`{.c} ![](img.png){.d}\n *\n * differs from 'inline attributes' as it does\n * not have a closing tag (nesting: -1)\n */\n {\n name: \"inline nesting self-close\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: -1,\n type: (str) => str === \"image\" || str === \"code_inline\",\n },\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"start\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const childTokens = tokens[index].children!;\n const token = childTokens[childIndex];\n const targetToken = childTokens[childIndex - 1];\n const attrsEndIndex = options.right.length + range[1];\n\n // Apply attributes to the target token\n addAttrs(targetToken, token.content, range, options.allowed);\n\n if (token.content.length === attrsEndIndex) {\n childTokens.splice(childIndex, 1);\n } else {\n token.content = token.content.slice(attrsEndIndex);\n }\n },\n },\n\n /**\n * *emphasis*{.with attrs=1}\n */\n {\n name: \"inline attributes\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: -1,\n nesting: -1, // closing inline tag, </em>{.a}\n },\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"start\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const childTokens = tokens[index].children!;\n const currentToken = childTokens[childIndex];\n const { content } = currentToken;\n const attrsEndIndex = options.right.length + range[1];\n\n // Find the corresponding opening token\n const openingToken = getMatchingOpeningToken(childTokens, childIndex - 1);\n\n // Apply attributes to the opening token\n addAttrs(openingToken, content, range, options.allowed);\n\n // Remove attribute syntax from content\n currentToken.content = content.slice(attrsEndIndex);\n },\n },\n];\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getListRules = (options: DelimiterConfig): AttrRule[] => [\n /**\n * - item\n * {.a}\n */\n {\n name: \"list softbreak\",\n tests: [\n {\n shift: -2,\n type: \"list_item_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -2,\n type: \"softbreak\",\n },\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const childTokens = tokens[index].children!;\n const token = childTokens[childIndex];\n\n let listOpenIndex = index - 2;\n\n // Find the list opening token\n while (\n tokens[listOpenIndex - 1] &&\n tokens[listOpenIndex - 1].type !== \"ordered_list_open\" &&\n tokens[listOpenIndex - 1].type !== \"bullet_list_open\"\n ) {\n listOpenIndex--;\n }\n\n // Apply attributes to the list opening token\n addAttrs(\n tokens[listOpenIndex - 1],\n token.content,\n range,\n options.allowed,\n );\n\n // Remove the attribute tokens from children\n tokens[index].children = childTokens.slice(0, -2);\n },\n },\n\n /**\n * - nested list\n * - with double \\n\n * {.a} <-- apply to nested ul\n *\n * {.b} <-- apply to root <ul>\n */\n {\n name: \"list double softbreak\",\n tests: [\n {\n // let this token be i = 0 so that we can erase\n // the <p>{.a}</p> tokens below\n shift: 0,\n type: (type) =>\n type === \"bullet_list_close\" || type === \"ordered_list_close\",\n },\n {\n shift: 1,\n type: \"paragraph_open\",\n },\n {\n shift: 2,\n type: \"inline\",\n content: getDelimiterChecker(options, \"only\"),\n children: (children) => children.length === 1,\n },\n {\n shift: 3,\n type: \"paragraph_close\",\n },\n ],\n transform: (tokens, index, _, range): void => {\n const token = tokens[index + 2];\n const openingToken = getMatchingOpeningToken(tokens, index);\n\n // Apply attributes to the opening token\n addAttrs(openingToken, token.content, range, options.allowed);\n\n // Remove the paragraph tokens containing the attributes\n tokens.splice(index + 1, 3);\n },\n },\n\n /**\n * - end of {.list-item}\n */\n {\n name: \"list item end\",\n tests: [\n {\n shift: -2,\n type: \"list_item_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"end\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n const attrStartIndex = range[0] - options.left.length;\n const hasTrailingSpace = isSpace(content.charCodeAt(attrStartIndex - 1));\n\n // Apply attributes to the list item opening token\n addAttrs(tokens[index - 2], content, range, options.allowed);\n\n // Remove attribute syntax from content\n token.content = content.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getSoftBreakRule = (options: DelimiterConfig): AttrRule => ({\n /**\n * something with softbreak\n * {.cls}\n */\n\n name: \"\\n{.a} softbreak then curly in start\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -2,\n type: \"softbreak\",\n },\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const childTokens = tokens[index].children!;\n const token = childTokens[childIndex];\n\n // Find the last closing tag by searching forward\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Apply attributes to the opening token\n addAttrs(\n getMatchingOpeningToken(tokens, closingTokenIndex),\n token.content,\n range,\n options.allowed,\n );\n\n // Remove the softbreak and attribute tokens\n tokens[index].children = childTokens.slice(0, -2);\n },\n});\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule, DelimiterRange } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport { addAttrs, getDelimiterChecker } from \"../helper/index.js\";\n\nexport const getHrRule = (options: DelimiterConfig): AttrRule => ({\n /**\n * horizontal rule --- {#id}\n */\n name: \"horizontal rule\",\n tests: [\n {\n shift: 0,\n type: \"paragraph_open\",\n },\n {\n shift: 1,\n type: \"inline\",\n children: (children) => children.length === 1,\n content: (content): DelimiterRange | false => {\n let pos = 0;\n let charCode;\n let offset = 0;\n\n while (pos < content.length) {\n charCode = content.charCodeAt(pos++);\n\n if (charCode === 32 /** space */) offset++;\n else if (charCode === 9 /** tab */) offset += 4 - (offset % 4);\n else break;\n }\n\n if (offset > 3) return false;\n\n const markerCode = content.charCodeAt(pos - 1);\n\n if (\n markerCode !== 45 /** - */ &&\n markerCode !== 42 /** * */ &&\n markerCode !== 95 /** _ */\n )\n return false;\n\n let count = 1;\n\n while (pos < content.length) {\n charCode = content.charCodeAt(pos++);\n if (charCode !== markerCode) break;\n count++;\n }\n\n if (count < 3) return false;\n\n if (!isSpace(content.charCodeAt(pos - 1))) pos--;\n\n return getDelimiterChecker(options, \"end\")(content);\n },\n },\n {\n shift: 2,\n type: \"paragraph_close\",\n },\n ],\n transform: (tokens, index, _, range): void => {\n const token = tokens[index];\n // Extract attributes from the inline content\n const inlineToken = tokens[index + 1];\n const { content } = inlineToken;\n\n token.type = \"hr\";\n token.tag = \"hr\";\n token.nesting = 0;\n\n // Apply attributes to the hr token\n addAttrs(token, content, range, options.allowed);\n token.markup = content;\n\n // Remove the inline and closing paragraph tokens\n tokens.splice(index + 1, 2);\n },\n});\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\nimport type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\ninterface TokenWithColumnCount extends Token {\n meta:\n | {\n columnCount?: number;\n [key: string]: unknown;\n }\n | undefined;\n}\n\n/**\n * Hidden table's cells and them inline children,\n * specially cast inline's content as empty\n * to prevent that escapes the table's box model\n */\nconst hideTokenContent = (token: Token): void => {\n token.hidden = true;\n token.children?.forEach((childToken) => {\n childToken.content = \"\";\n hideTokenContent(childToken);\n });\n};\n\n/**\n * Handle rowspan logic for table cells\n */\nconst handleRowspan = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n columnCount: number,\n colspan: number,\n rowspan: number,\n): void => {\n let adjustedColumnCount = columnCount - (colspan > 0 ? colspan : 1);\n\n for (\n let tokenIndex = startIndex, remainingRows = rowspan;\n tokenIndex < endIndex && remainingRows > 1;\n tokenIndex++\n ) {\n if (tokens[tokenIndex].type === \"tr_open\") {\n const trOpenToken = tokens[tokenIndex] as TokenWithColumnCount;\n\n trOpenToken.meta ??= {};\n\n if (trOpenToken.meta.columnCount) adjustedColumnCount -= 1;\n trOpenToken.meta.columnCount = adjustedColumnCount;\n remainingRows--;\n }\n }\n};\n\n/**\n * Handle table row processing\n */\nconst handleTableRow = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n): void => {\n const token = tokens[startIndex] as TokenWithColumnCount;\n const expectedColumnCount = token.meta?.columnCount;\n\n if (!expectedColumnCount) return;\n\n // hide extra table cells in the row\n for (let index = startIndex, cellCount = 0; index < endIndex; index++) {\n const currentToken = tokens[index];\n\n // break at end of table row\n if (currentToken.type === \"tr_close\") break;\n\n // Count table cells in the row\n if (currentToken.type === \"td_open\") cellCount += 1;\n\n // hide extra table cells\n if (cellCount > expectedColumnCount && !currentToken.hidden) {\n hideTokenContent(currentToken);\n }\n }\n};\n\n/**\n * Handle colspan logic for table cells\n */\nconst handleColspan = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n columnCount: number,\n colspan: number,\n tbodyOpenIndex: number,\n): void => {\n const cellIndices: number[] = [];\n const startToken = tokens[startIndex];\n\n let end = startIndex + 3;\n let colspanNum = columnCount;\n\n // Find previous row children indices\n for (let tokenIndex = startIndex; tokenIndex > tbodyOpenIndex; tokenIndex--) {\n if (tokens[tokenIndex].type === \"tr_open\") {\n colspanNum =\n (tokens[tokenIndex] as TokenWithColumnCount).meta?.columnCount ??\n colspanNum;\n break;\n } else if (tokens[tokenIndex].type === \"td_open\") {\n cellIndices.unshift(tokenIndex);\n }\n }\n\n // Find current row children indices\n for (let index = startIndex + 2; index < endIndex; index++) {\n if (tokens[index].type === \"tr_close\") {\n end = index;\n break;\n } else if (tokens[index].type === \"td_open\") {\n cellIndices.push(index);\n }\n }\n\n const cellOffset = cellIndices.indexOf(startIndex);\n\n const realColspan = Math.min(colspan, colspanNum - cellOffset);\n\n if (colspan > realColspan) {\n startToken.attrSet(\"colspan\", realColspan.toString());\n }\n\n const hiddenStartIndex = cellIndices.slice(\n colspanNum + 1 - columnCount - realColspan,\n )[0];\n\n for (let index = hiddenStartIndex; index < end; index++) {\n if (!tokens[index].hidden) hideTokenContent(tokens[index]);\n }\n};\n\nexport const getTableRules = (options: DelimiterConfig): AttrRule[] => [\n {\n /**\n * | h1 |\n * | -- |\n * | c1 |\n *\n * {.c}\n */\n name: \"table\",\n tests: [\n {\n // let this token be i, such that for-loop continues at\n // next token after tokens.splice\n shift: 0,\n type: \"table_close\",\n },\n {\n shift: 1,\n type: \"paragraph_open\",\n },\n {\n shift: 2,\n type: \"inline\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n transform: (tokens, index, _, range): void => {\n const token = tokens[index + 2];\n const tableOpeningToken = getMatchingOpeningToken(tokens, index);\n\n // Apply attributes to the table opening token\n addAttrs(tableOpeningToken, token.content, range, options.allowed);\n\n // Remove the paragraph tokens containing the attributes\n tokens.splice(index + 1, 3);\n },\n },\n /**\n * Handle table cell attributes: title {.class}\n * This rule processes attributes within table cell text content\n */\n {\n name: \"table cell attributes\",\n tests: [\n {\n shift: -1,\n type: (type) => type === \"td_open\" || type === \"th_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"end\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n const attrStartIndex = range[0] - options.left.length;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const cellOpenToken = tokens[index - 1];\n const { content } = token;\n const hasTrailingSpace = isSpace(content.charCodeAt(attrStartIndex - 1));\n\n // Find last attribute syntax in the content\n\n // Apply attributes to the table cell token\n addAttrs(cellOpenToken, content, range, options.allowed);\n\n // Remove attribute syntax from content\n token.content = content.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n },\n {\n /**\n * | A | B |\n * | -- | -- |\n * | 1 | 2 |\n *\n * | C | D |\n * | -- | -- |\n *\n * only `| A | B |` sets the columnCount metadata\n */\n name: \"table thead metadata\",\n tests: [\n {\n shift: 0,\n type: \"tr_close\",\n },\n {\n shift: 1,\n type: \"thead_close\",\n },\n {\n shift: 2,\n type: \"tbody_open\",\n },\n ],\n\n transform: (tokens, index): void => {\n const trOpenToken = getMatchingOpeningToken(tokens, index);\n const thCloseToken = tokens[index - 1];\n let columnCount = 0;\n let currentIndex = index - 1;\n\n // Find the matching tr_open token and count columns\n while (currentIndex > 0) {\n const currentToken = tokens[currentIndex];\n\n if (currentToken === trOpenToken) {\n const tHeadOpenToken = tokens[\n currentIndex - 1\n ] as TokenWithColumnCount;\n\n tHeadOpenToken.meta = {\n ...tHeadOpenToken.meta,\n columnCount,\n };\n break;\n }\n\n // Count th_close tokens at the same level\n if (\n currentToken.level === thCloseToken.level &&\n currentToken.type === thCloseToken.type\n ) {\n columnCount++;\n }\n\n currentIndex--;\n }\n\n // Apply metadata to tbody_open token\n const tbodyOpenToken = tokens[index + 2] as TokenWithColumnCount;\n\n tbodyOpenToken.meta = {\n ...tbodyOpenToken.meta,\n columnCount,\n };\n },\n },\n {\n /**\n * | A | B | C | D |\n * | -- | -- | -- | -- |\n * | 1 | 11 | 111 | 1111 {rowspan=3} |\n * | 2 {colspan=2 rowspan=2} | 22 | 222 | 2222 |\n * | 3 | 33 | 333 | 3333 |\n */\n name: \"table tbody calculate\",\n tests: [\n {\n shift: 0,\n type: \"tbody_close\",\n hidden: false,\n },\n ],\n transform: (tokens, index): void => {\n // Find the tbody_open token index\n let tbodyOpenIndex = index - 2;\n\n while (tbodyOpenIndex > 0) {\n tbodyOpenIndex--;\n if (tokens[tbodyOpenIndex].type === \"tbody_open\") break;\n }\n\n const columnCount = Number(\n (tokens[tbodyOpenIndex] as TokenWithColumnCount).meta?.columnCount ?? 0,\n );\n\n if (columnCount < 2) return;\n\n const maxLevel = tokens[index].level + 2;\n\n for (\n let currentIndex = tbodyOpenIndex;\n currentIndex < index;\n currentIndex++\n ) {\n if (tokens[currentIndex].level > maxLevel) continue;\n\n const token = tokens[currentIndex];\n const rowspan = token.hidden ? 0 : Number(token.attrGet(\"rowspan\"));\n const colspan = token.hidden ? 0 : Number(token.attrGet(\"colspan\"));\n\n if (rowspan > 1) {\n handleRowspan(\n tokens,\n currentIndex,\n index,\n columnCount,\n colspan,\n rowspan,\n );\n }\n\n if (token.type === \"tr_open\") {\n handleTableRow(tokens, currentIndex, index);\n }\n\n if (colspan > 1) {\n handleColspan(\n tokens,\n currentIndex,\n index,\n columnCount,\n colspan,\n tbodyOpenIndex,\n );\n }\n }\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type {\n MarkdownItAttrRuleName,\n MarkdownItAttrsOptions,\n} from \"../options.js\";\nimport { getBlockRule } from \"./block.js\";\nimport { getFenceRule } from \"./fence.js\";\nimport { getHeadingRule } from \"./heading.js\";\nimport { getHrRule } from \"./hr.js\";\nimport { getInlineRules } from \"./inline.js\";\nimport { getListRules } from \"./list.js\";\nimport { getSoftBreakRule } from \"./softbreak.js\";\nimport { getTableRules } from \"./table.js\";\n\nconst AVAILABLE_RULES: MarkdownItAttrRuleName[] = [\n \"fence\",\n \"inline\",\n \"table\",\n \"list\",\n \"heading\",\n \"hr\",\n \"softbreak\",\n \"block\",\n];\n\nexport const getRules = (\n options: Required<MarkdownItAttrsOptions>,\n): AttrRule[] => {\n const enabledRules =\n // disable\n options.rule === false\n ? []\n : Array.isArray(options.rule)\n ? // user specific rules\n options.rule.filter((item) => AVAILABLE_RULES.includes(item))\n : AVAILABLE_RULES;\n\n const rules: AttrRule[] = [];\n\n if (enabledRules.includes(\"fence\")) rules.push(getFenceRule(options));\n if (enabledRules.includes(\"inline\")) rules.push(...getInlineRules(options));\n if (enabledRules.includes(\"table\")) rules.push(...getTableRules(options));\n if (enabledRules.includes(\"list\")) rules.push(...getListRules(options));\n if (enabledRules.includes(\"softbreak\")) rules.push(getSoftBreakRule(options));\n if (enabledRules.includes(\"hr\")) rules.push(getHrRule(options));\n if (enabledRules.includes(\"block\")) rules.push(getBlockRule(options));\n // heading rule is fully covered by block rules\n else if (enabledRules.includes(\"heading\"))\n rules.push(getHeadingRule(options));\n\n return rules;\n};\n","/**\n * Forked and modified from https://github.com/arve0/markdown-it-attrs/\n */\n\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type { RuleCore } from \"markdown-it/lib/parser_core.mjs\";\n\nimport { testRule } from \"./helper/index.js\";\nimport type { MarkdownItAttrsOptions } from \"./options.js\";\nimport type { DelimiterRange } from \"./rules/index.js\";\nimport { getRules } from \"./rules/index.js\";\n\nexport const attrs: PluginWithOptions<MarkdownItAttrsOptions> = (\n md,\n { left = \"{\", right = \"}\", allowed = [], rule = \"all\" } = {},\n) => {\n const rules = getRules({\n left,\n right,\n allowed,\n rule,\n });\n\n const attrsRule: RuleCore = ({ tokens }) => {\n for (let index = 0; index < tokens.length; index++)\n for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex++) {\n const pattern = rules[ruleIndex];\n // position of child with offset 0\n let position: null | number = null;\n let range: DelimiterRange | null = null;\n\n const match = pattern.tests.every((test) => {\n const result = testRule(tokens, index, test);\n\n if (result.position !== null) ({ position } = result);\n if (result.range) range = result.range;\n\n return result.match;\n });\n\n if (match) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n pattern.transform(tokens, index, position!, range!);\n\n if (\n pattern.name === \"inline attributes\" ||\n pattern.name === \"inline nesting self-close\"\n )\n // retry, may be several inline attributes\n ruleIndex--;\n }\n }\n };\n\n md.core.ruler.before(\"linkify\", \"attrs\", attrsRule);\n};\n"],"names":["CLASS_MARKER","ID_MARKER","PAIR_SEPARATOR","KEY_SEPARATOR","QUOTE_MARKER","isAllowedKeyChar","charCode","getAttrs","str","range","allowed","key","value","parsingKey","valueInsideQuotes","attrs","index","attr","item","addAttrs","token","content","getDelimiterChecker","left","right","where","leftLength","rightLength","minContentLength","start","end","nextCharPos","firstCharCode","length","getMatchingOpeningToken","tokens","level","type","currentToken","getArrayItem","arr","testRule","rule","testResult","isShift","tokenIndex","childTests","children","match","childTest","result","position","childIndex","ruleDetail","isSpace","code","getBlockRule","options","attrStartIndex","hasTrailingSpace","closingTokenIndex","openingToken","getFenceRule","_","info","getHeadingRule","getInlineRules","childTokens","targetToken","attrsEndIndex","getListRules","listOpenIndex","getSoftBreakRule","getHrRule","pos","offset","markerCode","count","inlineToken","hideTokenContent","childToken","handleRowspan","startIndex","endIndex","columnCount","colspan","rowspan","adjustedColumnCount","remainingRows","trOpenToken","handleTableRow","expectedColumnCount","cellCount","handleColspan","tbodyOpenIndex","cellIndices","startToken","colspanNum","cellOffset","realColspan","hiddenStartIndex","getTableRules","tableOpeningToken","cellOpenToken","thCloseToken","currentIndex","tHeadOpenToken","tbodyOpenToken","maxLevel","AVAILABLE_RULES","getRules","enabledRules","rules","md","attrsRule","ruleIndex","pattern","test"],"mappings":"AACa,MAAAA,EAAe,GAEfC,EAAY,GAEZC,EAAiB,GAEjBC,EAAgB,GAEhBC,EAAe,GCCtBC,EAAoBC,GACxB,EACEA,IAAa,GACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IAGJC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IAAa,CAC7D,MAAMC,EAAUJ,EAAMG,CAAS,EAE/B,IAAIhE,EAA0B,KAC1B1C,EAA+B,KAErB2G,EAAQ,MAAM,MAAOC,GAAS,CAC1C,MAAMnE,EAAST,EAASN,EAAQnB,EAAOqG,CAAI,EAE3C,OAAInE,EAAO,WAAa,OAAO,CAAE,SAAAC,CAAS,EAAID,GAC1CA,EAAO,QAAOzC,EAAQyC,EAAO,OAE1BA,EAAO,KAChB,CAAC,IAICkE,EAAQ,UAAUjF,EAAQnB,EAAOmC,EAAW1C,CAAM,GAGhD2G,EAAQ,OAAS,qBACjBA,EAAQ,OAAS,8BAGjBD,IAEN,CACJ,EAEAF,EAAG,KAAK,MAAM,OAAO,UAAW,QAASC,CAAS,CACpD","x_google_ignoreList":[7]}
package/lib/index.d.ts CHANGED
@@ -31,7 +31,7 @@ interface DelimiterConfig {
31
31
  allowed: (string | RegExp)[];
32
32
  }
33
33
 
34
- type MarkdownItAttrRuleName = "fence" | "inline" | "table" | "list" | "hr" | "softbreak" | "block";
34
+ type MarkdownItAttrRuleName = "fence" | "inline" | "table" | "list" | "heading" | "hr" | "softbreak" | "block";
35
35
  interface MarkdownItAttrsOptions extends Partial<DelimiterConfig> {
36
36
  /**
37
37
  * Rules to enable
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{escapeRegExp as b}from"@mdit/helper";const u=(e,t)=>{t&&e.forEach(([s,n])=>{switch(s){case"class":t.attrJoin("class",n);break;case"css-module":t.attrJoin("css-module",n);break;default:t.attrPush([s,n])}})},_=".",x="#",v=/[^\t\n\f />"'=]/,O=" ",E="=",d=(e,t,{left:s,right:n,allowed:o})=>{let i="",l="",r=!0,c=!1;const f=[];for(let h=t+s.length;h<e.length;h++){if(e.slice(h,h+n.length)===n){i!==""&&f.push([i,l]);break}const a=e.charAt(h);if(a===E&&r){r=!1;continue}if(a===_&&i===""){e.charAt(h+1)===_?(i="css-module",h++):i="class",r=!1;continue}if(a===x&&i===""){i="id",r=!1;continue}if(a==='"'&&l===""&&!c){c=!0;continue}if(a==='"'&&c){c=!1;continue}if(a===O&&!c){if(i==="")continue;f.push([i,l]),i="",l="",r=!0;continue}if(!(r&&a.search(v)===-1)){if(r){i+=a;continue}l+=a}}return o.length?f.filter(([h])=>o.some(a=>a instanceof RegExp?a.test(h):a===h)):f},y=({left:e,right:t},s)=>{if(!["start","end","only"].includes(s))throw new Error(`Invalid 'where' parameter: ${s}. Expected 'start', 'end', or 'only'.`);return n=>{const o=e.length,i=t.length,l=o+1+i,r=o+1;if(!n||typeof n!="string"||n.length<l)return!1;const c=p=>[_,x].includes(p.charAt(o))?p.length>=l+1:p.length>=l;let f,h,a,m;return s==="start"?(a=n.slice(0,o),f=a===e?0:-1,h=f===-1?-1:n.indexOf(t,r),m=n.charAt(h+i),m&&t.includes(m)&&(h=-1)):s==="end"?(f=n.lastIndexOf(e),h=f===-1?-1:n.indexOf(t,f+r),h=h===n.length-i?h:-1):(a=n.slice(0,o),f=a===e?0:-1,a=n.slice(n.length-i),h=a===t?n.length-i:-1),f!==-1&&h!==-1&&c(n.substring(f,h+i))}},g=(e,t)=>{const s=e[t];if(s.type==="softbreak")return null;if(s.nesting===0)return s;const n=s.level,o=s.type.replace("_close","_open");for(;t>=0;){const i=e[t];if(i.type===o&&i.level===n)return i;t--}/* istanbul ignore next -- @preserve */return null},w=(e,t,s)=>{const n=b(t),o=b(s),i=e.search(new RegExp(`[ \\n]?${n}[^${n}${o}]+${o}$`));return i!==-1?e.slice(0,i):e},C=(e,t)=>t>=0?e[t]:e[e.length+t],I=e=>Array.isArray(e)&&!!e.length&&e.every(t=>typeof t=="function"),$=e=>Array.isArray(e)&&!!e.length&&e.every(t=>typeof t=="object"),k=(e,t,s)=>{const n={match:!1,position:null},o=s.shift!==void 0?t+s.shift:s.position;if(s.shift!==void 0&&o<0)return n;const i=C(e,o);if(!i)return n;for(const l of Object.keys(s)){if(l==="shift"||l==="position")continue;if(i[l]===void 0)return n;if(l==="children"&&$(s.children)){if(i.children?.length===0)return n;let c;const f=s.children,h=i.children;if(f.every(a=>a.position!==void 0)){if(c=f.every(a=>k(h,a.position,a).match),c){const a=f[f.length-1]?.position??0;n.position=a>=0?a:h.length+a}}else for(let a=0;a<h.length;a++)if(c=f.every(m=>k(h,a,m).match),c){n.position=a;break}if(c===!1)return n;continue}const r=s[l];switch(typeof r){case"boolean":case"number":case"string":{if(i[l]!==r)return n;break}case"function":{if(!r(i[l]))return n;break}default:{if(I(r)){if(!r.every(c=>c(i[l])))return n;break}throw new Error(`Unknown type of pattern test (key: ${l}). Test should be of type boolean, number, string, function or array of functions.`)}}}return n.match=!0,n},S=e=>({name:"end of block",tests:[{shift:0,type:"inline",children:[{position:-1,content:y(e,"end"),type:t=>t!=="code_inline"&&t!=="math_inline"}]}],transform:(t,s,n)=>{const o=t[s].children[n],{content:i}=o,l=i.lastIndexOf(e.left),r=d(i,l,e);let c=s+1;for(;t[c+1]&&t[c+1].nesting===-1;)c++;const f=g(t,c);u(r,f);const h=i.slice(0,l),a=h[h.length-1]===" ";o.content=a?h.slice(0,-1):h}}),T=e=>({name:"code-block",tests:[{shift:0,block:!0,info:y(e,"end")}],transform:(t,s)=>{const n=t[s];let o="";const i=/{(?:[\d,-]+)}/.exec(n.info);i&&(n.info=n.info.replace(i[0],""),o=i[0]);const l=n.info.lastIndexOf(e.left),r=d(n.info,l,e);u(r,n);const c=w(n.info,e.left,e.right);n.info=`${c} ${o}`.trim()}}),D=e=>[{name:"inline nesting self-close",tests:[{shift:0,type:"inline",children:[{shift:-1,type:t=>t==="image"||t==="code_inline"},{shift:0,type:"text",content:y(e,"start")}]}],transform:(t,s,n)=>{const o=e.right.length,i=t[s].children[n],l=i.content.indexOf(e.right),r=t[s].children[n-1],c=d(i.content,0,e);u(c,r),i.content.length===l+o?t[s].children.splice(n,1):i.content=i.content.slice(l+o)}},{name:"inline attributes",tests:[{shift:0,type:"inline",children:[{shift:-1,nesting:-1},{shift:0,type:"text",content:y(e,"start")}]}],transform:(t,s,n)=>{const o=t[s].children[n],{content:i}=o,l=d(i,0,e),r=g(t[s].children,n-1);u(l,r);const c=i.indexOf(e.right)+e.right.length;o.content=i.slice(c)}}],K=e=>[{name:"list softbreak",tests:[{shift:-2,type:"list_item_open"},{shift:0,type:"inline",children:[{position:-2,type:"softbreak"},{position:-1,type:"text",content:y(e,"only")}]}],transform:(t,s,n)=>{const o=t[s].children[n],i=d(o.content,0,e);let l=s-2;for(;t[l-1]&&t[l-1].type!=="ordered_list_open"&&t[l-1].type!=="bullet_list_open";)l--;u(i,t[l-1]),t[s].children=t[s].children.slice(0,-2)}},{name:"list double softbreak",tests:[{shift:0,type:t=>t==="bullet_list_close"||t==="ordered_list_close"},{shift:1,type:"paragraph_open"},{shift:2,type:"inline",content:y(e,"only"),children:t=>t.length===1},{shift:3,type:"paragraph_close"}],transform:(t,s)=>{const n=t[s+2],o=d(n.content,0,e),i=g(t,s);u(o,i),t.splice(s+1,3)}},{name:"list item end",tests:[{shift:-2,type:"list_item_open"},{shift:0,type:"inline",children:[{position:-1,type:"text",content:y(e,"end")}]}],transform:(t,s,n)=>{const o=t[s].children[n],{content:i}=o,l=i.lastIndexOf(e.left),r=d(i,l,e);u(r,t[s-2]);const c=i.slice(0,l),f=c[c.length-1]===" ";o.content=f?c.slice(0,-1):c}}],L=e=>({name:`
2
- {.a} softbreak then curly in start`,tests:[{shift:0,type:"inline",children:[{position:-2,type:"softbreak"},{position:-1,type:"text",content:y(e,"only")}]}],transform:(t,s,n)=>{const o=t[s].children[n],i=d(o.content,0,e);let l=s+1;for(;t[l+1]&&t[l+1].nesting===-1;)l++;const r=g(t,l);u(i,r),t[s].children=t[s].children.slice(0,-2)}}),M=e=>({name:"horizontal rule",tests:[{shift:0,type:"paragraph_open"},{shift:1,type:"inline",children:t=>t.length===1,content:t=>new RegExp(`^ {0,3}[-*_]{3,} ?${b(e.left)}[^${b(e.right)}]`).test(t)},{shift:2,type:"paragraph_close"}],transform:(t,s)=>{const n=t[s];n.type="hr",n.tag="hr",n.nesting=0;const o=t[s+1],{content:i}=o,l=i.lastIndexOf(e.left),r=d(i,l,e);u(r,n),n.markup=i,t.splice(s+1,2)}}),A=e=>{e.hidden=!0,e.children?.forEach(t=>{t.content="",A(t)})},P=(e,t,s,n,o,i)=>{let l=n-(o>0?o:1);for(let r=t,c=i;r<s&&c>1;r++)if(e[r].type==="tr_open"){const f=e[r];f.meta??={},f.meta.columnCount&&(l-=1),f.meta.columnCount=l,c--}},j=(e,t,s)=>{const n=e[t].meta?.columnCount;if(n)for(let o=t,i=0;o<s;o++){const l=e[o];if(l.type==="td_open")i+=1;else if(l.type==="tr_close")break;i>n&&!l.hidden&&A(l)}},N=(e,t,s,n,o,i)=>{const l=[],r=e[t];let c=t+3,f=n;for(let p=t;p>i;p--)if(e[p].type==="tr_open"){f=e[p].meta?.columnCount??f;break}else e[p].type==="td_open"&&l.unshift(p);for(let p=t+2;p<s;p++)if(e[p].type==="tr_close"){c=p;break}else e[p].type==="td_open"&&l.push(p);const h=l.indexOf(t),a=Math.min(o,f-h);o>a&&r.attrSet("colspan",a.toString());const m=l.slice(f+1-n-a)[0];for(let p=m;p<c;p++)e[p].hidden||A(e[p])},B=e=>[{name:"table",tests:[{shift:0,type:"table_close"},{shift:1,type:"paragraph_open"},{shift:2,type:"inline",content:y(e,"only")}],transform:(t,s)=>{const n=t[s+2],o=g(t,s),i=d(n.content,0,e);u(i,o),t.splice(s+1,3)}},{name:"table cell attributes",tests:[{shift:-1,type:t=>t==="td_open"||t==="th_open"},{shift:0,type:"inline",children:[{shift:0,type:"text",content:y(e,"end")}]}],transform:(t,s,n)=>{const o=t[s].children[n],i=t[s-1],{content:l}=o,r=l.lastIndexOf(e.left),c=d(l,r,e);u(c,i),o.content=l.substring(0,r).trim()}},{name:"table thead metadata",tests:[{shift:0,type:"tr_close"},{shift:1,type:"thead_close"},{shift:2,type:"tbody_open"}],transform:(t,s)=>{const n=g(t,s),o=t[s-1];let i=0,l=s-1;for(;l>0;){const c=t[l];if(c===n){const f=t[l-1];f.meta={...f.meta,columnCount:i};break}c.level===o.level&&c.type===o.type&&i++,l--}const r=t[s+2];r.meta={...r.meta,columnCount:i}}},{name:"table tbody calculate",tests:[{shift:0,type:"tbody_close",hidden:!1}],transform:(t,s)=>{let n=s-2;for(;n>0&&(n--,t[n].type!=="tbody_open"););const o=Number(t[n].meta?.columnCount??0);if(o<2)return;const i=t[s].level+2;for(let l=n;l<s;l++){if(t[l].level>i)continue;const r=t[l],c=r.hidden?0:Number(r.attrGet("rowspan")),f=r.hidden?0:Number(r.attrGet("colspan"));c>1&&P(t,l,s,o,f,c),r.type==="tr_open"&&j(t,l,s),f>1&&N(t,l,s,o,f,n)}}}],R=["fence","inline","table","list","hr","softbreak","block"],F=e=>{const t=e.rule===!1?[]:Array.isArray(e.rule)?e.rule.filter(n=>R.includes(n)):R,s=[];return t.includes("fence")&&s.push(T(e)),t.includes("inline")&&s.push(...D(e)),t.includes("table")&&s.push(...B(e)),t.includes("list")&&s.push(...K(e)),t.includes("softbreak")&&s.push(L(e)),t.includes("hr")&&s.push(M(e)),t.includes("block")&&s.push(S(e)),s},G=(e,{left:t="{",right:s="}",allowed:n=[],rule:o="all"}={})=>{const i=F({left:t,right:s,allowed:n,rule:o}),l=({tokens:r})=>{for(let c=0;c<r.length;c++)for(let f=0;f<i.length;f++){const h=i[f];let a=null;h.tests.every(m=>{const p=k(r,c,m);return p.position!==null&&({position:a}=p),p.match})&&(h.transform(r,c,a),(h.name==="inline attributes"||h.name==="inline nesting self-close")&&f--)}};e.core.ruler.before("linkify","attrs",l)};export{G as attrs};
1
+ import{isSpace as b}from"markdown-it/lib/common/utils.mjs";const k=46,w=35,E=32,v=61,R=34,S=e=>!(e===9||e===10||e===12||e===32||e===47||e===62||e===34||e===39||e===61),O=(e,t,n)=>{let l="",i="",o=!0,s=!1;const r=[];for(let a=t[0];a<t[1];a++){const c=e.charCodeAt(a);if(c===v&&o){o=!1;continue}if(c===k&&l===""){e.charCodeAt(a+1)===k?(l="css-module",a++):l="class",o=!1;continue}if(c===w&&l===""){l="id",o=!1;continue}if(c===R&&i===""&&!s){s=!0;continue}if(c===R&&s){s=!1;continue}if(c===E&&!s){if(l==="")continue;r.push([l,i]),l="",i="",o=!0;continue}if(!(o&&!S(c))){if(o){l+=String.fromCharCode(c);continue}i+=String.fromCharCode(c)}}return l!==""&&r.push([l,i]),n.length?r.filter(([a])=>n.some(c=>c instanceof RegExp?c.test(a):c===a)):r},p=(e,t,n,l)=>{e&&O(t,n,l).forEach(([i,o])=>{switch(i){case"class":e.attrJoin("class",o);break;case"css-module":e.attrJoin("css-module",o);break;default:e.attrPush([i,o])}})},d=({left:e,right:t},n)=>{if(!["start","end","only"].includes(n))throw new Error(`Invalid 'where' parameter: ${n}. Expected 'start', 'end', or 'only'.`);const l=e.length,i=t.length,o=l+1+i;return s=>{if(typeof s!="string"||s.length<o)return!1;let r,a;if(n==="start"){if(!s.startsWith(e)||(r=l,a=s.indexOf(t,l+1),a===-1))return!1;const u=a+i;if(u<s.length&&t.includes(s.charAt(u)))return!1}else if(n==="end"){if(r=s.lastIndexOf(e),r===-1||(a=s.indexOf(t,r+l+1),r+=l,a===-1||a+i!==s.length))return!1}else{if(!s.startsWith(e)||!s.endsWith(t))return!1;r=l,a=s.length-i}const c=s.charCodeAt(r),h=a-r;return(c===k||c===w?h>=2:h>=1)?[r,a]:!1}},y=(e,t)=>{const n=e[t];if(n.type==="softbreak")return null;if(n.nesting===0)return n;const l=n.level,i=n.type.replace("_close","_open");for(;t>=0;){const o=e[t];if(o.type===i&&o.level===l)return o;t--}/* istanbul ignore next -- @preserve */return null},T=(e,t)=>t>=0?e[t]:e[e.length+t],A=(e,t,n)=>{const l={match:!1,position:null,range:null},i=n.shift!==void 0,o=i?t+n.shift:n.position;if(i&&o<0)return l;const s=T(e,o);if(!s)return l;for(const r of Object.keys(n)){if(r==="shift"||r==="position")continue;if(s[r]==null)return l;if(r==="children"&&Array.isArray(n.children)){if(!s.children?.length)return l;const c=n.children,h=s.children;let u,g=null;if(c.every(f=>f.position!=null)){if(u=c.every(f=>{const m=A(h,f.position,f);return m.match?(m.range&&(g=m.range),!0):!1}),u){const{position:f}=c[c.length-1];l.position=f>=0?f:h.length+f,l.range=g}}else for(let f=0;f<h.length;f++)if(u=c.every(m=>{const _=A(h,f,m);return _.match?(_.range&&(g=_.range),!0):!1}),u){l.position=f,g&&(l.range=g);break}if(u===!1)return l;continue}const a=n[r];switch(typeof a){case"boolean":case"number":case"string":{if(s[r]!==a)return l;break}case"function":{const c=a(s[r]);if(!c)return l;Array.isArray(c)&&(l.range=c);break}default:throw new Error(`Unknown type of pattern test (key: ${r}). Test should be of type boolean, number, string or function.`)}}return l.match=!0,l},I=e=>({name:"end of block",tests:[{shift:0,type:"inline",children:[{position:-1,content:d(e,"end"),type:t=>t!=="code_inline"&&t!=="math_inline"}]}],transform:(t,n,l,i)=>{const o=i[0]-e.left.length,s=t[n].children[l],{content:r}=s,a=b(r.charCodeAt(o-1));let c=n+1;for(;t[c+1]&&t[c+1].nesting===-1;)c++;const h=y(t,c);p(h,r,i,e.allowed),s.content=r.slice(0,a?o-1:o)}}),M=e=>({name:"code-block",tests:[{shift:0,block:!0,info:d(e,"end")}],transform:(t,n,l,i)=>{const o=i[0]-e.left.length,s=t[n],{info:r}=s,a=b(r.charCodeAt(o-1));p(s,r,i,e.allowed),s.info=r.slice(0,a?o-1:o)}}),K=e=>({name:"end of block",tests:[{shift:-1,type:"heading_open"},{shift:0,type:"inline",children:[{position:-1,content:d(e,"end"),type:t=>t!=="code_inline"&&t!=="math_inline"}]}],transform:(t,n,l,i)=>{const o=i[0]-e.left.length,s=t[n].children[l],{content:r}=s,a=b(r.charCodeAt(o-1));let c=n+1;for(;t[c+1]&&t[c+1].nesting===-1;)c++;const h=y(t,c);p(h,r,i,e.allowed),s.content=r.slice(0,a?o-1:o)}}),P=e=>[{name:"inline nesting self-close",tests:[{shift:0,type:"inline",children:[{shift:-1,type:t=>t==="image"||t==="code_inline"},{shift:0,type:"text",content:d(e,"start")}]}],transform:(t,n,l,i)=>{const o=t[n].children,s=o[l],r=o[l-1],a=e.right.length+i[1];p(r,s.content,i,e.allowed),s.content.length===a?o.splice(l,1):s.content=s.content.slice(a)}},{name:"inline attributes",tests:[{shift:0,type:"inline",children:[{shift:-1,nesting:-1},{shift:0,type:"text",content:d(e,"start")}]}],transform:(t,n,l,i)=>{const o=t[n].children,s=o[l],{content:r}=s,a=e.right.length+i[1],c=y(o,l-1);p(c,r,i,e.allowed),s.content=r.slice(a)}}],N=e=>[{name:"list softbreak",tests:[{shift:-2,type:"list_item_open"},{shift:0,type:"inline",children:[{position:-2,type:"softbreak"},{position:-1,type:"text",content:d(e,"only")}]}],transform:(t,n,l,i)=>{const o=t[n].children,s=o[l];let r=n-2;for(;t[r-1]&&t[r-1].type!=="ordered_list_open"&&t[r-1].type!=="bullet_list_open";)r--;p(t[r-1],s.content,i,e.allowed),t[n].children=o.slice(0,-2)}},{name:"list double softbreak",tests:[{shift:0,type:t=>t==="bullet_list_close"||t==="ordered_list_close"},{shift:1,type:"paragraph_open"},{shift:2,type:"inline",content:d(e,"only"),children:t=>t.length===1},{shift:3,type:"paragraph_close"}],transform:(t,n,l,i)=>{const o=t[n+2],s=y(t,n);p(s,o.content,i,e.allowed),t.splice(n+1,3)}},{name:"list item end",tests:[{shift:-2,type:"list_item_open"},{shift:0,type:"inline",children:[{position:-1,type:"text",content:d(e,"end")}]}],transform:(t,n,l,i)=>{const o=t[n].children[l],{content:s}=o,r=i[0]-e.left.length,a=b(s.charCodeAt(r-1));p(t[n-2],s,i,e.allowed),o.content=s.slice(0,a?r-1:r)}}],W=e=>({name:`
2
+ {.a} softbreak then curly in start`,tests:[{shift:0,type:"inline",children:[{position:-2,type:"softbreak"},{position:-1,type:"text",content:d(e,"only")}]}],transform:(t,n,l,i)=>{const o=t[n].children,s=o[l];let r=n+1;for(;t[r+1]&&t[r+1].nesting===-1;)r++;p(y(t,r),s.content,i,e.allowed),t[n].children=o.slice(0,-2)}}),B=e=>({name:"horizontal rule",tests:[{shift:0,type:"paragraph_open"},{shift:1,type:"inline",children:t=>t.length===1,content:t=>{let n=0,l,i=0;for(;n<t.length;)if(l=t.charCodeAt(n++),l===32)i++;else if(l===9)i+=4-i%4;else break;if(i>3)return!1;const o=t.charCodeAt(n-1);if(o!==45&&o!==42&&o!==95)return!1;let s=1;for(;n<t.length&&(l=t.charCodeAt(n++),l===o);)s++;return s<3?!1:(b(t.charCodeAt(n-1))||n--,d(e,"end")(t))}},{shift:2,type:"paragraph_close"}],transform:(t,n,l,i)=>{const o=t[n],s=t[n+1],{content:r}=s;o.type="hr",o.tag="hr",o.nesting=0,p(o,r,i,e.allowed),o.markup=r,t.splice(n+1,2)}}),C=e=>{e.hidden=!0,e.children?.forEach(t=>{t.content="",C(t)})},D=(e,t,n,l,i,o)=>{let s=l-(i>0?i:1);for(let r=t,a=o;r<n&&a>1;r++)if(e[r].type==="tr_open"){const c=e[r];c.meta??={},c.meta.columnCount&&(s-=1),c.meta.columnCount=s,a--}},G=(e,t,n)=>{const l=e[t].meta?.columnCount;if(l)for(let i=t,o=0;i<n;i++){const s=e[i];if(s.type==="tr_close")break;s.type==="td_open"&&(o+=1),o>l&&!s.hidden&&C(s)}},H=(e,t,n,l,i,o)=>{const s=[],r=e[t];let a=t+3,c=l;for(let f=t;f>o;f--)if(e[f].type==="tr_open"){c=e[f].meta?.columnCount??c;break}else e[f].type==="td_open"&&s.unshift(f);for(let f=t+2;f<n;f++)if(e[f].type==="tr_close"){a=f;break}else e[f].type==="td_open"&&s.push(f);const h=s.indexOf(t),u=Math.min(i,c-h);i>u&&r.attrSet("colspan",u.toString());const g=s.slice(c+1-l-u)[0];for(let f=g;f<a;f++)e[f].hidden||C(e[f])},J=e=>[{name:"table",tests:[{shift:0,type:"table_close"},{shift:1,type:"paragraph_open"},{shift:2,type:"inline",content:d(e,"only")}],transform:(t,n,l,i)=>{const o=t[n+2],s=y(t,n);p(s,o.content,i,e.allowed),t.splice(n+1,3)}},{name:"table cell attributes",tests:[{shift:-1,type:t=>t==="td_open"||t==="th_open"},{shift:0,type:"inline",children:[{shift:0,type:"text",content:d(e,"end")}]}],transform:(t,n,l,i)=>{const o=i[0]-e.left.length,s=t[n].children[l],r=t[n-1],{content:a}=s,c=b(a.charCodeAt(o-1));p(r,a,i,e.allowed),s.content=a.slice(0,c?o-1:o)}},{name:"table thead metadata",tests:[{shift:0,type:"tr_close"},{shift:1,type:"thead_close"},{shift:2,type:"tbody_open"}],transform:(t,n)=>{const l=y(t,n),i=t[n-1];let o=0,s=n-1;for(;s>0;){const a=t[s];if(a===l){const c=t[s-1];c.meta={...c.meta,columnCount:o};break}a.level===i.level&&a.type===i.type&&o++,s--}const r=t[n+2];r.meta={...r.meta,columnCount:o}}},{name:"table tbody calculate",tests:[{shift:0,type:"tbody_close",hidden:!1}],transform:(t,n)=>{let l=n-2;for(;l>0&&(l--,t[l].type!=="tbody_open"););const i=Number(t[l].meta?.columnCount??0);if(i<2)return;const o=t[n].level+2;for(let s=l;s<n;s++){if(t[s].level>o)continue;const r=t[s],a=r.hidden?0:Number(r.attrGet("rowspan")),c=r.hidden?0:Number(r.attrGet("colspan"));a>1&&D(t,s,n,i,c,a),r.type==="tr_open"&&G(t,s,n),c>1&&H(t,s,n,i,c,l)}}}],x=["fence","inline","table","list","heading","hr","softbreak","block"],L=e=>{const t=e.rule===!1?[]:Array.isArray(e.rule)?e.rule.filter(l=>x.includes(l)):x,n=[];return t.includes("fence")&&n.push(M(e)),t.includes("inline")&&n.push(...P(e)),t.includes("table")&&n.push(...J(e)),t.includes("list")&&n.push(...N(e)),t.includes("softbreak")&&n.push(W(e)),t.includes("hr")&&n.push(B(e)),t.includes("block")?n.push(I(e)):t.includes("heading")&&n.push(K(e)),n},U=(e,{left:t="{",right:n="}",allowed:l=[],rule:i="all"}={})=>{const o=L({left:t,right:n,allowed:l,rule:i}),s=({tokens:r})=>{for(let a=0;a<r.length;a++)for(let c=0;c<o.length;c++){const h=o[c];let u=null,g=null;h.tests.every(f=>{const m=A(r,a,f);return m.position!==null&&({position:u}=m),m.range&&(g=m.range),m.match})&&(h.transform(r,a,u,g),(h.name==="inline attributes"||h.name==="inline nesting self-close")&&c--)}};e.core.ruler.before("linkify","attrs",s)};export{U as attrs};
3
3
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/helper/addAttrs.ts","../src/helper/constants.ts","../src/helper/getAttrs.ts","../src/helper/getDelimiterChecker.ts","../src/helper/getMatchingOpeningToken.ts","../src/helper/removeDelimiter.ts","../src/utils.ts","../src/helper/testRule.ts","../src/rules/block.ts","../src/rules/fence.ts","../src/rules/inline.ts","../src/rules/list.ts","../src/rules/softbreak.ts","../src/rules/hr.ts","../src/rules/table.ts","../src/rules/rules.ts","../src/plugin.ts"],"sourcesContent":["import type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { Attr } from \"./types.js\";\n\nexport const addAttrs = (attrs: Attr[], token: Token | null): void => {\n if (!token) return;\n\n attrs.forEach(([key, value]) => {\n switch (key) {\n case \"class\":\n token.attrJoin(\"class\", value);\n break;\n case \"css-module\":\n token.attrJoin(\"css-module\", value);\n break;\n default:\n token.attrPush([key, value]);\n }\n });\n};\n","export const CLASS_MARKER = \".\";\nexport const ID_MARKER = \"#\";\nexport const ALLOWED_KEY_CHARS = /[^\\t\\n\\f />\"'=]/;\nexport const PAIR_SEPARATOR = \" \";\nexport const KEY_SEPARATOR = \"=\";\n","import {\n ALLOWED_KEY_CHARS,\n CLASS_MARKER,\n ID_MARKER,\n KEY_SEPARATOR,\n PAIR_SEPARATOR,\n} from \"./constants.js\";\nimport type { Attr, DelimiterConfig } from \"./types.js\";\n\nexport const getAttrs = (\n str: string,\n start: number,\n { left, right, allowed }: DelimiterConfig,\n): Attr[] => {\n let key = \"\";\n let value = \"\";\n let parsingKey = true;\n let valueInsideQuotes = false;\n\n const attrs: Attr[] = [];\n\n // read inside {}\n // start + left delimiter length to avoid beginning {\n // breaks when } is found or end of string\n for (let index = start + left.length; index < str.length; index++) {\n if (str.slice(index, index + right.length) === right) {\n if (key !== \"\") attrs.push([key, value]);\n break;\n }\n\n const char = str.charAt(index);\n\n // switch to reading value if equal sign\n if (char === KEY_SEPARATOR && parsingKey) {\n parsingKey = false;\n continue;\n }\n\n // {.class} {..css-module}\n if (char === CLASS_MARKER && key === \"\") {\n if (str.charAt(index + 1) === CLASS_MARKER) {\n key = \"css-module\";\n index++;\n } else {\n key = \"class\";\n }\n\n parsingKey = false;\n continue;\n }\n\n // {#id}\n if (char === ID_MARKER && key === \"\") {\n key = \"id\";\n parsingKey = false;\n continue;\n }\n\n // {value=\"inside quotes\"}\n if (char === '\"' && value === \"\" && !valueInsideQuotes) {\n valueInsideQuotes = true;\n continue;\n }\n\n if (char === '\"' && valueInsideQuotes) {\n valueInsideQuotes = false;\n continue;\n }\n\n // read next key/value pair\n if (char === PAIR_SEPARATOR && !valueInsideQuotes) {\n if (key === \"\")\n // beginning or ending space: { .red } vs {.red}\n continue;\n\n attrs.push([key, value]);\n key = \"\";\n value = \"\";\n parsingKey = true;\n\n continue;\n }\n\n // continue if character not allowed\n if (parsingKey && char.search(ALLOWED_KEY_CHARS) === -1) continue;\n\n // no other conditions met; append to key/value\n if (parsingKey) {\n key += char;\n continue;\n }\n\n value += char;\n }\n\n return allowed.length\n ? attrs.filter(([attr]) =>\n allowed.some((item) =>\n item instanceof RegExp ? item.test(attr) : item === attr,\n ),\n )\n : attrs;\n};\n","import { CLASS_MARKER, ID_MARKER } from \"./constants.js\";\nimport type { DelimiterConfig } from \"./types.js\";\n\nexport type DelimiterChecker = (content: string) => boolean;\n\nexport const getDelimiterChecker = (\n { left, right }: Required<DelimiterConfig>,\n where: \"start\" | \"end\" | \"only\",\n): DelimiterChecker => {\n if (![\"start\", \"end\", \"only\"].includes(where)) {\n throw new Error(\n `Invalid 'where' parameter: ${where}. Expected 'start', 'end', or 'only'.`,\n );\n }\n\n return (content: string): boolean => {\n const leftLength = left.length;\n const rightLength = right.length;\n // we need minimum three chars, for example {b}\n const minCurlyLength = leftLength + 1 + rightLength;\n const rightDelimiterMinimumShift = leftLength + 1;\n\n // perform a quick check\n if (\n !content ||\n typeof content !== \"string\" ||\n content.length < minCurlyLength\n )\n return false;\n\n const validCurlyLength = (curly: string): boolean =>\n [CLASS_MARKER, ID_MARKER].includes(curly.charAt(leftLength))\n ? curly.length >= minCurlyLength + 1\n : curly.length >= minCurlyLength;\n\n let start: number;\n let end: number;\n let slice: string;\n let nextChar: string;\n\n if (where === \"start\") {\n // first char should be {, } found in char 2 or more\n slice = content.slice(0, leftLength);\n start = slice === left ? 0 : -1;\n end =\n start === -1 ? -1 : content.indexOf(right, rightDelimiterMinimumShift);\n // check if next character is not one of the delimiters\n nextChar = content.charAt(end + rightLength);\n if (nextChar && right.includes(nextChar)) end = -1;\n } else if (where === \"end\") {\n // last char should be }\n start = content.lastIndexOf(left);\n end =\n start === -1\n ? -1\n : content.indexOf(right, start + rightDelimiterMinimumShift);\n end = end === content.length - rightLength ? end : -1;\n } else {\n // '{.a}'\n slice = content.slice(0, leftLength);\n start = slice === left ? 0 : -1;\n slice = content.slice(content.length - rightLength);\n end = slice === right ? content.length - rightLength : -1;\n }\n\n return (\n start !== -1 &&\n end !== -1 &&\n validCurlyLength(content.substring(start, end + rightLength))\n );\n };\n};\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nexport const getMatchingOpeningToken = (\n tokens: Token[],\n index: number,\n): Token | null => {\n const token = tokens[index];\n\n if (token.type === \"softbreak\") return null;\n\n // non closing blocks, example img\n if (token.nesting === 0) return token;\n\n const level = token.level;\n const type = token.type.replace(\"_close\", \"_open\");\n\n while (index >= 0) {\n const currentToken = tokens[index];\n\n if (currentToken.type === type && currentToken.level === level)\n return currentToken;\n\n index--;\n }\n\n /* istanbul ignore next -- @preserve */\n return null;\n};\n","import { escapeRegExp } from \"@mdit/helper\";\n\nexport const removeDelimiter = (\n str: string,\n left: string,\n right: string,\n): string => {\n const start = escapeRegExp(left);\n const end = escapeRegExp(right);\n const pos = str.search(\n new RegExp(`[ \\\\n]?${start}[^${start}${end}]+${end}$`),\n );\n\n return pos !== -1 ? str.slice(0, pos) : str;\n};\n","/**\n * Get index item of array. Supports negative index, where -1 is last\n * element in array.\n */\nexport const getArrayItem = <T>(arr: T[], index: number): T =>\n index >= 0 ? arr[index] : arr[arr.length + index];\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport const isArrayOfFunctions = (arr: unknown): arr is Function[] =>\n Array.isArray(arr) &&\n Boolean(arr.length) &&\n arr.every((item) => typeof item === \"function\");\n\nexport const isArrayOfObjects = (arr: unknown): arr is object[] =>\n Array.isArray(arr) &&\n Boolean(arr.length) &&\n arr.every((item) => typeof item === \"object\");\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { AttrRuleSet, TestFunction } from \"../rules/types.js\";\nimport {\n getArrayItem,\n isArrayOfFunctions,\n isArrayOfObjects,\n} from \"../utils.js\";\n\nexport interface TestRuleResult {\n /** whether rule matches token stream */\n match: boolean;\n /** position of token */\n position: null | number;\n}\n\n/**\n * Test if rule matches token stream.\n *\n */\nexport const testRule = (\n tokens: Token[],\n index: number,\n rule: AttrRuleSet,\n): TestRuleResult => {\n const result: TestRuleResult = {\n match: false,\n position: null,\n };\n\n const tokenIndex =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n rule.shift !== undefined ? index + rule.shift : rule.position!;\n\n // we should never shift to negative indexes (rolling around to back of array)\n if (rule.shift !== undefined && tokenIndex < 0) return result;\n\n const token = getArrayItem(tokens, tokenIndex);\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!token) return result;\n\n for (const key of Object.keys(rule) as (keyof typeof rule)[]) {\n if (key === \"shift\" || key === \"position\") continue;\n\n if (token[key as keyof Token] === undefined) return result;\n\n if (key === \"children\" && isArrayOfObjects(rule.children)) {\n if (token.children?.length === 0) return result;\n\n let match;\n const childTests = rule.children;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const children = token.children!;\n\n if (childTests.every((childTest) => childTest.position !== undefined)) {\n // positions instead of shifts, do not loop all children\n match = childTests.every(\n (childTest) =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n testRule(children, childTest.position!, childTest).match,\n );\n\n if (match) {\n // we may need position of child in transform\n const position = childTests[childTests.length - 1]?.position ?? 0;\n\n result.position =\n position >= 0 ? position : children.length + position;\n }\n } else {\n for (let token = 0; token < children.length; token++) {\n match = childTests.every(\n (childTest) => testRule(children, token, childTest).match,\n );\n\n if (match) {\n result.position = token;\n // all tests true, continue with next key of pattern t\n break;\n }\n }\n }\n\n if (match === false) return result;\n\n continue;\n }\n\n const ruleDetail = rule[key];\n\n switch (typeof ruleDetail) {\n case \"boolean\":\n case \"number\":\n case \"string\": {\n if (token[key] !== ruleDetail) return result;\n\n break;\n }\n\n case \"function\": {\n if (!(ruleDetail as TestFunction)(token[key])) return result;\n\n break;\n }\n\n // fall through for objects !== arrays of functions\n default: {\n if (isArrayOfFunctions(ruleDetail)) {\n if (\n !(ruleDetail as TestFunction[]).every((ruleItem) =>\n ruleItem(token[key]),\n )\n )\n return result;\n\n break;\n }\n\n throw new Error(\n `Unknown type of pattern test (key: ${key}). Test should be of type boolean, number, string, function or array of functions.`,\n );\n }\n }\n }\n\n // no tests returned false -> all tests returns true\n result.match = true;\n\n return result;\n};\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getBlockRule = (options: Required<DelimiterConfig>): AttrRule =>\n /**\n * end of {.block}\n */\n ({\n name: \"end of block\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n content: getDelimiterChecker(options, \"end\"),\n type: (type) => type !== \"code_inline\" && type !== \"math_inline\",\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n\n // Extract attributes from the content\n const attrStartIndex = content.lastIndexOf(options.left);\n const attrs = getAttrs(content, attrStartIndex, options);\n\n // Find the closing token by skipping all nested closing tokens\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Get the corresponding opening token\n const openingToken = getMatchingOpeningToken(tokens, closingTokenIndex);\n\n // Apply attributes to the opening token\n addAttrs(attrs, openingToken);\n\n // Remove the attribute syntax from content\n const contentWithoutAttributes = content.slice(0, attrStartIndex);\n const hasTrailingSpace =\n contentWithoutAttributes[contentWithoutAttributes.length - 1] === \" \";\n\n token.content = hasTrailingSpace\n ? contentWithoutAttributes.slice(0, -1)\n : contentWithoutAttributes;\n },\n });\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n removeDelimiter,\n} from \"../helper/index.js\";\n\nexport const getFenceRule = (options: Required<DelimiterConfig>): AttrRule =>\n /**\n * fenced code blocks\n *\n * ```python {.cls}\n * for i in range(10):\n * print(i)\n * ```\n */\n ({\n name: \"code-block\",\n tests: [\n {\n shift: 0,\n block: true,\n info: getDelimiterChecker(options, \"end\"),\n },\n ],\n transform: (tokens, index): void => {\n const token = tokens[index];\n let lineNumbers = \"\";\n\n // Special handler for VuePress line numbers syntax\n const lineNumberMatch = /{(?:[\\d,-]+)}/.exec(token.info);\n\n if (lineNumberMatch) {\n token.info = token.info.replace(lineNumberMatch[0], \"\");\n lineNumbers = lineNumberMatch[0];\n }\n\n // Extract attributes from the token info\n const attributeStartIndex = token.info.lastIndexOf(options.left);\n const attributes = getAttrs(token.info, attributeStartIndex, options);\n\n // Apply attributes to the current token\n addAttrs(attributes, token);\n\n // Remove attribute syntax from info and restore line numbers\n const infoWithoutAttributes = removeDelimiter(\n token.info,\n options.left,\n options.right,\n );\n\n token.info = `${infoWithoutAttributes} ${lineNumbers}`.trim();\n },\n });\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getInlineRules = (\n options: Required<DelimiterConfig>,\n): AttrRule[] => [\n /**\n * bla `click()`{.c} ![](img.png){.d}\n *\n * differs from 'inline attributes' as it does\n * not have a closing tag (nesting: -1)\n */\n {\n name: \"inline nesting self-close\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: -1,\n type: (str) => str === \"image\" || str === \"code_inline\",\n },\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"start\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n const rightDelimiterLength = options.right.length;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n\n const attrEndIndex = token.content.indexOf(options.right);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const targetToken = tokens[index].children![childIndex - 1];\n const attrs = getAttrs(token.content, 0, options);\n\n // Apply attributes to the target token\n addAttrs(attrs, targetToken);\n\n // Remove or update token content based on remaining content\n if (token.content.length === attrEndIndex + rightDelimiterLength) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n tokens[index].children!.splice(childIndex, 1);\n } else {\n token.content = token.content.slice(\n attrEndIndex + rightDelimiterLength,\n );\n }\n },\n },\n\n /**\n * *emphasis*{.with attrs=1}\n */\n {\n name: \"inline attributes\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: -1,\n nesting: -1, // closing inline tag, </em>{.a}\n },\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"start\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const currentToken = tokens[index].children![childIndex];\n const { content } = currentToken;\n\n // Extract attributes from the content\n const attributes = getAttrs(content, 0, options);\n\n // Find the corresponding opening token\n const openingToken = getMatchingOpeningToken(\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n tokens[index].children!,\n childIndex - 1,\n );\n\n // Apply attributes to the opening token\n addAttrs(attributes, openingToken);\n\n // Remove attribute syntax from content\n const attributeEndIndex =\n content.indexOf(options.right) + options.right.length;\n\n currentToken.content = content.slice(attributeEndIndex);\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getListRules = (\n options: Required<DelimiterConfig>,\n): AttrRule[] => [\n /**\n * - item\n * {.a}\n */\n {\n name: \"list softbreak\",\n tests: [\n {\n shift: -2,\n type: \"list_item_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -2,\n type: \"softbreak\",\n },\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const attrs = getAttrs(token.content, 0, options);\n let listOpenIndex = index - 2;\n\n // Find the list opening token\n while (\n tokens[listOpenIndex - 1] &&\n tokens[listOpenIndex - 1].type !== \"ordered_list_open\" &&\n tokens[listOpenIndex - 1].type !== \"bullet_list_open\"\n ) {\n listOpenIndex--;\n }\n\n // Apply attributes to the list opening token\n addAttrs(attrs, tokens[listOpenIndex - 1]);\n\n // Remove the attribute tokens from children\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n tokens[index].children = tokens[index].children!.slice(0, -2);\n },\n },\n\n /**\n * - nested list\n * - with double \\n\n * {.a} <-- apply to nested ul\n *\n * {.b} <-- apply to root <ul>\n */\n {\n name: \"list double softbreak\",\n tests: [\n {\n // let this token be i = 0 so that we can erase\n // the <p>{.a}</p> tokens below\n shift: 0,\n type: (type) =>\n type === \"bullet_list_close\" || type === \"ordered_list_close\",\n },\n {\n shift: 1,\n type: \"paragraph_open\",\n },\n {\n shift: 2,\n type: \"inline\",\n content: getDelimiterChecker(options, \"only\"),\n children: (children) => children.length === 1,\n },\n {\n shift: 3,\n type: \"paragraph_close\",\n },\n ],\n transform: (tokens, index): void => {\n const token = tokens[index + 2];\n const attrs = getAttrs(token.content, 0, options);\n const openingToken = getMatchingOpeningToken(tokens, index);\n\n // Apply attributes to the opening token\n addAttrs(attrs, openingToken);\n\n // Remove the paragraph tokens containing the attributes\n tokens.splice(index + 1, 3);\n },\n },\n\n /**\n * - end of {.list-item}\n */\n {\n name: \"list item end\",\n tests: [\n {\n shift: -2,\n type: \"list_item_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"end\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n\n // Extract attributes from the content\n const attrStartIndex = content.lastIndexOf(options.left);\n const attrs = getAttrs(content, attrStartIndex, options);\n\n // Apply attributes to the list item opening token\n addAttrs(attrs, tokens[index - 2]);\n\n // Remove attribute syntax from content\n const contentWithoutAttributes = content.slice(0, attrStartIndex);\n const hasTrailingSpace =\n contentWithoutAttributes[contentWithoutAttributes.length - 1] === \" \";\n\n token.content = hasTrailingSpace\n ? contentWithoutAttributes.slice(0, -1)\n : contentWithoutAttributes;\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getSoftBreakRule = (\n options: Required<DelimiterConfig>,\n): AttrRule => ({\n /**\n * something with softbreak\n * {.cls}\n */\n\n name: \"\\n{.a} softbreak then curly in start\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -2,\n type: \"softbreak\",\n },\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const attrs = getAttrs(token.content, 0, options);\n\n // Find the last closing tag by searching forward\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Get the corresponding opening token\n const openingToken = getMatchingOpeningToken(tokens, closingTokenIndex);\n\n // Apply attributes to the opening token\n addAttrs(attrs, openingToken);\n\n // Remove the softbreak and attribute tokens\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n tokens[index].children = tokens[index].children!.slice(0, -2);\n },\n});\n","import { escapeRegExp } from \"@mdit/helper\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport { addAttrs, getAttrs } from \"../helper/index.js\";\n\nexport const getHrRule = (options: Required<DelimiterConfig>): AttrRule => ({\n /**\n * horizontal rule --- {#id}\n */\n name: \"horizontal rule\",\n tests: [\n {\n shift: 0,\n type: \"paragraph_open\",\n },\n {\n shift: 1,\n type: \"inline\",\n children: (children) => children.length === 1,\n content: (content) =>\n new RegExp(\n `^ {0,3}[-*_]{3,} ?${escapeRegExp(options.left)}[^${escapeRegExp(\n options.right,\n )}]`,\n ).test(content),\n },\n {\n shift: 2,\n type: \"paragraph_close\",\n },\n ],\n transform: (tokens, index): void => {\n const token = tokens[index];\n\n token.type = \"hr\";\n token.tag = \"hr\";\n token.nesting = 0;\n\n // Extract attributes from the inline content\n const inlineToken = tokens[index + 1];\n const { content } = inlineToken;\n const attributeStartIndex = content.lastIndexOf(options.left);\n const attributes = getAttrs(content, attributeStartIndex, options);\n\n // Apply attributes to the hr token\n addAttrs(attributes, token);\n token.markup = content;\n\n // Remove the inline and closing paragraph tokens\n tokens.splice(index + 1, 2);\n },\n});\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\ninterface TokenWithColumnCount extends Token {\n meta:\n | {\n columnCount?: number;\n [key: string]: unknown;\n }\n | undefined;\n}\n\n/**\n * Hidden table's cells and them inline children,\n * specially cast inline's content as empty\n * to prevent that escapes the table's box model\n */\nconst hideTokenContent = (token: Token): void => {\n token.hidden = true;\n token.children?.forEach((childToken) => {\n childToken.content = \"\";\n hideTokenContent(childToken);\n });\n};\n\n/**\n * Handle rowspan logic for table cells\n */\nconst handleRowspan = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n columnCount: number,\n colspan: number,\n rowspan: number,\n): void => {\n let adjustedColumnCount = columnCount - (colspan > 0 ? colspan : 1);\n\n for (\n let tokenIndex = startIndex, remainingRows = rowspan;\n tokenIndex < endIndex && remainingRows > 1;\n tokenIndex++\n ) {\n if (tokens[tokenIndex].type === \"tr_open\") {\n const trOpenToken = tokens[tokenIndex] as TokenWithColumnCount;\n\n trOpenToken.meta ??= {};\n\n if (trOpenToken.meta.columnCount) {\n adjustedColumnCount -= 1;\n }\n\n trOpenToken.meta.columnCount = adjustedColumnCount;\n remainingRows--;\n }\n }\n};\n\n/**\n * Handle table row processing\n */\nconst handleTableRow = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n): void => {\n const token = tokens[startIndex] as TokenWithColumnCount;\n const expectedColumnCount = token.meta?.columnCount;\n\n if (!expectedColumnCount) return;\n\n // hide extra table cells in the row\n for (let index = startIndex, cellCount = 0; index < endIndex; index++) {\n const currentToken = tokens[index];\n\n // Count table cells in the row\n if (currentToken.type === \"td_open\") {\n cellCount += 1;\n }\n // break at end of table row\n else if (currentToken.type === \"tr_close\") {\n break;\n }\n\n // hide extra table cells\n if (cellCount > expectedColumnCount && !currentToken.hidden) {\n hideTokenContent(currentToken);\n }\n }\n};\n\n/**\n * Handle colspan logic for table cells\n */\nconst handleColspan = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n columnCount: number,\n colspan: number,\n tbodyOpenIndex: number,\n): void => {\n const cellIndices: number[] = [];\n const startToken = tokens[startIndex];\n\n let end = startIndex + 3;\n let colspanNum = columnCount;\n\n // Find previous row children indices\n for (let tokenIndex = startIndex; tokenIndex > tbodyOpenIndex; tokenIndex--) {\n if (tokens[tokenIndex].type === \"tr_open\") {\n colspanNum =\n (tokens[tokenIndex] as TokenWithColumnCount).meta?.columnCount ??\n colspanNum;\n break;\n } else if (tokens[tokenIndex].type === \"td_open\") {\n cellIndices.unshift(tokenIndex);\n }\n }\n\n // Find current row children indices\n for (let index = startIndex + 2; index < endIndex; index++) {\n if (tokens[index].type === \"tr_close\") {\n end = index;\n break;\n } else if (tokens[index].type === \"td_open\") {\n cellIndices.push(index);\n }\n }\n\n const cellOffset = cellIndices.indexOf(startIndex);\n\n const realColspan = Math.min(colspan, colspanNum - cellOffset);\n\n if (colspan > realColspan) {\n startToken.attrSet(\"colspan\", realColspan.toString());\n }\n\n const hiddenStartIndex = cellIndices.slice(\n colspanNum + 1 - columnCount - realColspan,\n )[0];\n\n for (let index = hiddenStartIndex; index < end; index++) {\n if (!tokens[index].hidden) hideTokenContent(tokens[index]);\n }\n};\n\nexport const getTableRules = (\n options: Required<DelimiterConfig>,\n): AttrRule[] => [\n {\n /**\n * | h1 |\n * | -- |\n * | c1 |\n *\n * {.c}\n */\n name: \"table\",\n tests: [\n {\n // let this token be i, such that for-loop continues at\n // next token after tokens.splice\n shift: 0,\n type: \"table_close\",\n },\n {\n shift: 1,\n type: \"paragraph_open\",\n },\n {\n shift: 2,\n type: \"inline\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n transform: (tokens, index): void => {\n const token = tokens[index + 2];\n const tableOpeningToken = getMatchingOpeningToken(tokens, index);\n const attrs = getAttrs(token.content, 0, options);\n\n // Apply attributes to the table opening token\n addAttrs(attrs, tableOpeningToken);\n\n // Remove the paragraph tokens containing the attributes\n tokens.splice(index + 1, 3);\n },\n },\n /**\n * Handle table cell attributes: title {.class}\n * This rule processes attributes within table cell text content\n */\n {\n name: \"table cell attributes\",\n tests: [\n {\n shift: -1,\n type: (type) => type === \"td_open\" || type === \"th_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"end\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const cellOpenToken = tokens[index - 1];\n const { content } = token;\n\n // Find last attribute syntax in the content\n const attrStartIndex = content.lastIndexOf(options.left);\n\n // Extract attributes from the content\n const attributes = getAttrs(content, attrStartIndex, options);\n\n // Apply attributes to the table cell token\n addAttrs(attributes, cellOpenToken);\n\n // Remove attribute syntax from content\n token.content = content.substring(0, attrStartIndex).trim();\n },\n },\n {\n /**\n * | A | B |\n * | -- | -- |\n * | 1 | 2 |\n *\n * | C | D |\n * | -- | -- |\n *\n * only `| A | B |` sets the columnCount metadata\n */\n name: \"table thead metadata\",\n tests: [\n {\n shift: 0,\n type: \"tr_close\",\n },\n {\n shift: 1,\n type: \"thead_close\",\n },\n {\n shift: 2,\n type: \"tbody_open\",\n },\n ],\n\n transform: (tokens, index): void => {\n const trOpenToken = getMatchingOpeningToken(tokens, index);\n const thCloseToken = tokens[index - 1];\n let columnCount = 0;\n let currentIndex = index - 1;\n\n // Find the matching tr_open token and count columns\n while (currentIndex > 0) {\n const currentToken = tokens[currentIndex];\n\n if (currentToken === trOpenToken) {\n const tHeadOpenToken = tokens[\n currentIndex - 1\n ] as TokenWithColumnCount;\n\n tHeadOpenToken.meta = {\n ...tHeadOpenToken.meta,\n columnCount,\n };\n break;\n }\n\n // Count th_close tokens at the same level\n if (\n currentToken.level === thCloseToken.level &&\n currentToken.type === thCloseToken.type\n ) {\n columnCount++;\n }\n\n currentIndex--;\n }\n\n // Apply metadata to tbody_open token\n const tbodyOpenToken = tokens[index + 2] as TokenWithColumnCount;\n\n tbodyOpenToken.meta = {\n ...tbodyOpenToken.meta,\n columnCount,\n };\n },\n },\n {\n /**\n * | A | B | C | D |\n * | -- | -- | -- | -- |\n * | 1 | 11 | 111 | 1111 {rowspan=3} |\n * | 2 {colspan=2 rowspan=2} | 22 | 222 | 2222 |\n * | 3 | 33 | 333 | 3333 |\n */\n name: \"table tbody calculate\",\n tests: [\n {\n shift: 0,\n type: \"tbody_close\",\n hidden: false,\n },\n ],\n transform: (tokens, index): void => {\n // Find the tbody_open token index\n let tbodyOpenIndex = index - 2;\n\n while (tbodyOpenIndex > 0) {\n tbodyOpenIndex--;\n if (tokens[tbodyOpenIndex].type === \"tbody_open\") break;\n }\n\n const columnCount = Number(\n (tokens[tbodyOpenIndex] as TokenWithColumnCount).meta?.columnCount ?? 0,\n );\n\n if (columnCount < 2) return;\n\n const maxLevel = tokens[index].level + 2;\n\n for (\n let currentIndex = tbodyOpenIndex;\n currentIndex < index;\n currentIndex++\n ) {\n if (tokens[currentIndex].level > maxLevel) continue;\n\n const token = tokens[currentIndex];\n const rowspan = token.hidden ? 0 : Number(token.attrGet(\"rowspan\"));\n const colspan = token.hidden ? 0 : Number(token.attrGet(\"colspan\"));\n\n if (rowspan > 1) {\n handleRowspan(\n tokens,\n currentIndex,\n index,\n columnCount,\n colspan,\n rowspan,\n );\n }\n\n if (token.type === \"tr_open\") {\n handleTableRow(tokens, currentIndex, index);\n }\n\n if (colspan > 1) {\n handleColspan(\n tokens,\n currentIndex,\n index,\n columnCount,\n colspan,\n tbodyOpenIndex,\n );\n }\n }\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type {\n MarkdownItAttrRuleName,\n MarkdownItAttrsOptions,\n} from \"../options.js\";\nimport { getBlockRule } from \"./block.js\";\nimport { getFenceRule } from \"./fence.js\";\nimport { getHrRule } from \"./hr.js\";\nimport { getInlineRules } from \"./inline.js\";\nimport { getListRules } from \"./list.js\";\nimport { getSoftBreakRule } from \"./softbreak.js\";\nimport { getTableRules } from \"./table.js\";\n\nconst AVAILABLE_RULES: MarkdownItAttrRuleName[] = [\n \"fence\",\n \"inline\",\n \"table\",\n \"list\",\n \"hr\",\n \"softbreak\",\n \"block\",\n];\n\nexport const getRules = (\n options: Required<MarkdownItAttrsOptions>,\n): AttrRule[] => {\n const enabledRules =\n // disable\n options.rule === false\n ? []\n : Array.isArray(options.rule)\n ? // user specific rules\n options.rule.filter((item) => AVAILABLE_RULES.includes(item))\n : AVAILABLE_RULES;\n\n const rules: AttrRule[] = [];\n\n if (enabledRules.includes(\"fence\")) rules.push(getFenceRule(options));\n if (enabledRules.includes(\"inline\")) rules.push(...getInlineRules(options));\n if (enabledRules.includes(\"table\")) rules.push(...getTableRules(options));\n if (enabledRules.includes(\"list\")) rules.push(...getListRules(options));\n if (enabledRules.includes(\"softbreak\")) rules.push(getSoftBreakRule(options));\n if (enabledRules.includes(\"hr\")) rules.push(getHrRule(options));\n if (enabledRules.includes(\"block\")) rules.push(getBlockRule(options));\n\n return rules;\n};\n","/**\n * Forked and modified from https://github.com/arve0/markdown-it-attrs/\n */\n\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type { RuleCore } from \"markdown-it/lib/parser_core.mjs\";\n\nimport { testRule } from \"./helper/index.js\";\nimport type { MarkdownItAttrsOptions } from \"./options.js\";\nimport { getRules } from \"./rules/index.js\";\n\nexport const attrs: PluginWithOptions<MarkdownItAttrsOptions> = (\n md,\n { left = \"{\", right = \"}\", allowed = [], rule = \"all\" } = {},\n) => {\n const rules = getRules({\n left,\n right,\n allowed,\n rule,\n });\n\n const attrsRule: RuleCore = ({ tokens }) => {\n for (let index = 0; index < tokens.length; index++)\n for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex++) {\n const pattern = rules[ruleIndex];\n // position of child with offset 0\n let position: null | number = null;\n\n const match = pattern.tests.every((t) => {\n const result = testRule(tokens, index, t);\n\n if (result.position !== null) ({ position } = result);\n\n return result.match;\n });\n\n if (match) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n pattern.transform(tokens, index, position!);\n\n if (\n pattern.name === \"inline attributes\" ||\n pattern.name === \"inline nesting self-close\"\n )\n // retry, may be several inline attributes\n ruleIndex--;\n }\n }\n };\n\n md.core.ruler.before(\"linkify\", \"attrs\", attrsRule);\n};\n"],"names":["addAttrs","attrs","token","key","value","CLASS_MARKER","ID_MARKER","ALLOWED_KEY_CHARS","PAIR_SEPARATOR","KEY_SEPARATOR","getAttrs","str","start","left","right","allowed","parsingKey","valueInsideQuotes","index","char","attr","item","getDelimiterChecker","where","content","leftLength","rightLength","minCurlyLength","rightDelimiterMinimumShift","validCurlyLength","curly","end","slice","nextChar","getMatchingOpeningToken","tokens","level","type","currentToken","removeDelimiter","escapeRegExp","pos","getArrayItem","arr","isArrayOfFunctions","isArrayOfObjects","testRule","rule","result","tokenIndex","match","childTests","children","childTest","position","ruleDetail","ruleItem","getBlockRule","options","childIndex","attrStartIndex","closingTokenIndex","openingToken","contentWithoutAttributes","hasTrailingSpace","getFenceRule","lineNumbers","lineNumberMatch","attributeStartIndex","attributes","infoWithoutAttributes","getInlineRules","rightDelimiterLength","attrEndIndex","targetToken","attributeEndIndex","getListRules","listOpenIndex","getSoftBreakRule","getHrRule","inlineToken","hideTokenContent","childToken","handleRowspan","startIndex","endIndex","columnCount","colspan","rowspan","adjustedColumnCount","remainingRows","trOpenToken","handleTableRow","expectedColumnCount","cellCount","handleColspan","tbodyOpenIndex","cellIndices","startToken","colspanNum","cellOffset","realColspan","hiddenStartIndex","getTableRules","tableOpeningToken","cellOpenToken","thCloseToken","currentIndex","tHeadOpenToken","tbodyOpenToken","maxLevel","AVAILABLE_RULES","getRules","enabledRules","rules","md","attrsRule","ruleIndex","pattern","t"],"mappings":"4CAIO,MAAMA,EAAW,CAACC,EAAeC,IAA8B,CAC/DA,GAELD,EAAM,QAAQ,CAAC,CAACE,EAAKC,CAAK,IAAM,CAC9B,OAAQD,GACN,IAAK,QACHD,EAAM,SAAS,QAASE,CAAK,EAC7B,MACF,IAAK,aACHF,EAAM,SAAS,aAAcE,CAAK,EAClC,MACF,QACEF,EAAM,SAAS,CAACC,EAAKC,CAAK,CAAC,CAC/B,CACF,CAAC,CACH,ECnBaC,EAAe,IACfC,EAAY,IACZC,EAAoB,kBACpBC,EAAiB,IACjBC,EAAgB,ICKhBC,EAAW,CACtBC,EACAC,EACA,CAAE,KAAAC,EAAM,MAAAC,EAAO,QAAAC,CAAQ,IACZ,CACX,IAAIZ,EAAM,GACNC,EAAQ,GACRY,EAAa,GACbC,EAAoB,GAExB,MAAMhB,EAAgB,CAAA,EAKtB,QAASiB,EAAQN,EAAQC,EAAK,OAAQK,EAAQP,EAAI,OAAQO,IAAS,CACjE,GAAIP,EAAI,MAAMO,EAAOA,EAAQJ,EAAM,MAAM,IAAMA,EAAO,CAChDX,IAAQ,IAAIF,EAAM,KAAK,CAACE,EAAKC,CAAK,CAAC,EACvC,KACF,CAEA,MAAMe,EAAOR,EAAI,OAAOO,CAAK,EAG7B,GAAIC,IAASV,GAAiBO,EAAY,CACxCA,EAAa,GACb,QACF,CAGA,GAAIG,IAASd,GAAgBF,IAAQ,GAAI,CACnCQ,EAAI,OAAOO,EAAQ,CAAC,IAAMb,GAC5BF,EAAM,aACNe,KAEAf,EAAM,QAGRa,EAAa,GACb,QACF,CAGA,GAAIG,IAASb,GAAaH,IAAQ,GAAI,CACpCA,EAAM,KACNa,EAAa,GACb,QACF,CAGA,GAAIG,IAAS,KAAOf,IAAU,IAAM,CAACa,EAAmB,CACtDA,EAAoB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AS,qBACjBA,EAAQ,OAAS,8BAGjBD,IAEN,CACJ,EAEAF,EAAG,KAAK,MAAM,OAAO,UAAW,QAASC,CAAS,CACpD"}
1
+ {"version":3,"file":"index.js","sources":["../src/helper/constants.ts","../src/helper/getAttrs.ts","../src/helper/addAttrs.ts","../src/helper/getDelimiterChecker.ts","../src/helper/getMatchingOpeningToken.ts","../src/utils.ts","../src/helper/testRule.ts","../src/rules/block.ts","../src/rules/fence.ts","../src/rules/heading.ts","../src/rules/inline.ts","../src/rules/list.ts","../src/rules/softbreak.ts","../src/rules/hr.ts","../src/rules/table.ts","../src/rules/rules.ts","../src/plugin.ts"],"sourcesContent":["/** . */\nexport const CLASS_MARKER = 46;\n/** # */\nexport const ID_MARKER = 35;\n/** space */\nexport const PAIR_SEPARATOR = 32;\n/** = */\nexport const KEY_SEPARATOR = 61;\n/** \" */\nexport const QUOTE_MARKER = 34;\n","import {\n CLASS_MARKER,\n ID_MARKER,\n KEY_SEPARATOR,\n PAIR_SEPARATOR,\n QUOTE_MARKER,\n} from \"./constants.js\";\nimport type { Attr } from \"./types.js\";\nimport type { DelimiterRange } from \"../rules/types.js\";\n\nconst isAllowedKeyChar = (charCode: number): boolean =>\n !(\n charCode === 9 /* \\t */ ||\n charCode === 10 /* \\n */ ||\n charCode === 12 /* \\f */ ||\n charCode === 32 /* 空格 */ ||\n charCode === 47 /* / */ ||\n charCode === 62 /* > */ ||\n charCode === 34 /* \" */ ||\n charCode === 39 /* ' */ ||\n charCode === 61 /* = */\n );\n\nexport const getAttrs = (\n str: string,\n range: DelimiterRange,\n allowed: (string | RegExp)[],\n): Attr[] => {\n let key = \"\";\n let value = \"\";\n let parsingKey = true;\n let valueInsideQuotes = false;\n\n const attrs: Attr[] = [];\n\n // read inside marker\n // start + left delimiter length to avoid beginning marker\n // breaks when ending marker is found or end of string\n for (let index = range[0]; index < range[1]; index++) {\n const charCode = str.charCodeAt(index);\n\n // switch to reading value if equal sign\n if (charCode === KEY_SEPARATOR && parsingKey) {\n parsingKey = false;\n continue;\n }\n\n // {.class} {..css-module}\n if (charCode === CLASS_MARKER && key === \"\") {\n if (str.charCodeAt(index + 1) === CLASS_MARKER) {\n key = \"css-module\";\n index++;\n } else {\n key = \"class\";\n }\n\n parsingKey = false;\n continue;\n }\n\n // {#id}\n if (charCode === ID_MARKER && key === \"\") {\n key = \"id\";\n parsingKey = false;\n continue;\n }\n\n // {value=\"inside quotes\"}\n if (charCode === QUOTE_MARKER && value === \"\" && !valueInsideQuotes) {\n valueInsideQuotes = true;\n continue;\n }\n\n if (charCode === QUOTE_MARKER && valueInsideQuotes) {\n valueInsideQuotes = false;\n continue;\n }\n\n // read next key/value pair\n if (charCode === PAIR_SEPARATOR && !valueInsideQuotes) {\n if (key === \"\")\n // beginning or ending space: { .red } vs {.red}\n continue;\n\n attrs.push([key, value]);\n key = \"\";\n value = \"\";\n parsingKey = true;\n\n continue;\n }\n\n // continue if character not allowed\n if (parsingKey && !isAllowedKeyChar(charCode)) continue;\n\n // no other conditions met; append to key/value\n if (parsingKey) {\n key += String.fromCharCode(charCode);\n continue;\n }\n\n value += String.fromCharCode(charCode);\n }\n\n // append last key/value pair\n if (key !== \"\") attrs.push([key, value]);\n\n return allowed.length\n ? attrs.filter(([attr]) =>\n allowed.some((item) =>\n item instanceof RegExp ? item.test(attr) : item === attr,\n ),\n )\n : attrs;\n};\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nimport { getAttrs } from \"./getAttrs.js\";\nimport type { DelimiterRange } from \"../rules/types.js\";\n\nexport const addAttrs = (\n token: Token | null,\n content: string,\n range: DelimiterRange,\n allowed: (string | RegExp)[],\n): void => {\n if (!token) return;\n\n getAttrs(content, range, allowed).forEach(([key, value]) => {\n switch (key) {\n case \"class\":\n token.attrJoin(\"class\", value);\n break;\n case \"css-module\":\n token.attrJoin(\"css-module\", value);\n break;\n default:\n token.attrPush([key, value]);\n }\n });\n};\n","import { CLASS_MARKER, ID_MARKER } from \"./constants.js\";\nimport type { DelimiterConfig } from \"./types.js\";\nimport type { DelimiterChecker } from \"../rules/types.js\";\n\n/**\n * Get a function to check if a string matches the delimiter pattern\n * 获取一个函数来检查字符串是否匹配分隔符模式\n *\n * @param options - Delimiter configuration / 分隔符配置\n * @param where - Position for matching: start, end, or only / 匹配位置:开始、结束或仅匹配\n * @returns A function that checks if content matches the delimiter pattern / 检查内容是否匹配分隔符模式的函数\n */\nexport const getDelimiterChecker = (\n { left, right }: DelimiterConfig,\n where: \"start\" | \"end\" | \"only\",\n): DelimiterChecker => {\n if (![\"start\", \"end\", \"only\"].includes(where)) {\n throw new Error(\n `Invalid 'where' parameter: ${where}. Expected 'start', 'end', or 'only'.`,\n );\n }\n\n // Cache frequently used values\n const leftLength = left.length;\n const rightLength = right.length;\n const minContentLength = leftLength + 1 + rightLength;\n\n return (content) => {\n // Quick check for minimum length requirements\n if (typeof content !== \"string\" || content.length < minContentLength)\n return false;\n\n let start: number;\n let end: number;\n\n if (where === \"start\") {\n // Check if content starts with left delimiter\n if (!content.startsWith(left)) return false;\n\n start = leftLength;\n end = content.indexOf(right, leftLength + 1);\n\n if (end === -1) return false;\n\n // Check if next character is not part of right delimiter\n const nextCharPos = end + rightLength;\n\n if (\n nextCharPos < content.length &&\n right.includes(content.charAt(nextCharPos))\n ) {\n return false;\n }\n } else if (where === \"end\") {\n // Check if content ends with right delimiter\n start = content.lastIndexOf(left);\n\n if (start === -1) {\n return false;\n }\n\n end = content.indexOf(right, start + leftLength + 1);\n start += leftLength;\n\n if (end === -1 || end + rightLength !== content.length) {\n return false;\n }\n } else {\n // Check if content is wrapped by delimiters ('{.a}')\n if (!content.startsWith(left) || !content.endsWith(right)) return false;\n\n start = leftLength;\n end = content.length - rightLength;\n }\n\n // Check if content between delimiters is valid\n const firstCharCode = content.charCodeAt(start);\n const length = end - start;\n\n const isValid =\n firstCharCode === CLASS_MARKER || firstCharCode === ID_MARKER\n ? length >= 2\n : length >= 1;\n\n if (!isValid) return false;\n\n return [start, end];\n };\n};\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nexport const getMatchingOpeningToken = (\n tokens: Token[],\n index: number,\n): Token | null => {\n const token = tokens[index];\n\n if (token.type === \"softbreak\") return null;\n\n // non closing blocks, example img\n if (token.nesting === 0) return token;\n\n const level = token.level;\n const type = token.type.replace(\"_close\", \"_open\");\n\n while (index >= 0) {\n const currentToken = tokens[index];\n\n if (currentToken.type === type && currentToken.level === level)\n return currentToken;\n\n index--;\n }\n\n /* istanbul ignore next -- @preserve */\n return null;\n};\n","/**\n * Get index item of array. Supports negative index, where -1 is last element in array.\n *\n * 获取数组中的索引项。支持负索引,其中 -1 是数组的最后一个元素。\n *\n * @param arr - Array to get item from / 要获取项的数组\n * @param index - Index of item / 项的索引\n * @returns Array item / 数组项\n */\nexport const getArrayItem = <T>(arr: T[], index: number): T =>\n index >= 0 ? arr[index] : arr[arr.length + index];\n","import type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { AttrRuleSet } from \"../rules/types.js\";\nimport { getArrayItem } from \"../utils.js\";\n\nexport interface TestRuleResult {\n /** whether rule matches token stream */\n match: boolean;\n /** position of token */\n position: null | number;\n range: [start: number, end: number] | null;\n}\n\n/**\n * Test if rule matches token stream.\n *\n */\nexport const testRule = (\n tokens: Token[],\n index: number,\n rule: AttrRuleSet,\n): TestRuleResult => {\n const testResult: TestRuleResult = {\n match: false,\n position: null,\n range: null,\n };\n const isShift = rule.shift !== undefined;\n\n const tokenIndex = isShift ? index + rule.shift : rule.position;\n\n // we should never shift to negative indexes (rolling around to back of array)\n if (isShift && tokenIndex < 0) return testResult;\n\n const token = getArrayItem(tokens, tokenIndex);\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!token) return testResult;\n\n for (const key of Object.keys(rule) as (keyof typeof rule)[]) {\n if (key === \"shift\" || key === \"position\") continue;\n\n if (token[key as keyof Token] == undefined) return testResult;\n\n if (key === \"children\" && Array.isArray(rule.children)) {\n if (!token.children?.length) return testResult;\n\n const childTests = rule.children;\n const children = token.children;\n let match;\n let range: [start: number, end: number] | null = null;\n\n if (childTests.every((childTest) => childTest.position != undefined)) {\n // positions instead of shifts, do not loop all children\n match = childTests.every((childTest) => {\n const result = testRule(children, childTest.position, childTest);\n\n if (!result.match) return false;\n\n if (result.range) range = result.range;\n\n return true;\n });\n\n if (match) {\n // get position of child\n const { position } = childTests[childTests.length - 1];\n\n testResult.position =\n position >= 0 ? position : children.length + position;\n\n // set pos data\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n testResult.range = range!;\n }\n } else {\n for (let childIndex = 0; childIndex < children.length; childIndex++) {\n match = childTests.every((childTest) => {\n const result = testRule(children, childIndex, childTest);\n\n if (!result.match) return false;\n\n if (result.range) range = result.range;\n\n return true;\n });\n\n if (match) {\n testResult.position = childIndex;\n // set pos data\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (range) testResult.range = range;\n // all tests passes. so the check is successful\n break;\n }\n }\n }\n\n if (match === false) return testResult;\n\n continue;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const ruleDetail = rule[key];\n\n switch (typeof ruleDetail) {\n case \"boolean\":\n case \"number\":\n case \"string\": {\n if (token[key] !== ruleDetail) return testResult;\n\n break;\n }\n\n case \"function\": {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n const result = ruleDetail(token[key]) as\n | boolean\n | [start: number, end: number];\n\n if (!result) return testResult;\n\n if (Array.isArray(result)) testResult.range = result;\n\n break;\n }\n\n // fall through for objects !== arrays of functions\n default: {\n throw new Error(\n `Unknown type of pattern test (key: ${key}). Test should be of type boolean, number, string or function.`,\n );\n }\n }\n }\n\n // no tests returned false -> all tests returns true\n testResult.match = true;\n\n return testResult;\n};\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getBlockRule = (options: DelimiterConfig): AttrRule =>\n /**\n * end of {.block}\n */\n ({\n name: \"end of block\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n content: getDelimiterChecker(options, \"end\"),\n type: (type) => type !== \"code_inline\" && type !== \"math_inline\",\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n const attrStartIndex = range[0] - options.left.length;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n const hasTrailingSpace = isSpace(content.charCodeAt(attrStartIndex - 1));\n\n // Find the closing token by skipping all nested closing tokens\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Get the corresponding opening token\n const openingToken = getMatchingOpeningToken(tokens, closingTokenIndex);\n\n // Apply attributes to the opening token\n addAttrs(openingToken, content, range, options.allowed);\n\n // Remove the attribute syntax from content\n token.content = content.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n });\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport { addAttrs, getDelimiterChecker } from \"../helper/index.js\";\n\nexport const getFenceRule = (options: DelimiterConfig): AttrRule =>\n /**\n * fenced code blocks\n *\n * ```python {.cls}\n * for i in range(10):\n * print(i)\n * ```\n */\n ({\n name: \"code-block\",\n tests: [\n {\n shift: 0,\n block: true,\n info: getDelimiterChecker(options, \"end\"),\n },\n ],\n transform: (tokens, index, _, range): void => {\n const attrStartIndex = range[0] - options.left.length;\n const token = tokens[index];\n const { info } = token;\n const hasTrailingSpace = isSpace(info.charCodeAt(attrStartIndex - 1));\n\n // Apply attributes to the current token\n addAttrs(token, info, range, options.allowed);\n\n // Remove the attribute syntax from info\n token.info = info.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n });\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getHeadingRule = (options: DelimiterConfig): AttrRule =>\n /**\n * ## end of {#heading}\n */\n ({\n name: \"end of block\",\n tests: [\n {\n shift: -1,\n type: \"heading_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n content: getDelimiterChecker(options, \"end\"),\n type: (type) => type !== \"code_inline\" && type !== \"math_inline\",\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n const attrStartIndex = range[0] - options.left.length;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n const hasTrailingSpace = isSpace(content.charCodeAt(attrStartIndex - 1));\n\n // Find the closing token by skipping all nested closing tokens\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Get the corresponding opening token\n const openingToken = getMatchingOpeningToken(tokens, closingTokenIndex);\n\n // Apply attributes to the opening token\n addAttrs(openingToken, content, range, options.allowed);\n\n // Remove the attribute syntax from content\n token.content = content.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n });\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getInlineRules = (options: DelimiterConfig): AttrRule[] => [\n /**\n * bla `click()`{.c} ![](img.png){.d}\n *\n * differs from 'inline attributes' as it does\n * not have a closing tag (nesting: -1)\n */\n {\n name: \"inline nesting self-close\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: -1,\n type: (str) => str === \"image\" || str === \"code_inline\",\n },\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"start\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const childTokens = tokens[index].children!;\n const token = childTokens[childIndex];\n const targetToken = childTokens[childIndex - 1];\n const attrsEndIndex = options.right.length + range[1];\n\n // Apply attributes to the target token\n addAttrs(targetToken, token.content, range, options.allowed);\n\n if (token.content.length === attrsEndIndex) {\n childTokens.splice(childIndex, 1);\n } else {\n token.content = token.content.slice(attrsEndIndex);\n }\n },\n },\n\n /**\n * *emphasis*{.with attrs=1}\n */\n {\n name: \"inline attributes\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: -1,\n nesting: -1, // closing inline tag, </em>{.a}\n },\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"start\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const childTokens = tokens[index].children!;\n const currentToken = childTokens[childIndex];\n const { content } = currentToken;\n const attrsEndIndex = options.right.length + range[1];\n\n // Find the corresponding opening token\n const openingToken = getMatchingOpeningToken(childTokens, childIndex - 1);\n\n // Apply attributes to the opening token\n addAttrs(openingToken, content, range, options.allowed);\n\n // Remove attribute syntax from content\n currentToken.content = content.slice(attrsEndIndex);\n },\n },\n];\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getListRules = (options: DelimiterConfig): AttrRule[] => [\n /**\n * - item\n * {.a}\n */\n {\n name: \"list softbreak\",\n tests: [\n {\n shift: -2,\n type: \"list_item_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -2,\n type: \"softbreak\",\n },\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const childTokens = tokens[index].children!;\n const token = childTokens[childIndex];\n\n let listOpenIndex = index - 2;\n\n // Find the list opening token\n while (\n tokens[listOpenIndex - 1] &&\n tokens[listOpenIndex - 1].type !== \"ordered_list_open\" &&\n tokens[listOpenIndex - 1].type !== \"bullet_list_open\"\n ) {\n listOpenIndex--;\n }\n\n // Apply attributes to the list opening token\n addAttrs(\n tokens[listOpenIndex - 1],\n token.content,\n range,\n options.allowed,\n );\n\n // Remove the attribute tokens from children\n tokens[index].children = childTokens.slice(0, -2);\n },\n },\n\n /**\n * - nested list\n * - with double \\n\n * {.a} <-- apply to nested ul\n *\n * {.b} <-- apply to root <ul>\n */\n {\n name: \"list double softbreak\",\n tests: [\n {\n // let this token be i = 0 so that we can erase\n // the <p>{.a}</p> tokens below\n shift: 0,\n type: (type) =>\n type === \"bullet_list_close\" || type === \"ordered_list_close\",\n },\n {\n shift: 1,\n type: \"paragraph_open\",\n },\n {\n shift: 2,\n type: \"inline\",\n content: getDelimiterChecker(options, \"only\"),\n children: (children) => children.length === 1,\n },\n {\n shift: 3,\n type: \"paragraph_close\",\n },\n ],\n transform: (tokens, index, _, range): void => {\n const token = tokens[index + 2];\n const openingToken = getMatchingOpeningToken(tokens, index);\n\n // Apply attributes to the opening token\n addAttrs(openingToken, token.content, range, options.allowed);\n\n // Remove the paragraph tokens containing the attributes\n tokens.splice(index + 1, 3);\n },\n },\n\n /**\n * - end of {.list-item}\n */\n {\n name: \"list item end\",\n tests: [\n {\n shift: -2,\n type: \"list_item_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"end\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const { content } = token;\n const attrStartIndex = range[0] - options.left.length;\n const hasTrailingSpace = isSpace(content.charCodeAt(attrStartIndex - 1));\n\n // Apply attributes to the list item opening token\n addAttrs(tokens[index - 2], content, range, options.allowed);\n\n // Remove attribute syntax from content\n token.content = content.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\nexport const getSoftBreakRule = (options: DelimiterConfig): AttrRule => ({\n /**\n * something with softbreak\n * {.cls}\n */\n\n name: \"\\n{.a} softbreak then curly in start\",\n tests: [\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n position: -2,\n type: \"softbreak\",\n },\n {\n position: -1,\n type: \"text\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const childTokens = tokens[index].children!;\n const token = childTokens[childIndex];\n\n // Find the last closing tag by searching forward\n let closingTokenIndex = index + 1;\n\n while (\n tokens[closingTokenIndex + 1] &&\n tokens[closingTokenIndex + 1].nesting === -1\n ) {\n closingTokenIndex++;\n }\n\n // Apply attributes to the opening token\n addAttrs(\n getMatchingOpeningToken(tokens, closingTokenIndex),\n token.content,\n range,\n options.allowed,\n );\n\n // Remove the softbreak and attribute tokens\n tokens[index].children = childTokens.slice(0, -2);\n },\n});\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\n\nimport type { AttrRule, DelimiterRange } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport { addAttrs, getDelimiterChecker } from \"../helper/index.js\";\n\nexport const getHrRule = (options: DelimiterConfig): AttrRule => ({\n /**\n * horizontal rule --- {#id}\n */\n name: \"horizontal rule\",\n tests: [\n {\n shift: 0,\n type: \"paragraph_open\",\n },\n {\n shift: 1,\n type: \"inline\",\n children: (children) => children.length === 1,\n content: (content): DelimiterRange | false => {\n let pos = 0;\n let charCode;\n let offset = 0;\n\n while (pos < content.length) {\n charCode = content.charCodeAt(pos++);\n\n if (charCode === 32 /** space */) offset++;\n else if (charCode === 9 /** tab */) offset += 4 - (offset % 4);\n else break;\n }\n\n if (offset > 3) return false;\n\n const markerCode = content.charCodeAt(pos - 1);\n\n if (\n markerCode !== 45 /** - */ &&\n markerCode !== 42 /** * */ &&\n markerCode !== 95 /** _ */\n )\n return false;\n\n let count = 1;\n\n while (pos < content.length) {\n charCode = content.charCodeAt(pos++);\n if (charCode !== markerCode) break;\n count++;\n }\n\n if (count < 3) return false;\n\n if (!isSpace(content.charCodeAt(pos - 1))) pos--;\n\n return getDelimiterChecker(options, \"end\")(content);\n },\n },\n {\n shift: 2,\n type: \"paragraph_close\",\n },\n ],\n transform: (tokens, index, _, range): void => {\n const token = tokens[index];\n // Extract attributes from the inline content\n const inlineToken = tokens[index + 1];\n const { content } = inlineToken;\n\n token.type = \"hr\";\n token.tag = \"hr\";\n token.nesting = 0;\n\n // Apply attributes to the hr token\n addAttrs(token, content, range, options.allowed);\n token.markup = content;\n\n // Remove the inline and closing paragraph tokens\n tokens.splice(index + 1, 2);\n },\n});\n","import { isSpace } from \"markdown-it/lib/common/utils.mjs\";\nimport type Token from \"markdown-it/lib/token.mjs\";\n\nimport type { AttrRule } from \"./types.js\";\nimport type { DelimiterConfig } from \"../helper/index.js\";\nimport {\n addAttrs,\n getDelimiterChecker,\n getMatchingOpeningToken,\n} from \"../helper/index.js\";\n\ninterface TokenWithColumnCount extends Token {\n meta:\n | {\n columnCount?: number;\n [key: string]: unknown;\n }\n | undefined;\n}\n\n/**\n * Hidden table's cells and them inline children,\n * specially cast inline's content as empty\n * to prevent that escapes the table's box model\n */\nconst hideTokenContent = (token: Token): void => {\n token.hidden = true;\n token.children?.forEach((childToken) => {\n childToken.content = \"\";\n hideTokenContent(childToken);\n });\n};\n\n/**\n * Handle rowspan logic for table cells\n */\nconst handleRowspan = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n columnCount: number,\n colspan: number,\n rowspan: number,\n): void => {\n let adjustedColumnCount = columnCount - (colspan > 0 ? colspan : 1);\n\n for (\n let tokenIndex = startIndex, remainingRows = rowspan;\n tokenIndex < endIndex && remainingRows > 1;\n tokenIndex++\n ) {\n if (tokens[tokenIndex].type === \"tr_open\") {\n const trOpenToken = tokens[tokenIndex] as TokenWithColumnCount;\n\n trOpenToken.meta ??= {};\n\n if (trOpenToken.meta.columnCount) adjustedColumnCount -= 1;\n trOpenToken.meta.columnCount = adjustedColumnCount;\n remainingRows--;\n }\n }\n};\n\n/**\n * Handle table row processing\n */\nconst handleTableRow = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n): void => {\n const token = tokens[startIndex] as TokenWithColumnCount;\n const expectedColumnCount = token.meta?.columnCount;\n\n if (!expectedColumnCount) return;\n\n // hide extra table cells in the row\n for (let index = startIndex, cellCount = 0; index < endIndex; index++) {\n const currentToken = tokens[index];\n\n // break at end of table row\n if (currentToken.type === \"tr_close\") break;\n\n // Count table cells in the row\n if (currentToken.type === \"td_open\") cellCount += 1;\n\n // hide extra table cells\n if (cellCount > expectedColumnCount && !currentToken.hidden) {\n hideTokenContent(currentToken);\n }\n }\n};\n\n/**\n * Handle colspan logic for table cells\n */\nconst handleColspan = (\n tokens: Token[],\n startIndex: number,\n endIndex: number,\n columnCount: number,\n colspan: number,\n tbodyOpenIndex: number,\n): void => {\n const cellIndices: number[] = [];\n const startToken = tokens[startIndex];\n\n let end = startIndex + 3;\n let colspanNum = columnCount;\n\n // Find previous row children indices\n for (let tokenIndex = startIndex; tokenIndex > tbodyOpenIndex; tokenIndex--) {\n if (tokens[tokenIndex].type === \"tr_open\") {\n colspanNum =\n (tokens[tokenIndex] as TokenWithColumnCount).meta?.columnCount ??\n colspanNum;\n break;\n } else if (tokens[tokenIndex].type === \"td_open\") {\n cellIndices.unshift(tokenIndex);\n }\n }\n\n // Find current row children indices\n for (let index = startIndex + 2; index < endIndex; index++) {\n if (tokens[index].type === \"tr_close\") {\n end = index;\n break;\n } else if (tokens[index].type === \"td_open\") {\n cellIndices.push(index);\n }\n }\n\n const cellOffset = cellIndices.indexOf(startIndex);\n\n const realColspan = Math.min(colspan, colspanNum - cellOffset);\n\n if (colspan > realColspan) {\n startToken.attrSet(\"colspan\", realColspan.toString());\n }\n\n const hiddenStartIndex = cellIndices.slice(\n colspanNum + 1 - columnCount - realColspan,\n )[0];\n\n for (let index = hiddenStartIndex; index < end; index++) {\n if (!tokens[index].hidden) hideTokenContent(tokens[index]);\n }\n};\n\nexport const getTableRules = (options: DelimiterConfig): AttrRule[] => [\n {\n /**\n * | h1 |\n * | -- |\n * | c1 |\n *\n * {.c}\n */\n name: \"table\",\n tests: [\n {\n // let this token be i, such that for-loop continues at\n // next token after tokens.splice\n shift: 0,\n type: \"table_close\",\n },\n {\n shift: 1,\n type: \"paragraph_open\",\n },\n {\n shift: 2,\n type: \"inline\",\n content: getDelimiterChecker(options, \"only\"),\n },\n ],\n transform: (tokens, index, _, range): void => {\n const token = tokens[index + 2];\n const tableOpeningToken = getMatchingOpeningToken(tokens, index);\n\n // Apply attributes to the table opening token\n addAttrs(tableOpeningToken, token.content, range, options.allowed);\n\n // Remove the paragraph tokens containing the attributes\n tokens.splice(index + 1, 3);\n },\n },\n /**\n * Handle table cell attributes: title {.class}\n * This rule processes attributes within table cell text content\n */\n {\n name: \"table cell attributes\",\n tests: [\n {\n shift: -1,\n type: (type) => type === \"td_open\" || type === \"th_open\",\n },\n {\n shift: 0,\n type: \"inline\",\n children: [\n {\n shift: 0,\n type: \"text\",\n content: getDelimiterChecker(options, \"end\"),\n },\n ],\n },\n ],\n transform: (tokens, index, childIndex, range): void => {\n const attrStartIndex = range[0] - options.left.length;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const token = tokens[index].children![childIndex];\n const cellOpenToken = tokens[index - 1];\n const { content } = token;\n const hasTrailingSpace = isSpace(content.charCodeAt(attrStartIndex - 1));\n\n // Find last attribute syntax in the content\n\n // Apply attributes to the table cell token\n addAttrs(cellOpenToken, content, range, options.allowed);\n\n // Remove attribute syntax from content\n token.content = content.slice(\n 0,\n hasTrailingSpace ? attrStartIndex - 1 : attrStartIndex,\n );\n },\n },\n {\n /**\n * | A | B |\n * | -- | -- |\n * | 1 | 2 |\n *\n * | C | D |\n * | -- | -- |\n *\n * only `| A | B |` sets the columnCount metadata\n */\n name: \"table thead metadata\",\n tests: [\n {\n shift: 0,\n type: \"tr_close\",\n },\n {\n shift: 1,\n type: \"thead_close\",\n },\n {\n shift: 2,\n type: \"tbody_open\",\n },\n ],\n\n transform: (tokens, index): void => {\n const trOpenToken = getMatchingOpeningToken(tokens, index);\n const thCloseToken = tokens[index - 1];\n let columnCount = 0;\n let currentIndex = index - 1;\n\n // Find the matching tr_open token and count columns\n while (currentIndex > 0) {\n const currentToken = tokens[currentIndex];\n\n if (currentToken === trOpenToken) {\n const tHeadOpenToken = tokens[\n currentIndex - 1\n ] as TokenWithColumnCount;\n\n tHeadOpenToken.meta = {\n ...tHeadOpenToken.meta,\n columnCount,\n };\n break;\n }\n\n // Count th_close tokens at the same level\n if (\n currentToken.level === thCloseToken.level &&\n currentToken.type === thCloseToken.type\n ) {\n columnCount++;\n }\n\n currentIndex--;\n }\n\n // Apply metadata to tbody_open token\n const tbodyOpenToken = tokens[index + 2] as TokenWithColumnCount;\n\n tbodyOpenToken.meta = {\n ...tbodyOpenToken.meta,\n columnCount,\n };\n },\n },\n {\n /**\n * | A | B | C | D |\n * | -- | -- | -- | -- |\n * | 1 | 11 | 111 | 1111 {rowspan=3} |\n * | 2 {colspan=2 rowspan=2} | 22 | 222 | 2222 |\n * | 3 | 33 | 333 | 3333 |\n */\n name: \"table tbody calculate\",\n tests: [\n {\n shift: 0,\n type: \"tbody_close\",\n hidden: false,\n },\n ],\n transform: (tokens, index): void => {\n // Find the tbody_open token index\n let tbodyOpenIndex = index - 2;\n\n while (tbodyOpenIndex > 0) {\n tbodyOpenIndex--;\n if (tokens[tbodyOpenIndex].type === \"tbody_open\") break;\n }\n\n const columnCount = Number(\n (tokens[tbodyOpenIndex] as TokenWithColumnCount).meta?.columnCount ?? 0,\n );\n\n if (columnCount < 2) return;\n\n const maxLevel = tokens[index].level + 2;\n\n for (\n let currentIndex = tbodyOpenIndex;\n currentIndex < index;\n currentIndex++\n ) {\n if (tokens[currentIndex].level > maxLevel) continue;\n\n const token = tokens[currentIndex];\n const rowspan = token.hidden ? 0 : Number(token.attrGet(\"rowspan\"));\n const colspan = token.hidden ? 0 : Number(token.attrGet(\"colspan\"));\n\n if (rowspan > 1) {\n handleRowspan(\n tokens,\n currentIndex,\n index,\n columnCount,\n colspan,\n rowspan,\n );\n }\n\n if (token.type === \"tr_open\") {\n handleTableRow(tokens, currentIndex, index);\n }\n\n if (colspan > 1) {\n handleColspan(\n tokens,\n currentIndex,\n index,\n columnCount,\n colspan,\n tbodyOpenIndex,\n );\n }\n }\n },\n },\n];\n","import type { AttrRule } from \"./types.js\";\nimport type {\n MarkdownItAttrRuleName,\n MarkdownItAttrsOptions,\n} from \"../options.js\";\nimport { getBlockRule } from \"./block.js\";\nimport { getFenceRule } from \"./fence.js\";\nimport { getHeadingRule } from \"./heading.js\";\nimport { getHrRule } from \"./hr.js\";\nimport { getInlineRules } from \"./inline.js\";\nimport { getListRules } from \"./list.js\";\nimport { getSoftBreakRule } from \"./softbreak.js\";\nimport { getTableRules } from \"./table.js\";\n\nconst AVAILABLE_RULES: MarkdownItAttrRuleName[] = [\n \"fence\",\n \"inline\",\n \"table\",\n \"list\",\n \"heading\",\n \"hr\",\n \"softbreak\",\n \"block\",\n];\n\nexport const getRules = (\n options: Required<MarkdownItAttrsOptions>,\n): AttrRule[] => {\n const enabledRules =\n // disable\n options.rule === false\n ? []\n : Array.isArray(options.rule)\n ? // user specific rules\n options.rule.filter((item) => AVAILABLE_RULES.includes(item))\n : AVAILABLE_RULES;\n\n const rules: AttrRule[] = [];\n\n if (enabledRules.includes(\"fence\")) rules.push(getFenceRule(options));\n if (enabledRules.includes(\"inline\")) rules.push(...getInlineRules(options));\n if (enabledRules.includes(\"table\")) rules.push(...getTableRules(options));\n if (enabledRules.includes(\"list\")) rules.push(...getListRules(options));\n if (enabledRules.includes(\"softbreak\")) rules.push(getSoftBreakRule(options));\n if (enabledRules.includes(\"hr\")) rules.push(getHrRule(options));\n if (enabledRules.includes(\"block\")) rules.push(getBlockRule(options));\n // heading rule is fully covered by block rules\n else if (enabledRules.includes(\"heading\"))\n rules.push(getHeadingRule(options));\n\n return rules;\n};\n","/**\n * Forked and modified from https://github.com/arve0/markdown-it-attrs/\n */\n\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type { RuleCore } from \"markdown-it/lib/parser_core.mjs\";\n\nimport { testRule } from \"./helper/index.js\";\nimport type { MarkdownItAttrsOptions } from \"./options.js\";\nimport type { DelimiterRange } from \"./rules/index.js\";\nimport { getRules } from \"./rules/index.js\";\n\nexport const attrs: PluginWithOptions<MarkdownItAttrsOptions> = (\n md,\n { left = \"{\", right = \"}\", allowed = [], rule = \"all\" } = {},\n) => {\n const rules = getRules({\n left,\n right,\n allowed,\n rule,\n });\n\n const attrsRule: RuleCore = ({ tokens }) => {\n for (let index = 0; index < tokens.length; index++)\n for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex++) {\n const pattern = rules[ruleIndex];\n // position of child with offset 0\n let position: null | number = null;\n let range: DelimiterRange | null = null;\n\n const match = pattern.tests.every((test) => {\n const result = testRule(tokens, index, test);\n\n if (result.position !== null) ({ position } = result);\n if (result.range) range = result.range;\n\n return result.match;\n });\n\n if (match) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n pattern.transform(tokens, index, position!, range!);\n\n if (\n pattern.name === \"inline attributes\" ||\n pattern.name === \"inline nesting self-close\"\n )\n // retry, may be several inline attributes\n ruleIndex--;\n }\n }\n };\n\n md.core.ruler.before(\"linkify\", \"attrs\", attrsRule);\n};\n"],"names":["CLASS_MARKER","ID_MARKER","PAIR_SEPARATOR","KEY_SEPARATOR","QUOTE_MARKER","isAllowedKeyChar","charCode","getAttrs","str","range","allowed","key","value","parsingKey","valueInsideQuotes","attrs","index","attr","item","addAttrs","token","content","getDelimiterChecker","left","right","where","leftLength","rightLength","minContentLength","start","end","nextCharPos","firstCharCode","length","getMatchingOpeningToken","tokens","level","type","currentToken","getArrayItem","arr","testRule","rule","testResult","isShift","tokenIndex","childTests","children","match","childTest","result","position","childIndex","ruleDetail","getBlockRule","options","attrStartIndex","hasTrailingSpace","isSpace","closingTokenIndex","openingToken","getFenceRule","_","info","getHeadingRule","getInlineRules","childTokens","targetToken","attrsEndIndex","getListRules","listOpenIndex","getSoftBreakRule","getHrRule","pos","offset","markerCode","count","inlineToken","hideTokenContent","childToken","handleRowspan","startIndex","endIndex","columnCount","colspan","rowspan","adjustedColumnCount","remainingRows","trOpenToken","handleTableRow","expectedColumnCount","cellCount","handleColspan","tbodyOpenIndex","cellIndices","startToken","colspanNum","cellOffset","realColspan","hiddenStartIndex","getTableRules","tableOpeningToken","cellOpenToken","thCloseToken","currentIndex","tHeadOpenToken","tbodyOpenToken","maxLevel","AVAILABLE_RULES","getRules","enabledRules","rules","md","attrsRule","ruleIndex","pattern","test"],"mappings":"2DACa,MAAAA,EAAe,GAEfC,EAAY,GAEZC,EAAiB,GAEjBC,EAAgB,GAEhBC,EAAe,GCCtBC,EAAoBC,GACxB,EACEA,IAAa,GACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IACbA,IAAa,IAGJC,EAAW,CACtBC,EACAC,EACAC,IACW,CACX,IAAIC,EAAM,GACNC,EAAQ,GACRC,EAAa,GACbC,EAAoB,GAExB,MAAMC,EA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,SAAAC,CAAS,EAAID,GAC1CA,EAAO,QAAOzC,EAAQyC,EAAO,OAE1BA,EAAO,KAChB,CAAC,IAICiE,EAAQ,UAAUhF,EAAQnB,EAAOmC,EAAW1C,CAAM,GAGhD0G,EAAQ,OAAS,qBACjBA,EAAQ,OAAS,8BAGjBD,IAEN,CACJ,EAEAF,EAAG,KAAK,MAAM,OAAO,UAAW,QAASC,CAAS,CACpD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit/plugin-attrs",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "attrs plugin for MarkdownIt",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -26,23 +26,22 @@
26
26
  "exports": {
27
27
  ".": {
28
28
  "type": "./lib/index.d.ts",
29
- "browser": "./lib/browser.js",
30
29
  "default": "./lib/index.js"
31
30
  },
32
31
  "./package.json": "./package.json"
33
32
  },
34
- "main": "lib/index.js",
35
- "types": "lib/index.d.ts",
33
+ "browser": "./lib/browser.js",
34
+ "types": "./lib/index.d.ts",
36
35
  "files": [
37
36
  "lib"
38
37
  ],
39
38
  "dependencies": {
40
39
  "@types/markdown-it": "^14.1.2",
41
- "@mdit/helper": "0.22.0"
40
+ "@mdit/helper": "0.22.1"
42
41
  },
43
42
  "devDependencies": {
44
43
  "markdown-it": "14.1.0",
45
- "@mdit/plugin-katex": "0.22.0"
44
+ "@mdit/plugin-katex": "0.23.1"
46
45
  },
47
46
  "peerDependencies": {
48
47
  "markdown-it": "^14.1.0"