@isdk/mdast-plus 0.1.3 → 0.2.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/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var t,e=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,a=(t,e,s,a)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let u of n(e))o.call(t,u)||u===s||r(t,u,{get:()=>e[u],enumerable:!(a=i(e,u))||a.enumerable});return t},u=(t,i,n)=>(n=null!=t?e(s(t)):{},a(!i&&t&&t.__esModule?n:r(n,"default",{value:t,enumerable:!0}),t)),l={};((t,e)=>{for(var i in e)r(t,i,{get:e[i],enumerable:!0})})(l,{DefaultPipelineStage:()=>c,MdastBasePipeline:()=>Q,MdastPipeline:()=>U,PipelineStage:()=>p,astCompiler:()=>_,astFormat:()=>J,htmlFormat:()=>V,jsonParser:()=>G,markdownFormat:()=>$,mdast:()=>W}),module.exports=(t=l,a(r({},"__esModule",{value:!0}),t));var p=(t=>(t[t.parse=0]="parse",t[t.normalize=100]="normalize",t[t.compile=200]="compile",t[t.finalize=300]="finalize",t[t.stringify=400]="stringify",t))(p||{}),c=200,g=require("unified"),h=require("vfile"),m=u(require("remark-parse")),f=u(require("remark-stringify")),d=u(require("remark-gfm")),y=u(require("remark-directive")),w=u(require("remark-math")),v=u(require("remark-frontmatter")),k=require("unist-util-visit");function b(t,e){return{type:t,children:e,data:{hName:t}}}var q={mark:(t,e,r)=>"=="+r.containerPhrasing(t,{before:"==",after:"=="})+"==",sub:(t,e,r)=>"~"+r.containerPhrasing(t,{before:"~",after:"~"})+"~",sup:(t,e,r)=>"^"+r.containerPhrasing(t,{before:"^",after:"^"})+"^"},M={plugin:()=>t=>{!function(t){(0,k.visit)(t,"text",(t,e,r)=>{if(!r||void 0===e)return;const i=t.value;let n=0;const s=[];let o=!1;const a=/(==[^=]+==|~[^~]+~|\^[^^]+\^)/g;let u;for(;null!==(u=a.exec(i));){o=!0;const t=u[0],e=u.index;e>n&&s.push({type:"text",value:i.slice(n,e)});let r="mark",l="";t.startsWith("==")?(r="mark",l=t.slice(2,-2)):t.startsWith("~")?(r="sub",l=t.slice(1,-1)):t.startsWith("^")&&(r="sup",l=t.slice(1,-1)),s.push(b(r,[{type:"text",value:l}])),n=a.lastIndex}return o?(n<i.length&&s.push({type:"text",value:i.slice(n)}),r.children.splice(e,1,...s),e+s.length):void 0})}(t)},stage:100},x=require("unist-util-visit"),F={error:"danger",warn:"warning",success:"tip",important:"important",caution:"caution",note:"note"},S={plugin:()=>async t=>{(0,x.visit)(t,["containerDirective","leafDirective","textDirective"],t=>{const e=t,r=e.name.toLowerCase();if(e.name=F[r]||r,e.children&&e.children.length>0){const t=e.children[0];if(t.data?.directiveLabel||"directiveLabel"===t.type){const r=t;let i="";(0,x.visit)(r,"text",t=>{i+=t.value}),i&&!e.attributes?.title&&(e.attributes=e.attributes||{},e.attributes.title=i.trim()),e.children.shift()}}e.attributes?.title&&(e.attributes.title=String(e.attributes.title).trim()),e.data=e.data||{},e.data.hName=e.data.hName||("containerDirective"===e.type?"div":"span"),e.data.hProperties={...e.data.hProperties||{},...e.attributes,className:[e.name,e.data.hProperties?.className].filter(Boolean).join(" ")}})},stage:100,order:10},P=require("unist-util-visit"),j={plugin:()=>async t=>{(0,P.visit)(t,"tableCell",t=>{if(t.data){const{rowspan:e,colspan:r}=t.data;t.data.hProperties=t.data.hProperties||{},void 0!==e&&(t.data.hProperties.rowSpan=e,delete t.data.rowspan),void 0!==r&&(t.data.hProperties.colSpan=r,delete t.data.colspan)}})},stage:100,order:20},T=require("unist-util-visit"),D=require("shell-quote");var O={plugin:()=>async t=>{(0,T.visit)(t,"code",t=>{if(t.meta){const e=function(t){const e={},r=(0,D.parse)(t);for(const t of r)if("string"==typeof t){const r=t.split("=",2);2===r.length?e[r[0]]=r[1]:e[t]="true"}return e}(t.meta),r=t.data=t.data||{};e.title&&(r.title=e.title),e.filename&&(r.filename=e.filename),r.kv={...r.kv||{},...e}}})},stage:100,order:30},A=require("unist-util-visit"),N={plugin:()=>async t=>{(0,A.visit)(t,"image",t=>{const e=t.data=t.data||{},r=e.hProperties=e.hProperties||{},i=/[#?&](?:width=([0-9]+))?(?:&?height=([0-9]+))?(?:=([0-9]+)x([0-9]+))?$/,n=t.url.match(i);if(n){const e=n[1]||n[3],s=n[2]||n[4];e&&!r.width&&(r.width=parseInt(e,10)),s&&!r.height&&(r.height=parseInt(s,10)),t.url=t.url.replace(i,"")}e.width&&!r.width&&(r.width=e.width),e.height&&!r.height&&(r.height=e.height)})},stage:100,order:40},E=[{plugin:m.default,stage:0},{plugin:d.default,options:[{singleTilde:!1}],stage:0},{plugin:y.default,stage:0},{plugin:w.default,stage:0},{plugin:v.default,options:[["yaml","toml"]],stage:0},S,j,O,N,M],H=[{plugin:f.default,options:[{handlers:q}],stage:400},{plugin:d.default,options:[{singleTilde:!1}],stage:400},{plugin:y.default,stage:400},{plugin:w.default,stage:400},{plugin:v.default,options:[["yaml","toml"]],stage:400}];H.forEach(t=>{t.plugin===f.default?t.order=100:t.order=10});var $={id:"markdown",title:"Markdown (GFM + Directives)",extensions:["md","markdown","mdown","mkdn"],mediaTypes:["text/markdown"],input:E,output:H},z=u(require("rehype-parse")),B=u(require("rehype-remark")),I=u(require("remark-rehype")),L=u(require("rehype-sanitize")),C=u(require("rehype-stringify")),V={id:"html",title:"HTML",extensions:["html","htm"],mediaTypes:["text/html"],input:[{plugin:z.default,stage:0},{plugin:B.default,options:[{handlers:{mark:(t,e)=>{const r={type:"mark",children:t.all(e)};return t.patch(e,r),r},sub:(t,e)=>{const r={type:"sub",children:t.all(e)};return t.patch(e,r),r},sup:(t,e)=>{const r={type:"sup",children:t.all(e)};return t.patch(e,r),r}}}],stage:0,order:10}],output:[{plugin:I.default,stage:300,order:10},{plugin:L.default,options:[{...L.defaultSchema,tagNames:[...L.defaultSchema.tagNames||[],"mark","sub","sup"],attributes:{...L.defaultSchema.attributes,"*":[...L.defaultSchema.attributes?.["*"]||[],"className","id","style"],td:[...L.defaultSchema.attributes?.td||[],"rowSpan","colSpan","rowspan","colspan"],th:[...L.defaultSchema.attributes?.th||[],"rowSpan","colSpan","rowspan","colspan"],img:[...L.defaultSchema.attributes?.img||[],"width","height"]}}],stage:300,order:20},{plugin:C.default,stage:400}]};function _(){this.Compiler=t=>t}function G(){this.Parser=t=>JSON.parse(t)}var J={id:"ast",title:"MDAST",input:[{plugin:G,stage:0},S,j,O,N,M],output:[{plugin:_,options:[],stage:400}]};function R(t){return"object"==typeof t&&null!==t&&"string"==typeof t.type}var K=class t{constructor(t){this.queue=[],this.input=t}static register(t){this.registry.set(t.id,t)}static getFormat(t){return this.registry.get(t)}getFormat(t){return this.constructor.getFormat(t)}resolveFormat(t){if("string"==typeof t){const e=this.getFormat(t);if(!e)throw new Error(`[MdastPlus] Format '${t}' is not registered.`);return e}return t}toRuntimeEntry(t,e,r){let i=e;void 0!==t.stage&&(i="string"==typeof t.stage?p[t.stage]??e:t.stage);let n=t.options||[];const s=t.name||t.plugin.name;if(r&&s&&s in r){const t=r[s];n=Array.isArray(t)?t:[t]}return{name:s,plugin:t.plugin,options:n,stage:i,order:t.order||0}}ensureInputPlugins(e,r,i=400){const n=e.some(t=>0===(t.stage??c)),s=R(this.input);if(!n){let n=[];if(s){const e=t.getFormat("ast");e&&e.input&&(n=e.input)}else{const e=t.getFormat("markdown");e&&e.input&&(n=e.input)}for(const t of n){const n=this.toRuntimeEntry(t,0,r);(n.stage??c)<=i&&e.push(n)}}}from(t,e){const r=this.resolveFormat(t);if(!r.input||0===r.input.length)throw new Error(`[MdastPlus] Format '${r.id}' does not support input.`);for(const t of r.input)this.queue.push(this.toRuntimeEntry(t,0,e));return this}async to(t,e){const r=this.resolveFormat(t);if(!r.output)throw new Error(`[MdastPlus] Format '${r.id}' does not support output.`);const i=[...this.queue];this.ensureInputPlugins(i,e);for(const t of r.output)i.push(this.toRuntimeEntry(t,300,e));const n=this.assembleProcessor(i);if(R(this.input)){const t=await n.run(this.input),e=n.stringify(t),r=new h.VFile;return"string"==typeof e||Buffer.isBuffer(e)?r.value=e:r.result=e,r}return n.process(this.input)}use(t,...e){return this.useAt("compile",t,...e)}useAt(t,e,...r){return this.queue.push({plugin:e,options:r,stage:p[t],order:0}),this}priority(t){const e=this.queue[this.queue.length-1];return e&&(e.order=t),this}assembleProcessor(t){t.sort((t,e)=>{const r=t.stage??c,i=e.stage??c;return r!==i?r-i:t.order-e.order});const e=(0,g.unified)();for(const r of t)e.use(r.plugin,...r.options||[]);return e}};K.registry=new Map;var Q=K,U=class extends Q{async toMarkdown(){const t=await this.to("markdown");return String(t)}toMarkdownVFile(){return this.to("markdown")}async toHtml(){const t=await this.to("html");return String(t)}toHtmlVFile(){return this.to("html")}async toAst(t){if(t?.stage){const e=p[t.stage],r=this.queue.filter(t=>(t.stage??c)<=e);r.push({plugin:_,options:[],stage:400,order:0}),this.ensureInputPlugins(r,t.overrides,e);const i=this.assembleProcessor(r);if(R(this.input)){return await i.run(this.input)}return(await i.process(this.input)).result}return(await this.to("ast",t?.overrides)).result}toHTML(){return this.toHtml()}toAST(t){return this.toAst(t)}};function W(t){return new U(t)}U.register($),U.register(V),U.register(J);
1
+ "use strict";var t,e=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,a=(t,e,s,a)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let u of n(e))o.call(t,u)||u===s||r(t,u,{get:()=>e[u],enumerable:!(a=i(e,u))||a.enumerable});return t},u=(t,i,n)=>(n=null!=t?e(s(t)):{},a(!i&&t&&t.__esModule?n:r(n,"default",{value:t,enumerable:!0}),t)),l={};((t,e)=>{for(var i in e)r(t,i,{get:e[i],enumerable:!0})})(l,{DefaultPipelineStage:()=>p,MdastBasePipeline:()=>Q,MdastPipeline:()=>U,PipelineStage:()=>c,astCompiler:()=>V,astFormat:()=>G,htmlFormat:()=>C,htmlReadability:()=>Y,htmlReadabilityPlugin:()=>Z,htmlReadabilityPlugins:()=>et,jsonParser:()=>_,markdownFormat:()=>R,mdast:()=>W,restoreReadabilityMetaPlugin:()=>tt}),module.exports=(t=l,a(r({},"__esModule",{value:!0}),t));var c=(t=>(t[t.parse=0]="parse",t[t.normalize=100]="normalize",t[t.compile=200]="compile",t[t.finalize=300]="finalize",t[t.stringify=400]="stringify",t))(c||{}),p=200,f=require("unified"),h=require("vfile"),m=u(require("remark-parse")),g=u(require("remark-stringify")),d=u(require("remark-gfm")),y=u(require("remark-directive")),b=u(require("remark-math")),w=u(require("remark-frontmatter")),v=require("unist-util-visit");function k(t,e){return{type:t,children:e,data:{hName:t}}}var q={mark:(t,e,r)=>"=="+r.containerPhrasing(t,{before:"==",after:"=="})+"==",sub:(t,e,r)=>"~"+r.containerPhrasing(t,{before:"~",after:"~"})+"~",sup:(t,e,r)=>"^"+r.containerPhrasing(t,{before:"^",after:"^"})+"^"},j={plugin:()=>t=>{!function(t){(0,v.visit)(t,"text",(t,e,r)=>{if(!r||void 0===e)return;const i=t.value;let n=0;const s=[];let o=!1;const a=/(==[^=]+==|~[^~]+~|\^[^^]+\^)/g;let u;for(;null!==(u=a.exec(i));){o=!0;const t=u[0],e=u.index;e>n&&s.push({type:"text",value:i.slice(n,e)});let r="mark",l="";t.startsWith("==")?(r="mark",l=t.slice(2,-2)):t.startsWith("~")?(r="sub",l=t.slice(1,-1)):t.startsWith("^")&&(r="sup",l=t.slice(1,-1)),s.push(k(r,[{type:"text",value:l}])),n=a.lastIndex}return o?(n<i.length&&s.push({type:"text",value:i.slice(n)}),r.children.splice(e,1,...s),e+s.length):void 0})}(t)},stage:100},M=require("unist-util-visit"),P={error:"danger",warn:"warning",success:"tip",important:"important",caution:"caution",note:"note"},x={plugin:()=>async t=>{(0,M.visit)(t,["containerDirective","leafDirective","textDirective"],t=>{const e=t,r=e.name.toLowerCase();if(e.name=P[r]||r,e.children&&e.children.length>0){const t=e.children[0];if(t.data?.directiveLabel||"directiveLabel"===t.type){const r=t;let i="";(0,M.visit)(r,"text",t=>{i+=t.value}),i&&!e.attributes?.title&&(e.attributes=e.attributes||{},e.attributes.title=i.trim()),e.children.shift()}}e.attributes?.title&&(e.attributes.title=String(e.attributes.title).trim()),e.data=e.data||{},e.data.hName=e.data.hName||("containerDirective"===e.type?"div":"span"),e.data.hProperties={...e.data.hProperties||{},...e.attributes,className:[e.name,e.data.hProperties?.className].filter(Boolean).join(" ")}})},stage:100,order:10},F=require("unist-util-visit"),S={plugin:()=>async t=>{(0,F.visit)(t,"tableCell",t=>{if(t.data){const{rowspan:e,colspan:r}=t.data;t.data.hProperties=t.data.hProperties||{},void 0!==e&&(t.data.hProperties.rowSpan=e,delete t.data.rowspan),void 0!==r&&(t.data.hProperties.colSpan=r,delete t.data.colspan)}})},stage:100,order:20},O=require("unist-util-visit"),A=require("shell-quote");var D={plugin:()=>async t=>{(0,O.visit)(t,"code",t=>{if(t.meta){const e=function(t){const e={},r=(0,A.parse)(t);for(const t of r)if("string"==typeof t){const r=t.split("=",2);2===r.length?e[r[0]]=r[1]:e[t]="true"}return e}(t.meta),r=t.data=t.data||{};e.title&&(r.title=e.title),e.filename&&(r.filename=e.filename),r.kv={...r.kv||{},...e}}})},stage:100,order:30},T=require("unist-util-visit"),N={plugin:()=>async t=>{(0,T.visit)(t,"image",t=>{const e=t.data=t.data||{},r=e.hProperties=e.hProperties||{},i=/[#?&](?:width=([0-9]+))?(?:&?height=([0-9]+))?(?:=([0-9]+)x([0-9]+))?$/,n=t.url.match(i);if(n){const e=n[1]||n[3],s=n[2]||n[4];e&&!r.width&&(r.width=parseInt(e,10)),s&&!r.height&&(r.height=parseInt(s,10)),t.url=t.url.replace(i,"")}e.width&&!r.width&&(r.width=e.width),e.height&&!r.height&&(r.height=e.height)})},stage:100,order:40},z=[{plugin:m.default,stage:0},{plugin:d.default,options:[{singleTilde:!1}],stage:0},{plugin:y.default,stage:0},{plugin:b.default,stage:0},{plugin:w.default,options:[["yaml","toml"]],stage:0},x,S,D,N,j],E=[{plugin:g.default,options:[{handlers:q}],stage:400},{plugin:d.default,options:[{singleTilde:!1}],stage:400},{plugin:y.default,stage:400},{plugin:b.default,stage:400},{plugin:w.default,options:[["yaml","toml"]],stage:400}];E.forEach(t=>{t.plugin===g.default?t.order=100:t.order=10});var R={id:"markdown",title:"Markdown (GFM + Directives)",extensions:["md","markdown","mdown","mkdn"],mediaTypes:["text/markdown"],input:z,output:E},H=u(require("rehype-parse")),$=u(require("rehype-remark")),B=u(require("remark-rehype")),I=u(require("rehype-sanitize")),L=u(require("rehype-stringify")),C={id:"html",title:"HTML",extensions:["html","htm"],mediaTypes:["text/html"],input:[{name:"rehype-parse",plugin:H.default,stage:0},{name:"rehype-remark",plugin:$.default,options:[{handlers:{mark:(t,e)=>{const r={type:"mark",children:t.all(e)};return t.patch(e,r),r},sub:(t,e)=>{const r={type:"sub",children:t.all(e)};return t.patch(e,r),r},sup:(t,e)=>{const r={type:"sup",children:t.all(e)};return t.patch(e,r),r}}}],stage:0}],output:[{plugin:B.default,stage:300,order:10},{plugin:I.default,options:[{...I.defaultSchema,tagNames:[...I.defaultSchema.tagNames||[],"mark","sub","sup"],attributes:{...I.defaultSchema.attributes,"*":[...I.defaultSchema.attributes?.["*"]||[],"className","id","style"],td:[...I.defaultSchema.attributes?.td||[],"rowSpan","colSpan","rowspan","colspan"],th:[...I.defaultSchema.attributes?.th||[],"rowSpan","colSpan","rowspan","colspan"],img:[...I.defaultSchema.attributes?.img||[],"width","height"]}}],stage:300,order:20},{plugin:L.default,stage:400}]};function V(){this.Compiler=t=>t}function _(){this.Parser=t=>JSON.parse(t)}var G={id:"ast",title:"MDAST",input:[{plugin:_,stage:0},x,S,D,N,j],output:[{plugin:V,options:[],stage:400}]};function J(t){return"object"==typeof t&&null!==t&&"string"==typeof t.type}var K=class t{constructor(t){this.queue=[],this._data={},this.input=t}static register(t){this.registry.set(t.id,t)}static getFormat(t){return this.registry.get(t)}data(t,e){return"string"==typeof t?this._data[t]=e:Object.assign(this._data,t),this}getFormat(t){return this.constructor.getFormat(t)}resolveFormat(t){if("string"==typeof t){const e=this.getFormat(t);if(!e)throw new Error(`[MdastPlus] Format '${t}' is not registered.`);return e}return t}toRuntimeEntry(t,e,r){let i=e;void 0!==t.stage&&(i="string"==typeof t.stage?c[t.stage]??e:t.stage);let n=t.options||[];const s=t.name||t.plugin.name;if(r&&s&&s in r){const e=r[s];"object"!=typeof e||null===e||Array.isArray(e)?n=Array.isArray(e)?e:[e]:("main"in e&&(t.main=!!e.main),"before"in e&&(t.before=e.before),"after"in e&&(t.after=e.after),n=[e])}return{name:s,plugin:t.plugin,options:n,stage:i,order:t.order||0,main:t.main,before:t.before,after:t.after}}ensureInputPlugins(e,r,i=400){const n=e.some(t=>0===(t.stage??p)),s=J(this.input);if(!n){let n=[];if(s){const e=t.getFormat("ast");e&&e.input&&(n=e.input)}else{const e=t.getFormat("markdown");e&&e.input&&(n=e.input)}for(const t of n){const n=this.toRuntimeEntry(t,0,r);(n.stage??p)<=i&&e.push(n)}}}from(t,e){const r=this.resolveFormat(t);if(!r.input||0===r.input.length)throw new Error(`[MdastPlus] Format '${r.id}' does not support input.`);for(const t of r.input)this.queue.push(this.toRuntimeEntry(t,0,e));return this}async to(t,e){const r=this.resolveFormat(t);if(!r.output)throw new Error(`[MdastPlus] Format '${r.id}' does not support output.`);const i=[...this.queue];this.ensureInputPlugins(i,e);for(const t of r.output)i.push(this.toRuntimeEntry(t,300,e));const n=this.assembleProcessor(i);if(J(this.input)){const t=await n.run(this.input),e=n.stringify(t),r=new h.VFile;return"string"==typeof e||Buffer.isBuffer(e)?r.value=e:r.result=e,r}return n.process(this.input)}use(t,...e){return this.useAt("compile",t,...e)}useAt(t,e,...r){if(Array.isArray(t)){for(const i of t)this.useAt(i,e,...r);return this}if(Array.isArray(e)){for(const i of e)this.useAt(t,i,...r);return this}if("object"==typeof t&&null!==t&&"plugin"in t){const i=t,n=void 0!==i.stage?"string"==typeof i.stage?i.stage:c[i.stage]:"compile",s=void 0!==e?[e,...r]:i.options;this.queue.push(this.toRuntimeEntry({...i,options:s},c[n]))}else{const i=t;if("object"==typeof e&&null!==e&&"plugin"in e){const t=e,n=r.length>0?r:t.options;this.queue.push(this.toRuntimeEntry({...t,options:n},c[i]))}else e&&this.queue.push({plugin:e,options:r,stage:c[i],order:0})}return this}priority(t){const e=this.queue[this.queue.length-1];return e&&(e.order=t),this}assembleProcessor(t){const e={};for(const r of t){const t=r.stage??p;e[t]||(e[t]=[]),e[t].push(r)}const r=[],i=Object.keys(e).map(Number).sort((t,e)=>t-e);for(const t of i){const i=e[t].sort((t,e)=>(t.order||0)-(e.order||0)),n=i.findIndex(t=>t.main);if(-1!==n){const t=i[n];i.splice(n,1),i[0]=t}let s=!0,o=0;for(;s&&o<i.length;){s=!1,o++;for(let t=0;t<i.length;t++){const e=i[t];if(e.after){const r=i.findIndex(t=>t.name===e.after);if(-1!==r&&r>t){i.splice(t,1),i.splice(r,0,e),s=!0;break}}if(e.before){const r=i.findIndex(t=>t.name===e.before);if(-1!==r&&r<t){i.splice(t,1),i.splice(r,0,e),s=!0;break}}}}r.push(...i)}const n=(0,f.unified)();Object.keys(this._data).length>0&&n.data(this._data);for(const t of r)n.use(t.plugin,...t.options||[]);return n}};K.registry=new Map;var Q=K,U=class extends Q{async toMarkdown(){const t=await this.to("markdown");return String(t)}toMarkdownVFile(){return this.to("markdown")}async toHtml(){const t=await this.to("html");return String(t)}toHtmlVFile(){return this.to("html")}async toAst(t){if(t?.stage){const e=c[t.stage],r=this.queue.filter(t=>(t.stage??p)<=e);r.push({plugin:V,options:[],stage:400,order:0}),this.ensureInputPlugins(r,t.overrides,e);const i=this.assembleProcessor(r);if(J(this.input)){return await i.run(this.input)}return(await i.process(this.input)).result}return(await this.to("ast",t?.overrides)).result}toHTML(){return this.toHtml()}toAST(t){return this.toAst(t)}};function W(t){return new U(t)}U.register(R),U.register(C),U.register(G);var X=require("hast-util-from-html"),Y=function(t){let e={};"boolean"==typeof t?e={enable:t}:t&&(e=t);const{enable:r,readability:i,jsdom:n}=e;!1!==r&&(this.parser=function(t,e){let r,s;try{r=require("jsdom").JSDOM;s=require("@mozilla/readability").Readability}catch(t){throw new Error("[html-readability] Dependency missing. Please install 'jsdom' and '@mozilla/readability'.")}const o=new s(new r(t,n).window.document,i).parse();if(!o||!o.content)return(0,X.fromHtml)(t,{fragment:!0});const a=(0,X.fromHtml)(o.content,{fragment:!0}),u={title:o.title,byline:o.byline,excerpt:o.excerpt,siteName:o.siteName,lang:o.lang};return e&&(e.data=e.data||{},e.data.readability=u),a&&(a.data=a.data||{},a.data.readability=u),a})},Z={name:"readability",plugin:Y,stage:0},tt={name:"restore-readability-meta",plugin:()=>(t,e)=>{e.data?.readability&&(t.data=t.data||{},t.data.readability=e.data.readability)},stage:0,after:"rehype-remark"},et=[Z,tt];
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var t=(t=>(t[t.parse=0]="parse",t[t.normalize=100]="normalize",t[t.compile=200]="compile",t[t.finalize=300]="finalize",t[t.stringify=400]="stringify",t))(t||{}),r=200;import{unified as i}from"unified";import{VFile as e}from"vfile";import s from"remark-parse";import n from"remark-stringify";import o from"remark-gfm";import a from"remark-directive";import u from"remark-math";import p from"remark-frontmatter";import{visit as l}from"unist-util-visit";function m(t,r){return{type:t,children:r,data:{hName:t}}}var c={plugin:()=>t=>{!function(t){l(t,"text",(t,r,i)=>{if(!i||void 0===r)return;const e=t.value;let s=0;const n=[];let o=!1;const a=/(==[^=]+==|~[^~]+~|\^[^^]+\^)/g;let u;for(;null!==(u=a.exec(e));){o=!0;const t=u[0],r=u.index;r>s&&n.push({type:"text",value:e.slice(s,r)});let i="mark",p="";t.startsWith("==")?(i="mark",p=t.slice(2,-2)):t.startsWith("~")?(i="sub",p=t.slice(1,-1)):t.startsWith("^")&&(i="sup",p=t.slice(1,-1)),n.push(m(i,[{type:"text",value:p}])),s=a.lastIndex}return o?(s<e.length&&n.push({type:"text",value:e.slice(s)}),i.children.splice(r,1,...n),r+n.length):void 0})}(t)},stage:100};import{visit as f}from"unist-util-visit";var g={error:"danger",warn:"warning",success:"tip",important:"important",caution:"caution",note:"note"},h={plugin:()=>async t=>{f(t,["containerDirective","leafDirective","textDirective"],t=>{const r=t,i=r.name.toLowerCase();if(r.name=g[i]||i,r.children&&r.children.length>0){const t=r.children[0];if(t.data?.directiveLabel||"directiveLabel"===t.type){let i="";f(t,"text",t=>{i+=t.value}),i&&!r.attributes?.title&&(r.attributes=r.attributes||{},r.attributes.title=i.trim()),r.children.shift()}}r.attributes?.title&&(r.attributes.title=String(r.attributes.title).trim()),r.data=r.data||{},r.data.hName=r.data.hName||("containerDirective"===r.type?"div":"span"),r.data.hProperties={...r.data.hProperties||{},...r.attributes,className:[r.name,r.data.hProperties?.className].filter(Boolean).join(" ")}})},stage:100,order:10};import{visit as d}from"unist-util-visit";var v={plugin:()=>async t=>{d(t,"tableCell",t=>{if(t.data){const{rowspan:r,colspan:i}=t.data;t.data.hProperties=t.data.hProperties||{},void 0!==r&&(t.data.hProperties.rowSpan=r,delete t.data.rowspan),void 0!==i&&(t.data.hProperties.colSpan=i,delete t.data.colspan)}})},stage:100,order:20};import{visit as y}from"unist-util-visit";import{parse as w}from"shell-quote";var k={plugin:()=>async t=>{y(t,"code",t=>{if(t.meta){const r=function(t){const r={},i=w(t);for(const t of i)if("string"==typeof t){const i=t.split("=",2);2===i.length?r[i[0]]=i[1]:r[t]="true"}return r}(t.meta),i=t.data=t.data||{};r.title&&(i.title=r.title),r.filename&&(i.filename=r.filename),i.kv={...i.kv||{},...r}}})},stage:100,order:30};import{visit as b}from"unist-util-visit";var x={plugin:()=>async t=>{b(t,"image",t=>{const r=t.data=t.data||{},i=r.hProperties=r.hProperties||{},e=/[#?&](?:width=([0-9]+))?(?:&?height=([0-9]+))?(?:=([0-9]+)x([0-9]+))?$/,s=t.url.match(e);if(s){const r=s[1]||s[3],n=s[2]||s[4];r&&!i.width&&(i.width=parseInt(r,10)),n&&!i.height&&(i.height=parseInt(n,10)),t.url=t.url.replace(e,"")}r.width&&!i.width&&(i.width=r.width),r.height&&!i.height&&(i.height=r.height)})},stage:100,order:40},M=[{plugin:s,stage:0},{plugin:o,options:[{singleTilde:!1}],stage:0},{plugin:a,stage:0},{plugin:u,stage:0},{plugin:p,options:[["yaml","toml"]],stage:0},h,v,k,x,c],S=[{plugin:n,options:[{handlers:{mark:(t,r,i)=>"=="+i.containerPhrasing(t,{before:"==",after:"=="})+"==",sub:(t,r,i)=>"~"+i.containerPhrasing(t,{before:"~",after:"~"})+"~",sup:(t,r,i)=>"^"+i.containerPhrasing(t,{before:"^",after:"^"})+"^"}}],stage:400},{plugin:o,options:[{singleTilde:!1}],stage:400},{plugin:a,stage:400},{plugin:u,stage:400},{plugin:p,options:[["yaml","toml"]],stage:400}];S.forEach(t=>{t.plugin===n?t.order=100:t.order=10});var F={id:"markdown",title:"Markdown (GFM + Directives)",extensions:["md","markdown","mdown","mkdn"],mediaTypes:["text/markdown"],input:M,output:S};import T from"rehype-parse";import D from"rehype-remark";import A from"remark-rehype";import N,{defaultSchema as P}from"rehype-sanitize";import E from"rehype-stringify";var H={id:"html",title:"HTML",extensions:["html","htm"],mediaTypes:["text/html"],input:[{plugin:T,stage:0},{plugin:D,options:[{handlers:{mark:(t,r)=>{const i={type:"mark",children:t.all(r)};return t.patch(r,i),i},sub:(t,r)=>{const i={type:"sub",children:t.all(r)};return t.patch(r,i),i},sup:(t,r)=>{const i={type:"sup",children:t.all(r)};return t.patch(r,i),i}}}],stage:0,order:10}],output:[{plugin:A,stage:300,order:10},{plugin:N,options:[{...P,tagNames:[...P.tagNames||[],"mark","sub","sup"],attributes:{...P.attributes,"*":[...P.attributes?.["*"]||[],"className","id","style"],td:[...P.attributes?.td||[],"rowSpan","colSpan","rowspan","colspan"],th:[...P.attributes?.th||[],"rowSpan","colSpan","rowspan","colspan"],img:[...P.attributes?.img||[],"width","height"]}}],stage:300,order:20},{plugin:E,stage:400}]};function $(){this.Compiler=t=>t}function z(){this.Parser=t=>JSON.parse(t)}var I={id:"ast",title:"MDAST",input:[{plugin:z,stage:0},h,v,k,x,c],output:[{plugin:$,options:[],stage:400}]};function L(t){return"object"==typeof t&&null!==t&&"string"==typeof t.type}var B=class s{constructor(t){this.queue=[],this.input=t}static register(t){this.registry.set(t.id,t)}static getFormat(t){return this.registry.get(t)}getFormat(t){return this.constructor.getFormat(t)}resolveFormat(t){if("string"==typeof t){const r=this.getFormat(t);if(!r)throw new Error(`[MdastPlus] Format '${t}' is not registered.`);return r}return t}toRuntimeEntry(r,i,e){let s=i;void 0!==r.stage&&(s="string"==typeof r.stage?t[r.stage]??i:r.stage);let n=r.options||[];const o=r.name||r.plugin.name;if(e&&o&&o in e){const t=e[o];n=Array.isArray(t)?t:[t]}return{name:o,plugin:r.plugin,options:n,stage:s,order:r.order||0}}ensureInputPlugins(t,i,e=400){const n=t.some(t=>0===(t.stage??r)),o=L(this.input);if(!n){let n=[];if(o){const t=s.getFormat("ast");t&&t.input&&(n=t.input)}else{const t=s.getFormat("markdown");t&&t.input&&(n=t.input)}for(const s of n){const n=this.toRuntimeEntry(s,0,i);(n.stage??r)<=e&&t.push(n)}}}from(t,r){const i=this.resolveFormat(t);if(!i.input||0===i.input.length)throw new Error(`[MdastPlus] Format '${i.id}' does not support input.`);for(const t of i.input)this.queue.push(this.toRuntimeEntry(t,0,r));return this}async to(t,r){const i=this.resolveFormat(t);if(!i.output)throw new Error(`[MdastPlus] Format '${i.id}' does not support output.`);const s=[...this.queue];this.ensureInputPlugins(s,r);for(const t of i.output)s.push(this.toRuntimeEntry(t,300,r));const n=this.assembleProcessor(s);if(L(this.input)){const t=await n.run(this.input),r=n.stringify(t),i=new e;return"string"==typeof r||Buffer.isBuffer(r)?i.value=r:i.result=r,i}return n.process(this.input)}use(t,...r){return this.useAt("compile",t,...r)}useAt(r,i,...e){return this.queue.push({plugin:i,options:e,stage:t[r],order:0}),this}priority(t){const r=this.queue[this.queue.length-1];return r&&(r.order=t),this}assembleProcessor(t){t.sort((t,i)=>{const e=t.stage??r,s=i.stage??r;return e!==s?e-s:t.order-i.order});const e=i();for(const r of t)e.use(r.plugin,...r.options||[]);return e}};B.registry=new Map;var V=B,j=class extends V{async toMarkdown(){const t=await this.to("markdown");return String(t)}toMarkdownVFile(){return this.to("markdown")}async toHtml(){const t=await this.to("html");return String(t)}toHtmlVFile(){return this.to("html")}async toAst(i){if(i?.stage){const e=t[i.stage],s=this.queue.filter(t=>(t.stage??r)<=e);s.push({plugin:$,options:[],stage:400,order:0}),this.ensureInputPlugins(s,i.overrides,e);const n=this.assembleProcessor(s);if(L(this.input)){return await n.run(this.input)}return(await n.process(this.input)).result}return(await this.to("ast",i?.overrides)).result}toHTML(){return this.toHtml()}toAST(t){return this.toAst(t)}};function q(t){return new j(t)}j.register(F),j.register(H),j.register(I);export{r as DefaultPipelineStage,V as MdastBasePipeline,j as MdastPipeline,t as PipelineStage,$ as astCompiler,I as astFormat,H as htmlFormat,z as jsonParser,F as markdownFormat,q as mdast};
1
+ var t=(t=>"undefined"!=typeof require?require:"undefined"!=typeof Proxy?new Proxy(t,{get:(t,e)=>("undefined"!=typeof require?require:t)[e]}):t)(function(t){if("undefined"!=typeof require)return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')}),e=(t=>(t[t.parse=0]="parse",t[t.normalize=100]="normalize",t[t.compile=200]="compile",t[t.finalize=300]="finalize",t[t.stringify=400]="stringify",t))(e||{}),r=200;import{unified as i}from"unified";import{VFile as n}from"vfile";import o from"remark-parse";import s from"remark-stringify";import a from"remark-gfm";import u from"remark-directive";import p from"remark-math";import l from"remark-frontmatter";import{visit as f}from"unist-util-visit";function m(t,e){return{type:t,children:e,data:{hName:t}}}var c={plugin:()=>t=>{!function(t){f(t,"text",(t,e,r)=>{if(!r||void 0===e)return;const i=t.value;let n=0;const o=[];let s=!1;const a=/(==[^=]+==|~[^~]+~|\^[^^]+\^)/g;let u;for(;null!==(u=a.exec(i));){s=!0;const t=u[0],e=u.index;e>n&&o.push({type:"text",value:i.slice(n,e)});let r="mark",p="";t.startsWith("==")?(r="mark",p=t.slice(2,-2)):t.startsWith("~")?(r="sub",p=t.slice(1,-1)):t.startsWith("^")&&(r="sup",p=t.slice(1,-1)),o.push(m(r,[{type:"text",value:p}])),n=a.lastIndex}return s?(n<i.length&&o.push({type:"text",value:i.slice(n)}),r.children.splice(e,1,...o),e+o.length):void 0})}(t)},stage:100};import{visit as h}from"unist-util-visit";var g={error:"danger",warn:"warning",success:"tip",important:"important",caution:"caution",note:"note"},d={plugin:()=>async t=>{h(t,["containerDirective","leafDirective","textDirective"],t=>{const e=t,r=e.name.toLowerCase();if(e.name=g[r]||r,e.children&&e.children.length>0){const t=e.children[0];if(t.data?.directiveLabel||"directiveLabel"===t.type){let r="";h(t,"text",t=>{r+=t.value}),r&&!e.attributes?.title&&(e.attributes=e.attributes||{},e.attributes.title=r.trim()),e.children.shift()}}e.attributes?.title&&(e.attributes.title=String(e.attributes.title).trim()),e.data=e.data||{},e.data.hName=e.data.hName||("containerDirective"===e.type?"div":"span"),e.data.hProperties={...e.data.hProperties||{},...e.attributes,className:[e.name,e.data.hProperties?.className].filter(Boolean).join(" ")}})},stage:100,order:10};import{visit as y}from"unist-util-visit";var v={plugin:()=>async t=>{y(t,"tableCell",t=>{if(t.data){const{rowspan:e,colspan:r}=t.data;t.data.hProperties=t.data.hProperties||{},void 0!==e&&(t.data.hProperties.rowSpan=e,delete t.data.rowspan),void 0!==r&&(t.data.hProperties.colSpan=r,delete t.data.colspan)}})},stage:100,order:20};import{visit as w}from"unist-util-visit";import{parse as b}from"shell-quote";var k={plugin:()=>async t=>{w(t,"code",t=>{if(t.meta){const e=function(t){const e={},r=b(t);for(const t of r)if("string"==typeof t){const r=t.split("=",2);2===r.length?e[r[0]]=r[1]:e[t]="true"}return e}(t.meta),r=t.data=t.data||{};e.title&&(r.title=e.title),e.filename&&(r.filename=e.filename),r.kv={...r.kv||{},...e}}})},stage:100,order:30};import{visit as x}from"unist-util-visit";var M={plugin:()=>async t=>{x(t,"image",t=>{const e=t.data=t.data||{},r=e.hProperties=e.hProperties||{},i=/[#?&](?:width=([0-9]+))?(?:&?height=([0-9]+))?(?:=([0-9]+)x([0-9]+))?$/,n=t.url.match(i);if(n){const e=n[1]||n[3],o=n[2]||n[4];e&&!r.width&&(r.width=parseInt(e,10)),o&&!r.height&&(r.height=parseInt(o,10)),t.url=t.url.replace(i,"")}e.width&&!r.width&&(r.width=e.width),e.height&&!r.height&&(r.height=e.height)})},stage:100,order:40},j=[{plugin:o,stage:0},{plugin:a,options:[{singleTilde:!1}],stage:0},{plugin:u,stage:0},{plugin:p,stage:0},{plugin:l,options:[["yaml","toml"]],stage:0},d,v,k,M,c],S=[{plugin:s,options:[{handlers:{mark:(t,e,r)=>"=="+r.containerPhrasing(t,{before:"==",after:"=="})+"==",sub:(t,e,r)=>"~"+r.containerPhrasing(t,{before:"~",after:"~"})+"~",sup:(t,e,r)=>"^"+r.containerPhrasing(t,{before:"^",after:"^"})+"^"}}],stage:400},{plugin:a,options:[{singleTilde:!1}],stage:400},{plugin:u,stage:400},{plugin:p,stage:400},{plugin:l,options:[["yaml","toml"]],stage:400}];S.forEach(t=>{t.plugin===s?t.order=100:t.order=10});var F={id:"markdown",title:"Markdown (GFM + Directives)",extensions:["md","markdown","mdown","mkdn"],mediaTypes:["text/markdown"],input:j,output:S};import q from"rehype-parse";import A from"rehype-remark";import D from"remark-rehype";import P,{defaultSchema as T}from"rehype-sanitize";import N from"rehype-stringify";var E={id:"html",title:"HTML",extensions:["html","htm"],mediaTypes:["text/html"],input:[{name:"rehype-parse",plugin:q,stage:0},{name:"rehype-remark",plugin:A,options:[{handlers:{mark:(t,e)=>{const r={type:"mark",children:t.all(e)};return t.patch(e,r),r},sub:(t,e)=>{const r={type:"sub",children:t.all(e)};return t.patch(e,r),r},sup:(t,e)=>{const r={type:"sup",children:t.all(e)};return t.patch(e,r),r}}}],stage:0}],output:[{plugin:D,stage:300,order:10},{plugin:P,options:[{...T,tagNames:[...T.tagNames||[],"mark","sub","sup"],attributes:{...T.attributes,"*":[...T.attributes?.["*"]||[],"className","id","style"],td:[...T.attributes?.td||[],"rowSpan","colSpan","rowspan","colspan"],th:[...T.attributes?.th||[],"rowSpan","colSpan","rowspan","colspan"],img:[...T.attributes?.img||[],"width","height"]}}],stage:300,order:20},{plugin:N,stage:400}]};function z(){this.Compiler=t=>t}function H(){this.Parser=t=>JSON.parse(t)}var O={id:"ast",title:"MDAST",input:[{plugin:H,stage:0},d,v,k,M,c],output:[{plugin:z,options:[],stage:400}]};function $(t){return"object"==typeof t&&null!==t&&"string"==typeof t.type}var I=class t{constructor(t){this.queue=[],this._data={},this.input=t}static register(t){this.registry.set(t.id,t)}static getFormat(t){return this.registry.get(t)}data(t,e){return"string"==typeof t?this._data[t]=e:Object.assign(this._data,t),this}getFormat(t){return this.constructor.getFormat(t)}resolveFormat(t){if("string"==typeof t){const e=this.getFormat(t);if(!e)throw new Error(`[MdastPlus] Format '${t}' is not registered.`);return e}return t}toRuntimeEntry(t,r,i){let n=r;void 0!==t.stage&&(n="string"==typeof t.stage?e[t.stage]??r:t.stage);let o=t.options||[];const s=t.name||t.plugin.name;if(i&&s&&s in i){const e=i[s];"object"!=typeof e||null===e||Array.isArray(e)?o=Array.isArray(e)?e:[e]:("main"in e&&(t.main=!!e.main),"before"in e&&(t.before=e.before),"after"in e&&(t.after=e.after),o=[e])}return{name:s,plugin:t.plugin,options:o,stage:n,order:t.order||0,main:t.main,before:t.before,after:t.after}}ensureInputPlugins(e,i,n=400){const o=e.some(t=>0===(t.stage??r)),s=$(this.input);if(!o){let o=[];if(s){const e=t.getFormat("ast");e&&e.input&&(o=e.input)}else{const e=t.getFormat("markdown");e&&e.input&&(o=e.input)}for(const t of o){const o=this.toRuntimeEntry(t,0,i);(o.stage??r)<=n&&e.push(o)}}}from(t,e){const r=this.resolveFormat(t);if(!r.input||0===r.input.length)throw new Error(`[MdastPlus] Format '${r.id}' does not support input.`);for(const t of r.input)this.queue.push(this.toRuntimeEntry(t,0,e));return this}async to(t,e){const r=this.resolveFormat(t);if(!r.output)throw new Error(`[MdastPlus] Format '${r.id}' does not support output.`);const i=[...this.queue];this.ensureInputPlugins(i,e);for(const t of r.output)i.push(this.toRuntimeEntry(t,300,e));const o=this.assembleProcessor(i);if($(this.input)){const t=await o.run(this.input),e=o.stringify(t),r=new n;return"string"==typeof e||Buffer.isBuffer(e)?r.value=e:r.result=e,r}return o.process(this.input)}use(t,...e){return this.useAt("compile",t,...e)}useAt(t,r,...i){if(Array.isArray(t)){for(const e of t)this.useAt(e,r,...i);return this}if(Array.isArray(r)){for(const e of r)this.useAt(t,e,...i);return this}if("object"==typeof t&&null!==t&&"plugin"in t){const n=t,o=void 0!==n.stage?"string"==typeof n.stage?n.stage:e[n.stage]:"compile",s=void 0!==r?[r,...i]:n.options;this.queue.push(this.toRuntimeEntry({...n,options:s},e[o]))}else{const n=t;if("object"==typeof r&&null!==r&&"plugin"in r){const t=r,o=i.length>0?i:t.options;this.queue.push(this.toRuntimeEntry({...t,options:o},e[n]))}else r&&this.queue.push({plugin:r,options:i,stage:e[n],order:0})}return this}priority(t){const e=this.queue[this.queue.length-1];return e&&(e.order=t),this}assembleProcessor(t){const e={};for(const i of t){const t=i.stage??r;e[t]||(e[t]=[]),e[t].push(i)}const n=[],o=Object.keys(e).map(Number).sort((t,e)=>t-e);for(const t of o){const r=e[t].sort((t,e)=>(t.order||0)-(e.order||0)),i=r.findIndex(t=>t.main);if(-1!==i){const t=r[i];r.splice(i,1),r[0]=t}let o=!0,s=0;for(;o&&s<r.length;){o=!1,s++;for(let t=0;t<r.length;t++){const e=r[t];if(e.after){const i=r.findIndex(t=>t.name===e.after);if(-1!==i&&i>t){r.splice(t,1),r.splice(i,0,e),o=!0;break}}if(e.before){const i=r.findIndex(t=>t.name===e.before);if(-1!==i&&i<t){r.splice(t,1),r.splice(i,0,e),o=!0;break}}}}n.push(...r)}const s=i();Object.keys(this._data).length>0&&s.data(this._data);for(const t of n)s.use(t.plugin,...t.options||[]);return s}};I.registry=new Map;var L=I,B=class extends L{async toMarkdown(){const t=await this.to("markdown");return String(t)}toMarkdownVFile(){return this.to("markdown")}async toHtml(){const t=await this.to("html");return String(t)}toHtmlVFile(){return this.to("html")}async toAst(t){if(t?.stage){const i=e[t.stage],n=this.queue.filter(t=>(t.stage??r)<=i);n.push({plugin:z,options:[],stage:400,order:0}),this.ensureInputPlugins(n,t.overrides,i);const o=this.assembleProcessor(n);if($(this.input)){return await o.run(this.input)}return(await o.process(this.input)).result}return(await this.to("ast",t?.overrides)).result}toHTML(){return this.toHtml()}toAST(t){return this.toAst(t)}};function V(t){return new B(t)}B.register(F),B.register(E),B.register(O);import{fromHtml as C}from"hast-util-from-html";var G=function(e){let r={};"boolean"==typeof e?r={enable:e}:e&&(r=e);const{enable:i,readability:n,jsdom:o}=r;!1!==i&&(this.parser=function(e,r){let i,s;try{i=t("jsdom").JSDOM;s=t("@mozilla/readability").Readability}catch(t){throw new Error("[html-readability] Dependency missing. Please install 'jsdom' and '@mozilla/readability'.")}const a=new s(new i(e,o).window.document,n).parse();if(!a||!a.content)return C(e,{fragment:!0});const u=C(a.content,{fragment:!0}),p={title:a.title,byline:a.byline,excerpt:a.excerpt,siteName:a.siteName,lang:a.lang};return r&&(r.data=r.data||{},r.data.readability=p),u&&(u.data=u.data||{},u.data.readability=p),u})},J={name:"readability",plugin:G,stage:0},R={name:"restore-readability-meta",plugin:()=>(t,e)=>{e.data?.readability&&(t.data=t.data||{},t.data.readability=e.data.readability)},stage:0,after:"rehype-remark"},K=[J,R];export{r as DefaultPipelineStage,L as MdastBasePipeline,B as MdastPipeline,e as PipelineStage,z as astCompiler,O as astFormat,E as htmlFormat,G as htmlReadability,J as htmlReadabilityPlugin,K as htmlReadabilityPlugins,H as jsonParser,F as markdownFormat,V as mdast,R as restoreReadabilityMetaPlugin};
package/docs/README.md CHANGED
@@ -75,12 +75,18 @@ const rawAst = await mdast('==Highlighted==').toAST({ stage: 'parse' });
75
75
  ### Advanced Pipeline
76
76
 
77
77
  ```typescript
78
- const { content, assets } = await mdast(myInput)
78
+ import { htmlReadabilityPlugins } from '@isdk/mdast-plus';
79
+
80
+ const vfile = await mdast(myInput)
79
81
  .data({ myGlobal: 'value' })
80
- // Add a custom plugin at the 'compile' stage
81
- .useAt('compile', myPlugin, { option: 1 })
82
+ // Add multiple plugins as an array at the 'compile' stage
83
+ .use([pluginA, pluginB])
84
+ // Or add a set of plugins at a specific stage
85
+ .useAt('parse', htmlReadabilityPlugins)
82
86
  .priority(10) // Run later than default plugins
83
87
  .to('html');
88
+
89
+ console.log(vfile.value); // The serialized HTML string
84
90
  ```
85
91
 
86
92
  ### Plugin Behavior
@@ -129,7 +135,7 @@ const result = await mdast('Hello').to('reverse');
129
135
 
130
136
  ## Staged Processing
131
137
 
132
- Plugins are executed based on their `stage` and `order`:
138
+ Plugins are executed based on their `stage`, `order`, and semantic constraints (`before`/`after`):
133
139
 
134
140
  1. **parse** (0): Input parsing (e.g., `remark-parse`).
135
141
  2. **normalize** (100): Cleanup and canonicalize the tree.
@@ -137,6 +143,12 @@ Plugins are executed based on their `stage` and `order`:
137
143
  4. **finalize** (300): Final preparation before output (e.g. `rehype-sanitize`).
138
144
  5. **stringify** (400): Output generation.
139
145
 
146
+ ### Main Plugin Replacement
147
+
148
+ Each stage can have one "main" plugin. If a plugin is marked with `main: true`, it will **replace** the first plugin in that same stage. This is useful for swapping out default parsers or compilers while keeping the rest of the pipeline intact.
149
+
150
+ > **Note**: Only one main plugin is allowed per stage. If multiple plugins are marked as main, only the last one defined will take effect as the replacement.
151
+
140
152
  ## Core Plugins Included
141
153
 
142
154
  | Plugin | Stage | Description |
@@ -146,6 +158,7 @@ Plugins are executed based on their `stage` and `order`:
146
158
  | `extract-code-meta` | normalize | Parses `title="foo"` from code block meta. |
147
159
  | `image-size` | normalize | Parses `#=WxH` from image URLs. |
148
160
  | `normalize-inline-styles` | normalize | Standardizes `==mark==`, `~sub~`, and `^sup^`. |
161
+ | `html-readability` | parse | Uses Mozilla's Readability to extract main content from HTML. Use `htmlReadabilityPlugins` array for easier setup. |
149
162
 
150
163
  ## Contributing
151
164
 
@@ -8,14 +8,14 @@ Thank you for your interest in contributing to `@isdk/mdast-plus`! This document
8
8
 
9
9
  ### Core Concepts
10
10
 
11
- 1. **Fluent API**: The main entry point is the `mdast()` function in `src/pipeline.ts`, backed by `MdastPipeline`.
12
- 2. **Staged Plugins**: Plugins are categorized into 5 stages (`PipelineStage`):
13
- * `parse`: Parsing input to AST.
14
- * `normalize`: Cleanup and canonicalize the tree.
15
- * `compile`: High-level semantic transformations.
16
- * `finalize`: Final preparation before output.
17
- * `stringify`: Serializing AST to output.
18
- 3. **Universal Data Protocols**: Nodes use `node.data` for metadata, and `node.data.hProperties` for HTML attributes.
11
+ 1. **Fluent API**: The main entry point is the `mdast()` function in `src/pipeline.ts`, backed by `MdastPipeline`.
12
+ 2. **Staged Plugins**: Plugins are categorized into 5 stages (`PipelineStage`):
13
+ * `parse`: Parsing input to AST.
14
+ * `normalize`: Cleanup and canonicalize the tree.
15
+ * `compile`: High-level semantic transformations.
16
+ * `finalize`: Final preparation before output.
17
+ * `stringify`: Serializing AST to output.
18
+ 3. **Universal Data Protocols**: Nodes use `node.data` for metadata, and `node.data.hProperties` for HTML attributes.
19
19
 
20
20
  ## Getting Started
21
21
 
@@ -56,8 +56,8 @@ pnpm run lint
56
56
 
57
57
  ## Adding a New Plugin
58
58
 
59
- 1. Create your plugin in `src/plugins/`.
60
- 2. Implement the `MdastPlugin` interface. The `plugin` property should be a standard unified plugin.
59
+ 1. Create your plugin in `src/plugins/`.
60
+ 2. Implement the `MdastPlugin` interface. The `plugin` property should be a standard unified plugin.
61
61
 
62
62
  ```typescript
63
63
  import { MdastPlugin, PipelineStage } from '../types';
@@ -72,13 +72,21 @@ const myUnifiedPlugin = (options) => {
72
72
  };
73
73
 
74
74
  export const myPlugin: MdastPlugin = {
75
+ name: 'my-custom-plugin',
75
76
  plugin: myUnifiedPlugin,
76
- stage: PipelineStage.normalize, // or 'compile', 'finalize'
77
- order: 50, // 0-100
77
+ stage: PipelineStage.normalize, // or 'compile', 'finalize', etc.
78
+ order: 50, // 0-100
79
+ main: false, // Set to true to replace the first plugin of the stage, defaults to false
80
+ before: 'some-other-plugin', // Optional: run before another plugin
81
+ after: 'another-plugin', // Optional: run after another plugin
78
82
  };
79
83
  ```
80
84
 
81
- 3. If it's a default plugin, add it to the `input` or `output` list of the relevant format in `src/formats/`.
85
+ ### Main Plugins
86
+
87
+ Each stage supports a **single** main plugin. When a plugin is marked with `main: true`, it will replace the first plugin that was originally registered for that stage. This is primarily used by formats to allow users to override the default parser or stringifier by injecting a different one at the same stage.
88
+
89
+ 1. If it's a default plugin, add it to the `input` or `output` list of the relevant format in `src/formats/`.
82
90
 
83
91
  ## Adding a New Format
84
92
 
@@ -71,12 +71,18 @@ const rawAst = await mdast('==高亮内容==').toAST({ stage: 'parse' });
71
71
  ### 高级工作流
72
72
 
73
73
  ```typescript
74
- const { content, assets } = await mdast(myInput)
74
+ import { htmlReadabilityPlugins } from '@isdk/mdast-plus';
75
+
76
+ const vfile = await mdast(myInput)
75
77
  .data({ myGlobal: 'value' })
76
- // 'compile' 阶段添加自定义插件
77
- .useAt('compile', myPlugin, { option: 1 })
78
+ // 以数组形式在 'compile' 阶段添加多个插件
79
+ .use([pluginA, pluginB])
80
+ // 或在特定阶段添加一组插件
81
+ .useAt('parse', htmlReadabilityPlugins)
78
82
  .priority(10) // 比默认插件更晚执行
79
83
  .to('html');
84
+
85
+ console.log(vfile.value); // 序列化后的 HTML 字符串
80
86
  ```
81
87
 
82
88
  ### 插件行为
@@ -125,13 +131,19 @@ const result = await mdast('Hello').to('reverse');
125
131
 
126
132
  ## 分阶段处理
127
133
 
128
- 插件根据它们的 `stage` (阶段) 和 `order` (顺序) 执行:
134
+ 插件根据它们的 `stage` (阶段)、`order` (顺序) 以及语义约束 (`before`/`after`) 执行:
135
+
136
+ 1. **parse** (0): 输入解析 (例如 `remark-parse`)。
137
+ 2. **normalize** (100): 清理并规范化树。
138
+ 3. **compile** (200): 高级语义转换。
139
+ 4. **finalize** (300): 输出前的最后准备 (例如 `rehype-sanitize`)。
140
+ 5. **stringify** (400): 输出生成。
141
+
142
+ ### 主插件替换 (Main Plugin Replacement)
143
+
144
+ 每个阶段可以有一个“主”插件。如果一个插件被标记为 `main: true`,它将 **替换** 该阶段中的第一个插件。这对于在保持管道其余部分不变的情况下更换默认解析器或编译器非常有用。
129
145
 
130
- 1. **parse** (0): 输入解析 (例如 `remark-parse`)。
131
- 2. **normalize** (100): 清理并规范化树。
132
- 3. **compile** (200): 高级语义转换。
133
- 4. **finalize** (300): 输出前的最后准备 (例如 `rehype-sanitize`)。
134
- 5. **stringify** (400): 输出生成。
146
+ > **注意**: 每个阶段只允许存在一个主插件。如果多个插件被标记为 main,则只有最后定义的那个会作为替换生效。
135
147
 
136
148
  ## 内置核心插件
137
149
 
@@ -142,6 +154,7 @@ const result = await mdast('Hello').to('reverse');
142
154
  | `extract-code-meta` | normalize | 从代码块元数据中解析 `title="foo"`。 |
143
155
  | `image-size` | normalize | 从图片 URL 中解析 `#=WxH`。 |
144
156
  | `normalize-inline-styles` | normalize | 标准化 `==mark==`、`~sub~` 和 `^sup^`。 |
157
+ | `html-readability` | parse | 使用 Mozilla 的 Readability 从 HTML 中提取主体内容。使用 `htmlReadabilityPlugins` 数组可以简化配置。 |
145
158
 
146
159
  ## 贡献
147
160
 
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Class: MdastBasePipeline
8
8
 
9
- Defined in: [packages/mdast-plus/src/pipeline.ts:26](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L26)
9
+ Defined in: [packages/mdast-plus/src/pipeline.ts:26](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L26)
10
10
 
11
11
  Base implementation of the fluent mdast processing pipeline.
12
12
  Manages the plugin registry and the execution queue.
@@ -21,7 +21,7 @@ Manages the plugin registry and the execution queue.
21
21
 
22
22
  > **new MdastBasePipeline**(`input`): `MdastBasePipeline`
23
23
 
24
- Defined in: [packages/mdast-plus/src/pipeline.ts:53](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L53)
24
+ Defined in: [packages/mdast-plus/src/pipeline.ts:54](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L54)
25
25
 
26
26
  Initializes a new pipeline instance with the given input.
27
27
 
@@ -39,11 +39,19 @@ Content to process (string, Buffer, VFile, or AST Node).
39
39
 
40
40
  ## Properties
41
41
 
42
+ ### \_data
43
+
44
+ > `protected` **\_data**: `Record`\<`string`, `any`\> = `{}`
45
+
46
+ Defined in: [packages/mdast-plus/src/pipeline.ts:48](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L48)
47
+
48
+ ***
49
+
42
50
  ### input
43
51
 
44
52
  > `protected` **input**: `Compatible`
45
53
 
46
- Defined in: [packages/mdast-plus/src/pipeline.ts:46](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L46)
54
+ Defined in: [packages/mdast-plus/src/pipeline.ts:46](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L46)
47
55
 
48
56
  ***
49
57
 
@@ -51,7 +59,7 @@ Defined in: [packages/mdast-plus/src/pipeline.ts:46](https://github.com/isdk/mda
51
59
 
52
60
  > `protected` **queue**: [`MdastPlugin`](../interfaces/MdastPlugin.md)[] = `[]`
53
61
 
54
- Defined in: [packages/mdast-plus/src/pipeline.ts:47](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L47)
62
+ Defined in: [packages/mdast-plus/src/pipeline.ts:47](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L47)
55
63
 
56
64
  ## Methods
57
65
 
@@ -59,7 +67,7 @@ Defined in: [packages/mdast-plus/src/pipeline.ts:47](https://github.com/isdk/mda
59
67
 
60
68
  > `protected` **assembleProcessor**(`queue`): `Processor`
61
69
 
62
- Defined in: [packages/mdast-plus/src/pipeline.ts:254](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L254)
70
+ Defined in: [packages/mdast-plus/src/pipeline.ts:326](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L326)
63
71
 
64
72
  Assembles a unified processor based on the sorted plugin queue.
65
73
 
@@ -75,11 +83,41 @@ Assembles a unified processor based on the sorted plugin queue.
75
83
 
76
84
  ***
77
85
 
86
+ ### data()
87
+
88
+ > **data**(`key`, `value?`): `this`
89
+
90
+ Defined in: [packages/mdast-plus/src/pipeline.ts:64](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L64)
91
+
92
+ Configures global data for the pipeline, which will be available to all plugins via this.data().
93
+
94
+ #### Parameters
95
+
96
+ ##### key
97
+
98
+ Data key or a record of multiple data entries.
99
+
100
+ `string` | `Record`\<`string`, `any`\>
101
+
102
+ ##### value?
103
+
104
+ `any`
105
+
106
+ Value to set (if key is a string).
107
+
108
+ #### Returns
109
+
110
+ `this`
111
+
112
+ The pipeline instance for chaining.
113
+
114
+ ***
115
+
78
116
  ### ensureInputPlugins()
79
117
 
80
118
  > `protected` **ensureInputPlugins**(`queue`, `overrides?`, `maxStage?`): `void`
81
119
 
82
- Defined in: [packages/mdast-plus/src/pipeline.ts:123](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L123)
120
+ Defined in: [packages/mdast-plus/src/pipeline.ts:149](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L149)
83
121
 
84
122
  Ensures that input plugins (parser, normalizers) are present in the queue.
85
123
  Adds implicit plugins if no parser is detected.
@@ -108,7 +146,7 @@ Adds implicit plugins if no parser is detected.
108
146
 
109
147
  > **from**(`fmt`, `overrides?`): `this`
110
148
 
111
- Defined in: [packages/mdast-plus/src/pipeline.ts:152](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L152)
149
+ Defined in: [packages/mdast-plus/src/pipeline.ts:178](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L178)
112
150
 
113
151
  Configures the input format and adds its associated plugins to the pipeline.
114
152
 
@@ -138,7 +176,7 @@ The pipeline instance for chaining.
138
176
 
139
177
  > **getFormat**(`id`): `undefined` \| [`MdastFormat`](../interfaces/MdastFormat.md)
140
178
 
141
- Defined in: [packages/mdast-plus/src/pipeline.ts:60](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L60)
179
+ Defined in: [packages/mdast-plus/src/pipeline.ts:76](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L76)
142
180
 
143
181
  Instance-level access to the global format registry.
144
182
 
@@ -158,7 +196,7 @@ Instance-level access to the global format registry.
158
196
 
159
197
  > **priority**(`order`): `this`
160
198
 
161
- Defined in: [packages/mdast-plus/src/pipeline.ts:242](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L242)
199
+ Defined in: [packages/mdast-plus/src/pipeline.ts:314](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L314)
162
200
 
163
201
  Sets the priority order for the most recently added plugin.
164
202
  Plugins with lower order run earlier within the same stage.
@@ -183,7 +221,7 @@ The pipeline instance for chaining.
183
221
 
184
222
  > **to**(`fmt`, `overrides?`): `Promise`\<`VFile`\>
185
223
 
186
- Defined in: [packages/mdast-plus/src/pipeline.ts:172](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L172)
224
+ Defined in: [packages/mdast-plus/src/pipeline.ts:198](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L198)
187
225
 
188
226
  Processes the pipeline and serializes the result into the specified format.
189
227
 
@@ -213,7 +251,7 @@ A promise resolving to a VFile containing the result.
213
251
 
214
252
  > `protected` **toRuntimeEntry**(`entry`, `defaultStage`, `overrides?`): [`MdastPlugin`](../interfaces/MdastPlugin.md) & `object`
215
253
 
216
- Defined in: [packages/mdast-plus/src/pipeline.ts:84](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L84)
254
+ Defined in: [packages/mdast-plus/src/pipeline.ts:100](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L100)
217
255
 
218
256
  Normalizes a plugin entry for runtime execution.
219
257
 
@@ -241,23 +279,23 @@ Normalizes a plugin entry for runtime execution.
241
279
 
242
280
  > **use**(`plugin`, ...`options`): `this`
243
281
 
244
- Defined in: [packages/mdast-plus/src/pipeline.ts:215](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L215)
282
+ Defined in: [packages/mdast-plus/src/pipeline.ts:241](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L241)
245
283
 
246
- Adds a plugin to the pipeline's compile stage.
284
+ Adds a plugin or an array of plugins to the pipeline's compile stage.
247
285
 
248
286
  #### Parameters
249
287
 
250
288
  ##### plugin
251
289
 
252
- `any`
290
+ The unified plugin function, a MdastPlugin object, or an array of them.
253
291
 
254
- The unified plugin function.
292
+ [`MdastPlugin`](../interfaces/MdastPlugin.md) | `Plugin` | ([`MdastPlugin`](../interfaces/MdastPlugin.md) \| `Plugin`)[]
255
293
 
256
294
  ##### options
257
295
 
258
296
  ...`any`[]
259
297
 
260
- Arguments for the plugin.
298
+ Arguments for the plugin(s).
261
299
 
262
300
  #### Returns
263
301
 
@@ -269,33 +307,63 @@ The pipeline instance for chaining.
269
307
 
270
308
  ### useAt()
271
309
 
310
+ #### Call Signature
311
+
272
312
  > **useAt**(`stage`, `plugin`, ...`options`): `this`
273
313
 
274
- Defined in: [packages/mdast-plus/src/pipeline.ts:226](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L226)
314
+ Defined in: [packages/mdast-plus/src/pipeline.ts:252](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L252)
275
315
 
276
- Adds a plugin to the pipeline at a specific stage.
316
+ Adds a plugin or an array of plugins to the pipeline at a specific stage.
277
317
 
278
- #### Parameters
318
+ ##### Parameters
279
319
 
280
- ##### stage
320
+ ###### stage
281
321
 
282
322
  The stage name or numeric value.
283
323
 
284
324
  `"parse"` | `"normalize"` | `"compile"` | `"finalize"` | `"stringify"`
285
325
 
286
- ##### plugin
326
+ ###### plugin
287
327
 
288
- `any`
328
+ The unified plugin function, a MdastPlugin object, or an array of them.
289
329
 
290
- The unified plugin function.
330
+ [`MdastPlugin`](../interfaces/MdastPlugin.md) | `Plugin` | ([`MdastPlugin`](../interfaces/MdastPlugin.md) \| `Plugin`)[]
291
331
 
292
- ##### options
332
+ ###### options
293
333
 
294
334
  ...`any`[]
295
335
 
296
- Arguments for the plugin.
336
+ Arguments for the plugin(s).
297
337
 
298
- #### Returns
338
+ ##### Returns
339
+
340
+ `this`
341
+
342
+ The pipeline instance for chaining.
343
+
344
+ #### Call Signature
345
+
346
+ > **useAt**(`plugin`, ...`options`): `this`
347
+
348
+ Defined in: [packages/mdast-plus/src/pipeline.ts:259](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L259)
349
+
350
+ Adds a plugin or an array of plugins to the pipeline. The stage is taken from the plugin object(s).
351
+
352
+ ##### Parameters
353
+
354
+ ###### plugin
355
+
356
+ The MdastPlugin object or an array of them.
357
+
358
+ [`MdastPlugin`](../interfaces/MdastPlugin.md) | ([`MdastPlugin`](../interfaces/MdastPlugin.md) \| `Plugin`)[]
359
+
360
+ ###### options
361
+
362
+ ...`any`[]
363
+
364
+ Arguments for the plugin(s) (overrides plugin.options if provided).
365
+
366
+ ##### Returns
299
367
 
300
368
  `this`
301
369
 
@@ -307,7 +375,7 @@ The pipeline instance for chaining.
307
375
 
308
376
  > `static` **getFormat**(`id`): `undefined` \| [`MdastFormat`](../interfaces/MdastFormat.md)
309
377
 
310
- Defined in: [packages/mdast-plus/src/pipeline.ts:42](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L42)
378
+ Defined in: [packages/mdast-plus/src/pipeline.ts:42](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L42)
311
379
 
312
380
  Retrieves a registered format by its ID.
313
381
 
@@ -331,7 +399,7 @@ The format definition or undefined if not found.
331
399
 
332
400
  > `static` **register**(`format`): `void`
333
401
 
334
- Defined in: [packages/mdast-plus/src/pipeline.ts:33](https://github.com/isdk/mdast-plus.js/blob/bacb4922529058fef775e3f4b4e71c98ac1cab17/src/pipeline.ts#L33)
402
+ Defined in: [packages/mdast-plus/src/pipeline.ts:33](https://github.com/isdk/mdast-plus.js/blob/8870eec4ef97dd48bead818813d06479ceff9450/src/pipeline.ts#L33)
335
403
 
336
404
  Registers a global document format.
337
405