UNPKG

@unified-myst/role-extension

Version:

Extension to support the MyST role syntax (``{name}`content` ``) in unified

3 lines (2 loc) 3.1 kB
const e={mystRole:"mystRole",mystRoleMarker:"mystRoleMarker",mystRoleName:"mystRoleName"},t={mystRole:"mystRole",mystRoleName:"mystRoleName"};function n(e){return null!==e&&e<-2}const o={name:"codeText",tokenize:function(e,t,o){let r,i,s=0;return function(t){return e.enter("codeText"),e.enter("codeTextSequence"),c(t)};function c(t){return 96===t?(e.consume(t),s++,c):(e.exit("codeTextSequence"),l(t))}function l(t){return null===t?o(t):96===t?(i=e.enter("codeTextSequence"),r=0,a(t)):32===t?(e.enter("space"),e.consume(t),e.exit("space"),l):n(t)?(e.enter("lineEnding"),e.consume(t),e.exit("lineEnding"),l):(e.enter("codeTextData"),u(t))}function u(t){return null===t||32===t||96===t||n(t)?(e.exit("codeTextData"),l(t)):(e.consume(t),u)}function a(n){return 96===n?(e.consume(n),r++,a):r===s?(e.exit("codeTextSequence"),e.exit("codeText"),t(n)):(i.type="codeTextData",u(n))}},resolve:function(e){let t,n,o=e.length-4,r=3;if(!("lineEnding"!==e[r][1].type&&"space"!==e[r][1].type||"lineEnding"!==e[o][1].type&&"space"!==e[o][1].type))for(t=r;++t<o;)if("codeTextData"===e[t][1].type){e[r][1].type="codeTextPadding",e[o][1].type="codeTextPadding",r+=2,o-=2;break}t=r-1,o++;for(;++t<=o;)void 0===n?t!==o&&"lineEnding"!==e[t][1].type&&(n=t):t!==o&&"lineEnding"!==e[t][1].type||(e[n][1].type="codeTextData",t!==n+2&&(e[n][1].end=e[t-1][1].end,e.splice(n+2,t-n-2),o-=t-n-2,t=n+2),n=void 0);return e},previous:function(e){return 96!==e||"characterEscape"===this.events[this.events.length-1][1].type}};const r={text:{123:{name:"mystRole",tokenize:function(t,n,r){let i=!0;return function(n){return t.enter(e.mystRole),t.enter(e.mystRoleMarker),t.consume(n),t.exit(e.mystRoleMarker),c};function c(n){return s(n)?(t.enter(e.mystRoleName),t.enter("chunkString",{contentType:"string"}),l(n)):r(n)}function l(n){return 125===n?i?r(n):(t.exit("chunkString"),t.exit(e.mystRoleName),t.enter(e.mystRoleMarker),t.consume(n),t.exit(e.mystRoleMarker),t.attempt(o,u,r)):s(n)?(t.consume(n),i=!1,l):r(n)}function u(o){return t.exit(e.mystRole),n(o)}}}}},i=/[a-zA-Z0-9_.\-+:]/;function s(e){return null!==e&&i.test(String.fromCharCode(e))}const c={enter:{[e.mystRole]:function(){this.tag('<span class="myst-role">')}},exit:{[e.mystRole]:function(){this.tag("</span>")}}};const l={enter:{[e.mystRole]:function(e){this.enter({type:t.mystRole,children:[]},e)},[e.mystRoleName]:function(e){this.enter({type:t.mystRoleName},e),this.buffer()}},exit:{[e.mystRole]:function(e){const n=this.stack[this.stack.length-1],o=n.children;if(2!==o.length)throw new Error(`Expected 2 children for mystRole, but got ${o.length}`);const r=o[0],i=o[1];if(r.type!==t.mystRoleName)throw new Error(`Expected mystRoleName node, but got ${r.type}`);if("inlineCode"!==i.type)throw new Error(`Expected inlineCode node, but got ${i.type}`);delete n.children,n.name=r.value,n.value=i.value,this.exit(e)},[e.mystRoleName]:function(e){const t=this.resume();this.stack[this.stack.length-1].value=t,this.exit(e)}}};export{c as mystRoleHtmlExt,l as mystRoleMdastExt,r as mystRoleMmarkExt,t as nodeTypes,e as tokenTypes}; //# sourceMappingURL=index.esm.min.js.map