@isdk/mdast-plus 0.1.3 → 0.2.1
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/README.cn.md +24 -9
- package/README.md +19 -4
- package/dist/index.d.mts +409 -85
- package/dist/index.d.ts +409 -85
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/docs/README.md +19 -4
- package/docs/_media/CONTRIBUTING.md +23 -13
- package/docs/_media/README.cn.md +24 -9
- package/docs/classes/MdastBasePipeline.md +129 -29
- package/docs/classes/MdastPipeline.md +155 -39
- package/docs/enumerations/PipelineStage.md +6 -6
- package/docs/functions/astCompiler.md +1 -1
- package/docs/functions/jsonParser.md +1 -1
- package/docs/functions/mdast.md +1 -1
- package/docs/globals.md +5 -0
- package/docs/interfaces/MdastDataOrigin.md +4 -4
- package/docs/interfaces/MdastFormat.md +7 -7
- package/docs/interfaces/MdastMark.md +3 -3
- package/docs/interfaces/MdastPlugin.md +38 -6
- package/docs/interfaces/MdastSub.md +3 -3
- package/docs/interfaces/MdastSup.md +3 -3
- package/docs/interfaces/ReadabilityOptions.md +41 -0
- package/docs/type-aliases/PipelineStageName.md +1 -1
- package/docs/variables/DefaultPipelineStage.md +1 -1
- package/docs/variables/astFormat.md +1 -1
- package/docs/variables/htmlFormat.md +1 -1
- package/docs/variables/htmlReadability.md +13 -0
- package/docs/variables/htmlReadabilityPlugin.md +31 -0
- package/docs/variables/htmlReadabilityPlugins.md +13 -0
- package/docs/variables/markdownFormat.md +1 -1
- package/docs/variables/restoreReadabilityMetaPlugin.md +49 -0
- package/package.json +8 -1
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:()=>L,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"),g=u(require("remark-parse")),m=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},S=require("unist-util-visit"),F={plugin:()=>async t=>{(0,S.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"),O=require("shell-quote");var A={plugin:()=>async t=>{(0,T.visit)(t,"code",t=>{if(t.meta){const e=function(t){const e={},r=(0,O.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},D=require("unist-util-visit"),N={plugin:()=>async t=>{(0,D.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:g.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,F,A,N,j],z=[{plugin:m.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}];z.forEach(t=>{t.plugin===m.default?t.order=100:t.order=10});var R={id:"markdown",title:"Markdown (GFM + Directives)",extensions:["md","markdown","mdown","mkdn"],mediaTypes:["text/markdown"],input:E,output:z},$=u(require("rehype-parse")),B=u(require("rehype-remark")),C=u(require("remark-rehype")),H=u(require("rehype-sanitize")),I=u(require("rehype-stringify")),L={id:"html",title:"HTML",extensions:["html","htm"],mediaTypes:["text/html"],input:[{name:"rehype-parse",plugin:$.default,stage:0},{name:"rehype-remark",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}],output:[{plugin:C.default,stage:300,order:10},{plugin:H.default,options:[{...H.defaultSchema,tagNames:[...H.defaultSchema.tagNames||[],"mark","sub","sup"],attributes:{...H.defaultSchema.attributes,"*":[...H.defaultSchema.attributes?.["*"]||[],"className","id","style"],td:[...H.defaultSchema.attributes?.td||[],"rowSpan","colSpan","rowspan","colspan"],th:[...H.defaultSchema.attributes?.th||[],"rowSpan","colSpan","rowspan","colspan"],img:[...H.defaultSchema.attributes?.img||[],"width","height"]}}],stage:300,order:20},{plugin:I.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,F,A,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?c[i.stage]:i.stage:p,s=void 0!==e?[e,...r]:i.options;this.queue.push(this.toRuntimeEntry({...i,options:s},n))}else{const i="string"==typeof t?c[t]??p: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},i))}else e&&this.queue.push({plugin:e,options:r,stage:i,order:0})}return this}priority(t){const e=this.queue[this.queue.length-1];return e&&(e.order=t),this}configure(t,...e){for(let r=this.queue.length-1;r>=0;r--){const i=this.queue[r];if((i.name||i.plugin.name)===t){i.options=e;break}}return 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];!1===t.options?.[0]?console.warn(`Main Plugin "${t.name}" is disabled. Skipping.`):(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="string"==typeof t.stage?c[t.stage]: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(L),U.register(G);var X=require("hast-util-from-html"),Y=function(t){const{readability:e,jsdom:r,url:i}=t||{};this.parser=function(t,n){if(!1===e)return(0,X.fromHtml)(t,{fragment:!0});let s,o;try{s=require("jsdom").JSDOM;o=require("@mozilla/readability").Readability}catch(t){throw new Error("[html-readability] Dependency missing. Please install 'jsdom' and '@mozilla/readability'.")}const a=new o(new s(t,{url:i,pretendToBeVisual:!0,...r}).window.document,{maxElemsToParse:1e5,nbTopCandidates:5,charThreshold:500,keepClasses:!0,...e}).parse();if(!a||!a.content)return(0,X.fromHtml)(t,{fragment:!0});const u=(0,X.fromHtml)(a.content,{fragment:!0}),l={title:a.title,byline:a.byline,excerpt:a.excerpt,siteName:a.siteName,lang:a.lang};return n&&(n.data=n.data||{},n.data.readability=l),u&&(u.data=u.data||{},u.data.readability=l),u}},Z={name:"readability",plugin:Y,stage:0,main:!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},T=[{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 j={id:"markdown",title:"Markdown (GFM + Directives)",extensions:["md","markdown","mdown","mkdn"],mediaTypes:["text/markdown"],input:T,output:S};import P from"rehype-parse";import F from"rehype-remark";import q from"remark-rehype";import A,{defaultSchema as D}from"rehype-sanitize";import E from"rehype-stringify";var N={id:"html",title:"HTML",extensions:["html","htm"],mediaTypes:["text/html"],input:[{name:"rehype-parse",plugin:P,stage:0},{name:"rehype-remark",plugin:F,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:q,stage:300,order:10},{plugin:A,options:[{...D,tagNames:[...D.tagNames||[],"mark","sub","sup"],attributes:{...D.attributes,"*":[...D.attributes?.["*"]||[],"className","id","style"],td:[...D.attributes?.td||[],"rowSpan","colSpan","rowspan","colspan"],th:[...D.attributes?.th||[],"rowSpan","colSpan","rowspan","colspan"],img:[...D.attributes?.img||[],"width","height"]}}],stage:300,order:20},{plugin:E,stage:400}]};function z(){this.Compiler=t=>t}function $(){this.Parser=t=>JSON.parse(t)}var H={id:"ast",title:"MDAST",input:[{plugin:$,stage:0},d,v,k,M,c],output:[{plugin:z,options:[],stage:400}]};function O(t){return"object"==typeof t&&null!==t&&"string"==typeof t.type}var B=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=O(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(O(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,i,...n){if(Array.isArray(t)){for(const e of t)this.useAt(e,i,...n);return this}if(Array.isArray(i)){for(const e of i)this.useAt(t,e,...n);return this}if("object"==typeof t&&null!==t&&"plugin"in t){const o=t,s=void 0!==o.stage?"string"==typeof o.stage?e[o.stage]:o.stage:r,a=void 0!==i?[i,...n]:o.options;this.queue.push(this.toRuntimeEntry({...o,options:a},s))}else{const o="string"==typeof t?e[t]??r:t;if("object"==typeof i&&null!==i&&"plugin"in i){const t=i,e=n.length>0?n:t.options;this.queue.push(this.toRuntimeEntry({...t,options:e},o))}else i&&this.queue.push({plugin:i,options:n,stage:o,order:0})}return this}priority(t){const e=this.queue[this.queue.length-1];return e&&(e.order=t),this}configure(t,...e){for(let r=this.queue.length-1;r>=0;r--){const i=this.queue[r];if((i.name||i.plugin.name)===t){i.options=e;break}}return 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];!1===t.options?.[0]?console.warn(`Main Plugin "${t.name}" is disabled. Skipping.`):(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}};B.registry=new Map;var C=B,I=class extends C{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="string"==typeof t.stage?e[t.stage]: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(O(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 L(t){return new I(t)}I.register(j),I.register(N),I.register(H);import{fromHtml as V}from"hast-util-from-html";var G=function(e){const{readability:r,jsdom:i,url:n}=e||{};this.parser=function(e,o){if(!1===r)return V(e,{fragment:!0});let s,a;try{s=t("jsdom").JSDOM;a=t("@mozilla/readability").Readability}catch(t){throw new Error("[html-readability] Dependency missing. Please install 'jsdom' and '@mozilla/readability'.")}const u=new a(new s(e,{url:n,pretendToBeVisual:!0,...i}).window.document,{maxElemsToParse:1e5,nbTopCandidates:5,charThreshold:500,keepClasses:!0,...r}).parse();if(!u||!u.content)return V(e,{fragment:!0});const p=V(u.content,{fragment:!0}),l={title:u.title,byline:u.byline,excerpt:u.excerpt,siteName:u.siteName,lang:u.lang};return o&&(o.data=o.data||{},o.data.readability=l),p&&(p.data=p.data||{},p.data.readability=l),p}},J={name:"readability",plugin:G,stage:0,main:!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,C as MdastBasePipeline,I as MdastPipeline,e as PipelineStage,z as astCompiler,H as astFormat,N as htmlFormat,G as htmlReadability,J as htmlReadabilityPlugin,K as htmlReadabilityPlugins,$ as jsonParser,j as markdownFormat,L as mdast,R as restoreReadabilityMetaPlugin};
|
package/docs/README.md
CHANGED
|
@@ -75,18 +75,26 @@ const rawAst = await mdast('==Highlighted==').toAST({ stage: 'parse' });
|
|
|
75
75
|
### Advanced Pipeline
|
|
76
76
|
|
|
77
77
|
```typescript
|
|
78
|
-
|
|
78
|
+
import { htmlReadabilityPlugins } from '@isdk/mdast-plus';
|
|
79
|
+
|
|
80
|
+
const vfile = await mdast(myInput)
|
|
79
81
|
.data({ myGlobal: 'value' })
|
|
80
|
-
// Add
|
|
81
|
-
.
|
|
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
|
|
87
93
|
|
|
88
94
|
`mdast-plus` uses [unified](https://github.com/unifiedjs/unified) internally. If you add the same plugin function multiple times, the last configuration **overrides** the previous ones.
|
|
89
95
|
|
|
96
|
+
> **Warning**: Passing `false` as a plugin option (e.g., `.use(myPlugin, false)`) will **disable** the plugin entirely. For regular plugins, this means they simply won't run. For plugins marked as `main: true` (like replacements for the default parser), if they are disabled with `false`, they will **not** replace the default plugin of that stage, providing a safe fallback to the default behavior. If you want to bypass a plugin's logic while keeping it active (e.g. to maintain its parser), use an options object like `{ enable: false }` instead.
|
|
97
|
+
|
|
90
98
|
```typescript
|
|
91
99
|
// The plugin will run ONCE with option: 2
|
|
92
100
|
pipeline.use(myPlugin, { option: 1 });
|
|
@@ -129,7 +137,7 @@ const result = await mdast('Hello').to('reverse');
|
|
|
129
137
|
|
|
130
138
|
## Staged Processing
|
|
131
139
|
|
|
132
|
-
Plugins are executed based on their `stage` and `
|
|
140
|
+
Plugins are executed based on their `stage`, `order`, and semantic constraints (`before`/`after`):
|
|
133
141
|
|
|
134
142
|
1. **parse** (0): Input parsing (e.g., `remark-parse`).
|
|
135
143
|
2. **normalize** (100): Cleanup and canonicalize the tree.
|
|
@@ -137,6 +145,12 @@ Plugins are executed based on their `stage` and `order`:
|
|
|
137
145
|
4. **finalize** (300): Final preparation before output (e.g. `rehype-sanitize`).
|
|
138
146
|
5. **stringify** (400): Output generation.
|
|
139
147
|
|
|
148
|
+
### Main Plugin Replacement
|
|
149
|
+
|
|
150
|
+
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.
|
|
151
|
+
|
|
152
|
+
> **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.
|
|
153
|
+
|
|
140
154
|
## Core Plugins Included
|
|
141
155
|
|
|
142
156
|
| Plugin | Stage | Description |
|
|
@@ -146,6 +160,7 @@ Plugins are executed based on their `stage` and `order`:
|
|
|
146
160
|
| `extract-code-meta` | normalize | Parses `title="foo"` from code block meta. |
|
|
147
161
|
| `image-size` | normalize | Parses `#=WxH` from image URLs. |
|
|
148
162
|
| `normalize-inline-styles` | normalize | Standardizes `==mark==`, `~sub~`, and `^sup^`. |
|
|
163
|
+
| `html-readability` | parse | Uses Mozilla's Readability to extract main content from HTML. Use `htmlReadabilityPlugins` array for easier setup. |
|
|
149
164
|
|
|
150
165
|
## Contributing
|
|
151
166
|
|
|
@@ -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.
|
|
12
|
-
2.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
3.
|
|
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.
|
|
60
|
-
2.
|
|
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,23 @@ 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,
|
|
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
|
-
|
|
85
|
+
> **Important**: Never pass `false` as the second argument to `.use()` or within `MdastPlugin.options` if you want the plugin to execute. In `unified`, `false` is a special value that **disables** the plugin. If your plugin is a "main" plugin (like a parser replacement), disabling it with `false` will prevent it from replacing the default plugin of that stage, providing a safe fallback. A warning will be printed to the terminal when this fallback occurs. Use an options object (e.g., `{ enabled: false }`) if you need a way to skip logic within the plugin itself while keeping it active.
|
|
86
|
+
|
|
87
|
+
### Main Plugins
|
|
88
|
+
|
|
89
|
+
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.
|
|
90
|
+
|
|
91
|
+
1. If it's a default plugin, add it to the `input` or `output` list of the relevant format in `src/formats/`.
|
|
82
92
|
|
|
83
93
|
## Adding a New Format
|
|
84
94
|
|
package/docs/_media/README.cn.md
CHANGED
|
@@ -71,18 +71,26 @@ const rawAst = await mdast('==高亮内容==').toAST({ stage: 'parse' });
|
|
|
71
71
|
### 高级工作流
|
|
72
72
|
|
|
73
73
|
```typescript
|
|
74
|
-
|
|
74
|
+
import { htmlReadabilityPlugins } from '@isdk/mdast-plus';
|
|
75
|
+
|
|
76
|
+
const vfile = await mdast(myInput)
|
|
75
77
|
.data({ myGlobal: 'value' })
|
|
76
|
-
//
|
|
77
|
-
.
|
|
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
|
### 插件行为
|
|
83
89
|
|
|
84
90
|
`mdast-plus` 内部使用 [unified](https://github.com/unifiedjs/unified)。如果您多次添加同一个插件函数,最后的配置将**覆盖**之前的配置。
|
|
85
91
|
|
|
92
|
+
> **警告**: 将 `false` 作为插件选项传递(例如 `.use(myPlugin, false)`)将**完全禁用**该插件。对于普通插件,这意味着它们将不会运行。对于标记为 `main: true` 的插件(如默认解析器的替代者),如果它们被 `false` 禁用,它们将**不会**替换该阶段的默认插件,从而安全地回退到默认行为。如果你需要跳过插件逻辑但保持其激活状态(例如为了保留其解析器),请改用选项对象,例如 `{ enable: false }`。
|
|
93
|
+
|
|
86
94
|
```typescript
|
|
87
95
|
// 插件将只执行一次,且选项为: 2
|
|
88
96
|
pipeline.use(myPlugin, { option: 1 });
|
|
@@ -125,13 +133,19 @@ const result = await mdast('Hello').to('reverse');
|
|
|
125
133
|
|
|
126
134
|
## 分阶段处理
|
|
127
135
|
|
|
128
|
-
插件根据它们的 `stage` (阶段)
|
|
136
|
+
插件根据它们的 `stage` (阶段)、`order` (顺序) 以及语义约束 (`before`/`after`) 执行:
|
|
137
|
+
|
|
138
|
+
1. **parse** (0): 输入解析 (例如 `remark-parse`)。
|
|
139
|
+
2. **normalize** (100): 清理并规范化树。
|
|
140
|
+
3. **compile** (200): 高级语义转换。
|
|
141
|
+
4. **finalize** (300): 输出前的最后准备 (例如 `rehype-sanitize`)。
|
|
142
|
+
5. **stringify** (400): 输出生成。
|
|
143
|
+
|
|
144
|
+
### 主插件替换 (Main Plugin Replacement)
|
|
145
|
+
|
|
146
|
+
每个阶段可以有一个“主”插件。如果一个插件被标记为 `main: true`,它将 **替换** 该阶段中的第一个插件。这对于在保持管道其余部分不变的情况下更换默认解析器或编译器非常有用。
|
|
129
147
|
|
|
130
|
-
|
|
131
|
-
2. **normalize** (100): 清理并规范化树。
|
|
132
|
-
3. **compile** (200): 高级语义转换。
|
|
133
|
-
4. **finalize** (300): 输出前的最后准备 (例如 `rehype-sanitize`)。
|
|
134
|
-
5. **stringify** (400): 输出生成。
|
|
148
|
+
> **注意**: 每个阶段只允许存在一个主插件。如果多个插件被标记为 main,则只有最后定义的那个会作为替换生效。
|
|
135
149
|
|
|
136
150
|
## 内置核心插件
|
|
137
151
|
|
|
@@ -142,6 +156,7 @@ const result = await mdast('Hello').to('reverse');
|
|
|
142
156
|
| `extract-code-meta` | normalize | 从代码块元数据中解析 `title="foo"`。 |
|
|
143
157
|
| `image-size` | normalize | 从图片 URL 中解析 `#=WxH`。 |
|
|
144
158
|
| `normalize-inline-styles` | normalize | 标准化 `==mark==`、`~sub~` 和 `^sup^`。 |
|
|
159
|
+
| `html-readability` | parse | 使用 Mozilla 的 Readability 从 HTML 中提取主体内容。使用 `htmlReadabilityPlugins` 数组可以简化配置。 |
|
|
145
160
|
|
|
146
161
|
## 贡献
|
|
147
162
|
|
|
@@ -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/
|
|
9
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:26](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/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:
|
|
24
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:54](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/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/becb4bdeb4b577bd75c7751367751e84056ff87e/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/
|
|
54
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:46](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/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/
|
|
62
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:47](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/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:
|
|
70
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:347](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L347)
|
|
63
71
|
|
|
64
72
|
Assembles a unified processor based on the sorted plugin queue.
|
|
65
73
|
|
|
@@ -75,11 +83,73 @@ Assembles a unified processor based on the sorted plugin queue.
|
|
|
75
83
|
|
|
76
84
|
***
|
|
77
85
|
|
|
86
|
+
### configure()
|
|
87
|
+
|
|
88
|
+
> **configure**(`pluginName`, ...`options`): `this`
|
|
89
|
+
|
|
90
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:331](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L331)
|
|
91
|
+
|
|
92
|
+
Modifies the options of a plugin that is already in the pipeline queue.
|
|
93
|
+
Searches from the end of the queue and updates the first match found.
|
|
94
|
+
|
|
95
|
+
#### Parameters
|
|
96
|
+
|
|
97
|
+
##### pluginName
|
|
98
|
+
|
|
99
|
+
`string`
|
|
100
|
+
|
|
101
|
+
The name of the plugin to modify.
|
|
102
|
+
Matches against explicit plugin name or function name.
|
|
103
|
+
|
|
104
|
+
##### options
|
|
105
|
+
|
|
106
|
+
...`any`[]
|
|
107
|
+
|
|
108
|
+
The new options to pass to the plugin (replaces existing options).
|
|
109
|
+
|
|
110
|
+
#### Returns
|
|
111
|
+
|
|
112
|
+
`this`
|
|
113
|
+
|
|
114
|
+
The pipeline instance for chaining.
|
|
115
|
+
|
|
116
|
+
***
|
|
117
|
+
|
|
118
|
+
### data()
|
|
119
|
+
|
|
120
|
+
> **data**(`key`, `value?`): `this`
|
|
121
|
+
|
|
122
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:64](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L64)
|
|
123
|
+
|
|
124
|
+
Configures global data for the pipeline, which will be available to all plugins via this.data().
|
|
125
|
+
|
|
126
|
+
#### Parameters
|
|
127
|
+
|
|
128
|
+
##### key
|
|
129
|
+
|
|
130
|
+
Data key or a record of multiple data entries.
|
|
131
|
+
|
|
132
|
+
`string` | `Record`\<`string`, `any`\>
|
|
133
|
+
|
|
134
|
+
##### value?
|
|
135
|
+
|
|
136
|
+
`any`
|
|
137
|
+
|
|
138
|
+
Value to set (if key is a string).
|
|
139
|
+
|
|
140
|
+
#### Returns
|
|
141
|
+
|
|
142
|
+
`this`
|
|
143
|
+
|
|
144
|
+
The pipeline instance for chaining.
|
|
145
|
+
|
|
146
|
+
***
|
|
147
|
+
|
|
78
148
|
### ensureInputPlugins()
|
|
79
149
|
|
|
80
150
|
> `protected` **ensureInputPlugins**(`queue`, `overrides?`, `maxStage?`): `void`
|
|
81
151
|
|
|
82
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:
|
|
152
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:149](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L149)
|
|
83
153
|
|
|
84
154
|
Ensures that input plugins (parser, normalizers) are present in the queue.
|
|
85
155
|
Adds implicit plugins if no parser is detected.
|
|
@@ -108,7 +178,7 @@ Adds implicit plugins if no parser is detected.
|
|
|
108
178
|
|
|
109
179
|
> **from**(`fmt`, `overrides?`): `this`
|
|
110
180
|
|
|
111
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:
|
|
181
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:178](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L178)
|
|
112
182
|
|
|
113
183
|
Configures the input format and adds its associated plugins to the pipeline.
|
|
114
184
|
|
|
@@ -138,7 +208,7 @@ The pipeline instance for chaining.
|
|
|
138
208
|
|
|
139
209
|
> **getFormat**(`id`): `undefined` \| [`MdastFormat`](../interfaces/MdastFormat.md)
|
|
140
210
|
|
|
141
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:
|
|
211
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:76](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L76)
|
|
142
212
|
|
|
143
213
|
Instance-level access to the global format registry.
|
|
144
214
|
|
|
@@ -158,7 +228,7 @@ Instance-level access to the global format registry.
|
|
|
158
228
|
|
|
159
229
|
> **priority**(`order`): `this`
|
|
160
230
|
|
|
161
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:
|
|
231
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:314](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L314)
|
|
162
232
|
|
|
163
233
|
Sets the priority order for the most recently added plugin.
|
|
164
234
|
Plugins with lower order run earlier within the same stage.
|
|
@@ -183,7 +253,7 @@ The pipeline instance for chaining.
|
|
|
183
253
|
|
|
184
254
|
> **to**(`fmt`, `overrides?`): `Promise`\<`VFile`\>
|
|
185
255
|
|
|
186
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:
|
|
256
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:198](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L198)
|
|
187
257
|
|
|
188
258
|
Processes the pipeline and serializes the result into the specified format.
|
|
189
259
|
|
|
@@ -213,7 +283,7 @@ A promise resolving to a VFile containing the result.
|
|
|
213
283
|
|
|
214
284
|
> `protected` **toRuntimeEntry**(`entry`, `defaultStage`, `overrides?`): [`MdastPlugin`](../interfaces/MdastPlugin.md) & `object`
|
|
215
285
|
|
|
216
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:
|
|
286
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:100](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L100)
|
|
217
287
|
|
|
218
288
|
Normalizes a plugin entry for runtime execution.
|
|
219
289
|
|
|
@@ -241,23 +311,23 @@ Normalizes a plugin entry for runtime execution.
|
|
|
241
311
|
|
|
242
312
|
> **use**(`plugin`, ...`options`): `this`
|
|
243
313
|
|
|
244
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:
|
|
314
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:241](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L241)
|
|
245
315
|
|
|
246
|
-
Adds a plugin to the pipeline's compile stage.
|
|
316
|
+
Adds a plugin or an array of plugins to the pipeline's compile stage.
|
|
247
317
|
|
|
248
318
|
#### Parameters
|
|
249
319
|
|
|
250
320
|
##### plugin
|
|
251
321
|
|
|
252
|
-
|
|
322
|
+
The unified plugin function, a MdastPlugin object, or an array of them.
|
|
253
323
|
|
|
254
|
-
|
|
324
|
+
[`MdastPlugin`](../interfaces/MdastPlugin.md) | `Plugin` | ([`MdastPlugin`](../interfaces/MdastPlugin.md) \| `Plugin`)[]
|
|
255
325
|
|
|
256
326
|
##### options
|
|
257
327
|
|
|
258
328
|
...`any`[]
|
|
259
329
|
|
|
260
|
-
Arguments for the plugin.
|
|
330
|
+
Arguments for the plugin(s).
|
|
261
331
|
|
|
262
332
|
#### Returns
|
|
263
333
|
|
|
@@ -269,33 +339,63 @@ The pipeline instance for chaining.
|
|
|
269
339
|
|
|
270
340
|
### useAt()
|
|
271
341
|
|
|
342
|
+
#### Call Signature
|
|
343
|
+
|
|
272
344
|
> **useAt**(`stage`, `plugin`, ...`options`): `this`
|
|
273
345
|
|
|
274
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:
|
|
346
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:252](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L252)
|
|
275
347
|
|
|
276
|
-
Adds a plugin to the pipeline at a specific stage.
|
|
348
|
+
Adds a plugin or an array of plugins to the pipeline at a specific stage.
|
|
277
349
|
|
|
278
|
-
|
|
350
|
+
##### Parameters
|
|
279
351
|
|
|
280
|
-
|
|
352
|
+
###### stage
|
|
281
353
|
|
|
282
354
|
The stage name or numeric value.
|
|
283
355
|
|
|
284
|
-
`"parse"` | `"normalize"` | `"compile"` | `"finalize"` | `"stringify"`
|
|
356
|
+
[`PipelineStage`](../enumerations/PipelineStage.md) | `"parse"` | `"normalize"` | `"compile"` | `"finalize"` | `"stringify"`
|
|
285
357
|
|
|
286
|
-
|
|
358
|
+
###### plugin
|
|
287
359
|
|
|
288
|
-
|
|
360
|
+
The unified plugin function, a MdastPlugin object, or an array of them.
|
|
289
361
|
|
|
290
|
-
|
|
362
|
+
[`MdastPlugin`](../interfaces/MdastPlugin.md) | `Plugin` | ([`MdastPlugin`](../interfaces/MdastPlugin.md) \| `Plugin`)[]
|
|
291
363
|
|
|
292
|
-
|
|
364
|
+
###### options
|
|
293
365
|
|
|
294
366
|
...`any`[]
|
|
295
367
|
|
|
296
|
-
Arguments for the plugin.
|
|
368
|
+
Arguments for the plugin(s).
|
|
297
369
|
|
|
298
|
-
|
|
370
|
+
##### Returns
|
|
371
|
+
|
|
372
|
+
`this`
|
|
373
|
+
|
|
374
|
+
The pipeline instance for chaining.
|
|
375
|
+
|
|
376
|
+
#### Call Signature
|
|
377
|
+
|
|
378
|
+
> **useAt**(`plugin`, ...`options`): `this`
|
|
379
|
+
|
|
380
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:259](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L259)
|
|
381
|
+
|
|
382
|
+
Adds a plugin or an array of plugins to the pipeline. The stage is taken from the plugin object(s).
|
|
383
|
+
|
|
384
|
+
##### Parameters
|
|
385
|
+
|
|
386
|
+
###### plugin
|
|
387
|
+
|
|
388
|
+
The MdastPlugin object or an array of them.
|
|
389
|
+
|
|
390
|
+
[`MdastPlugin`](../interfaces/MdastPlugin.md) | [`MdastPlugin`](../interfaces/MdastPlugin.md)[]
|
|
391
|
+
|
|
392
|
+
###### options
|
|
393
|
+
|
|
394
|
+
...`any`[]
|
|
395
|
+
|
|
396
|
+
Arguments for the plugin(s) (overrides plugin.options if provided).
|
|
397
|
+
|
|
398
|
+
##### Returns
|
|
299
399
|
|
|
300
400
|
`this`
|
|
301
401
|
|
|
@@ -307,7 +407,7 @@ The pipeline instance for chaining.
|
|
|
307
407
|
|
|
308
408
|
> `static` **getFormat**(`id`): `undefined` \| [`MdastFormat`](../interfaces/MdastFormat.md)
|
|
309
409
|
|
|
310
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:42](https://github.com/isdk/mdast-plus.js/blob/
|
|
410
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:42](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L42)
|
|
311
411
|
|
|
312
412
|
Retrieves a registered format by its ID.
|
|
313
413
|
|
|
@@ -331,7 +431,7 @@ The format definition or undefined if not found.
|
|
|
331
431
|
|
|
332
432
|
> `static` **register**(`format`): `void`
|
|
333
433
|
|
|
334
|
-
Defined in: [packages/mdast-plus/src/pipeline.ts:33](https://github.com/isdk/mdast-plus.js/blob/
|
|
434
|
+
Defined in: [packages/mdast-plus/src/pipeline.ts:33](https://github.com/isdk/mdast-plus.js/blob/becb4bdeb4b577bd75c7751367751e84056ff87e/src/pipeline.ts#L33)
|
|
335
435
|
|
|
336
436
|
Registers a global document format.
|
|
337
437
|
|