ll-package
Version:
2 lines (1 loc) • 11 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Ce=require("../../micromark/lib/parse.js"),Pe=require("../../micromark/lib/preprocess.js"),Re=require("../../micromark/lib/postprocess.js"),ze=require("../../micromark-util-decode-numeric-character-reference/index.js"),qe=require("../../micromark-util-decode-string/index.js"),F=require("../../micromark-util-normalize-identifier/index.js"),He=require("../../decode-named-character-reference/index.dom.js"),T=require("../../unist-util-stringify-position/lib/index.js"),Le=require("../../mdast-util-to-string/lib/index.js"),V={}.hasOwnProperty,Oe=function(d,r,c){return typeof r!="string"&&(c=r,r=void 0),De(c)(Re.postprocess(Ce.parse(c).document().write(Pe.preprocess()(d,r,!0))))};function De(d){const r={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:a(O),autolinkProtocol:k,autolinkEmail:k,atxHeading:a(q),blockQuote:a(xe),characterEscape:k,characterReference:k,codeFenced:a(z),codeFencedFenceInfo:f,codeFencedFenceMeta:f,codeIndented:a(z,f),codeText:a(ye,f),codeTextData:k,data:k,codeFlowValue:k,definition:a(Se),definitionDestinationString:f,definitionLabelString:f,definitionTitleString:f,emphasis:a(be),hardBreakEscape:a(H),hardBreakTrailing:a(H),htmlFlow:a(L,f),htmlFlowData:k,htmlText:a(L,f),htmlTextData:k,image:a(Ie),label:f,link:a(O),listItem:a(we),listItemValue:N,listOrdered:a(D,j),listUnordered:a(D),paragraph:a(Te),reference:fe,referenceString:f,resourceDestinationString:f,resourceTitleString:f,setextHeading:a(q),strong:a(Ee),thematicBreak:a(Be)},exit:{atxHeading:o(),atxHeadingSequence:Z,autolink:o(),autolinkEmail:me,autolinkProtocol:ke,blockQuote:o(),characterEscapeValue:m,characterReferenceMarkerHexadecimal:R,characterReferenceMarkerNumeric:R,characterReferenceValue:ge,codeFenced:o(G),codeFencedFence:W,codeFencedFenceInfo:U,codeFencedFenceMeta:A,codeFlowValue:m,codeIndented:o(J),codeText:o(se),codeTextData:m,data:m,definition:o(),definitionDestinationString:Y,definitionLabelString:K,definitionTitleString:X,emphasis:o(),hardBreakEscape:o(P),hardBreakTrailing:o(P),htmlFlow:o(ie),htmlFlowData:m,htmlText:o(re),htmlTextData:m,image:o(ae),label:le,labelText:oe,lineEnding:ne,link:o(ce),listItem:o(),listOrdered:o(),listUnordered:o(),paragraph:o(),referenceString:pe,resourceDestinationString:de,resourceTitleString:ue,resource:he,setextHeading:o(te),setextHeadingLineSequence:ee,setextHeadingText:v,strong:o(),thematicBreak:o()}};Q(r,(d||{}).mdastExtensions||[]);const c={};return h;function h(e){let t={type:"root",children:[]};const n={stack:[t],tokenStack:[],config:r,enter:B,exit:C,buffer:f,resume:$,setData:u,getData:g},i=[];let s=-1;for(;++s<e.length;)if(e[s][1].type==="listOrdered"||e[s][1].type==="listUnordered")if(e[s][0]==="enter")i.push(s);else{const p=i.pop();s=_(e,p,s)}for(s=-1;++s<e.length;){const p=r[e[s][0]];V.call(p,e[s][1].type)&&p[e[s][1].type].call(Object.assign({sliceSerialize:e[s][2].sliceSerialize},n),e[s][1])}if(n.tokenStack.length>0){const p=n.tokenStack[n.tokenStack.length-1];(p[1]||M).call(n,void 0,p[0])}for(t.position={start:b(e.length>0?e[0][1].start:{line:1,column:1,offset:0}),end:b(e.length>0?e[e.length-2][1].end:{line:1,column:1,offset:0})},s=-1;++s<r.transforms.length;)t=r.transforms[s](t)||t;return t}function _(e,t,n){let i=t-1,s=-1,p=!1,S,x,I,w;for(;++i<=n;){const l=e[i];if(l[1].type==="listUnordered"||l[1].type==="listOrdered"||l[1].type==="blockQuote"?(l[0]==="enter"?s++:s--,w=void 0):l[1].type==="lineEndingBlank"?l[0]==="enter"&&(S&&!w&&!s&&!I&&(I=i),w=void 0):l[1].type==="linePrefix"||l[1].type==="listItemValue"||l[1].type==="listItemMarker"||l[1].type==="listItemPrefix"||l[1].type==="listItemPrefixWhitespace"||(w=void 0),!s&&l[0]==="enter"&&l[1].type==="listItemPrefix"||s===-1&&l[0]==="exit"&&(l[1].type==="listUnordered"||l[1].type==="listOrdered")){if(S){let E=i;for(x=void 0;E--;){const y=e[E];if(y[1].type==="lineEnding"||y[1].type==="lineEndingBlank"){if(y[0]==="exit")continue;x&&(e[x][1].type="lineEndingBlank",p=!0),y[1].type="lineEnding",x=E}else if(!(y[1].type==="linePrefix"||y[1].type==="blockQuotePrefix"||y[1].type==="blockQuotePrefixWhitespace"||y[1].type==="blockQuoteMarker"||y[1].type==="listItemIndent"))break}I&&(!x||I<x)&&(S._spread=!0),S.end=Object.assign({},x?e[x][1].start:l[1].end),e.splice(x||i,0,["exit",S,l[2]]),i++,n++}l[1].type==="listItemPrefix"&&(S={type:"listItem",_spread:!1,start:Object.assign({},l[1].start),end:void 0},e.splice(i,0,["enter",S,l[2]]),i++,n++,I=void 0,w=!0)}}return e[t][1]._spread=p,n}function u(e,t){c[e]=t}function g(e){return c[e]}function a(e,t){return n;function n(i){B.call(this,e(i),i),t&&t.call(this,i)}}function f(){this.stack.push({type:"fragment",children:[]})}function B(e,t,n){return this.stack[this.stack.length-1].children.push(e),this.stack.push(e),this.tokenStack.push([t,n]),e.position={start:b(t.start)},e}function o(e){return t;function t(n){e&&e.call(this,n),C.call(this,n)}}function C(e,t){const n=this.stack.pop(),i=this.tokenStack.pop();if(i)i[0].type!==e.type&&(t?t.call(this,e,i[0]):(i[1]||M).call(this,e,i[0]));else throw new Error("Cannot close `"+e.type+"` ("+T.stringifyPosition({start:e.start,end:e.end})+"): it’s not open");return n.position.end=b(e.end),n}function $(){return Le.toString(this.stack.pop())}function j(){u("expectingFirstListItemValue",!0)}function N(e){if(g("expectingFirstListItemValue")){const t=this.stack[this.stack.length-2];t.start=Number.parseInt(this.sliceSerialize(e),10),u("expectingFirstListItemValue")}}function U(){const e=this.resume(),t=this.stack[this.stack.length-1];t.lang=e}function A(){const e=this.resume(),t=this.stack[this.stack.length-1];t.meta=e}function W(){g("flowCodeInside")||(this.buffer(),u("flowCodeInside",!0))}function G(){const e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),u("flowCodeInside")}function J(){const e=this.resume(),t=this.stack[this.stack.length-1];t.value=e.replace(/(\r?\n|\r)$/g,"")}function K(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=F.normalizeIdentifier(this.sliceSerialize(e)).toLowerCase()}function X(){const e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function Y(){const e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function Z(e){const t=this.stack[this.stack.length-1];if(!t.depth){const n=this.sliceSerialize(e).length;t.depth=n}}function v(){u("setextHeadingSlurpLineEnding",!0)}function ee(e){const t=this.stack[this.stack.length-1];t.depth=this.sliceSerialize(e).charCodeAt(0)===61?1:2}function te(){u("setextHeadingSlurpLineEnding")}function k(e){const t=this.stack[this.stack.length-1];let n=t.children[t.children.length-1];(!n||n.type!=="text")&&(n=Fe(),n.position={start:b(e.start)},t.children.push(n)),this.stack.push(n)}function m(e){const t=this.stack.pop();t.value+=this.sliceSerialize(e),t.position.end=b(e.end)}function ne(e){const t=this.stack[this.stack.length-1];if(g("atHardBreak")){const n=t.children[t.children.length-1];n.position.end=b(e.end),u("atHardBreak");return}!g("setextHeadingSlurpLineEnding")&&r.canContainEols.includes(t.type)&&(k.call(this,e),m.call(this,e))}function P(){u("atHardBreak",!0)}function ie(){const e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function re(){const e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function se(){const e=this.resume(),t=this.stack[this.stack.length-1];t.value=e}function ce(){const e=this.stack[this.stack.length-1];if(g("inReference")){const t=g("referenceType")||"shortcut";e.type+="Reference",e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;u("referenceType")}function ae(){const e=this.stack[this.stack.length-1];if(g("inReference")){const t=g("referenceType")||"shortcut";e.type+="Reference",e.referenceType=t,delete e.url,delete e.title}else delete e.identifier,delete e.label;u("referenceType")}function oe(e){const t=this.sliceSerialize(e),n=this.stack[this.stack.length-2];n.label=qe.decodeString(t),n.identifier=F.normalizeIdentifier(t).toLowerCase()}function le(){const e=this.stack[this.stack.length-1],t=this.resume(),n=this.stack[this.stack.length-1];if(u("inReference",!0),n.type==="link"){const i=e.children;n.children=i}else n.alt=t}function de(){const e=this.resume(),t=this.stack[this.stack.length-1];t.url=e}function ue(){const e=this.resume(),t=this.stack[this.stack.length-1];t.title=e}function he(){u("inReference")}function fe(){u("referenceType","collapsed")}function pe(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.label=t,n.identifier=F.normalizeIdentifier(this.sliceSerialize(e)).toLowerCase(),u("referenceType","full")}function R(e){u("characterReferenceType",e.type)}function ge(e){const t=this.sliceSerialize(e),n=g("characterReferenceType");let i;n?(i=ze.decodeNumericCharacterReference(t,n==="characterReferenceMarkerNumeric"?10:16),u("characterReferenceType")):i=He.decodeNamedCharacterReference(t);const s=this.stack.pop();s.value+=i,s.position.end=b(e.end)}function ke(e){m.call(this,e);const t=this.stack[this.stack.length-1];t.url=this.sliceSerialize(e)}function me(e){m.call(this,e);const t=this.stack[this.stack.length-1];t.url="mailto:"+this.sliceSerialize(e)}function xe(){return{type:"blockquote",children:[]}}function z(){return{type:"code",lang:null,meta:null,value:""}}function ye(){return{type:"inlineCode",value:""}}function Se(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function be(){return{type:"emphasis",children:[]}}function q(){return{type:"heading",depth:void 0,children:[]}}function H(){return{type:"break"}}function L(){return{type:"html",value:""}}function Ie(){return{type:"image",title:null,url:"",alt:null}}function O(){return{type:"link",title:null,url:"",children:[]}}function D(e){return{type:"list",ordered:e.type==="listOrdered",start:null,spread:e._spread,children:[]}}function we(e){return{type:"listItem",spread:e._spread,checked:null,children:[]}}function Te(){return{type:"paragraph",children:[]}}function Ee(){return{type:"strong",children:[]}}function Fe(){return{type:"text",value:""}}function Be(){return{type:"thematicBreak"}}}function b(d){return{line:d.line,column:d.column,offset:d.offset}}function Q(d,r){let c=-1;for(;++c<r.length;){const h=r[c];Array.isArray(h)?Q(d,h):Me(d,h)}}function Me(d,r){let c;for(c in r)if(V.call(r,c)){if(c==="canContainEols"){const h=r[c];h&&d[c].push(...h)}else if(c==="transforms"){const h=r[c];h&&d[c].push(...h)}else if(c==="enter"||c==="exit"){const h=r[c];h&&Object.assign(d[c],h)}}}function M(d,r){throw d?new Error("Cannot close `"+d.type+"` ("+T.stringifyPosition({start:d.start,end:d.end})+"): a different token (`"+r.type+"`, "+T.stringifyPosition({start:r.start,end:r.end})+") is open"):new Error("Cannot close document, a token (`"+r.type+"`, "+T.stringifyPosition({start:r.start,end:r.end})+") is still open")}exports.fromMarkdown=Oe;