remark-mdat 0.6.11 → 0.6.12

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.
Files changed (2) hide show
  1. package/dist/index.js +3 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import h from"chalk";var L,D=((L=process==null?void 0:process.versions)==null?void 0:L.node)!==void 0,ae={verbose:!1,log(...e){if(!this.verbose)return;let r=h.gray("[Log]");D?console.warn(r,...e):console.log(r,...e)},logPrefixed(e,...r){this.info(h.blue(`[${e}]`),...r)},info(...e){if(!this.verbose)return;let r=h.green("[Info]");D?console.warn(r,...e):console.info(r,...e)},infoPrefixed(e,...r){this.info(h.blue(`[${e}]`),...r)},warn(...e){console.warn(h.yellow("[Warning]"),...e)},warnPrefixed(e,...r){this.warn(h.blue(`[${e}]`),...r)},error(...e){console.error(h.red("[Error]"),...e)},errorPrefixed(e,...r){this.error(h.blue(`[${e}]`),...r)}},y=ae;import w from"chalk";import J from"node:path";function p(e,r,n,t,o,i){var u,f;let a,s;o===void 0||typeof o=="number"?(a=o??0,s=i??0):(a=((u=o==null?void 0:o.position)==null?void 0:u.start.line)??0,s=((f=o==null?void 0:o.position)==null?void 0:f.start.column)??0);let l={place:{end:{column:s,line:a},start:{column:s,line:a}},source:n},d=e.message(t,l);d.fatal=r==="error"?!0:r==="warn"?!1:void 0}function le(e){return{column:e.column,level:e.fatal?"error":e.fatal===!1?"warn":"info",line:e.line,message:e.reason,source:e.source}}function me(e){return e.map(r=>U(r))}function U(e){var n;let r={destinationPath:e.history.length>0?e.history.at(-1):void 0,errors:[],infos:[],sourcePath:e.history.at(0)??e.path,warnings:[]};(n=r.sourcePath)!=null&&n.startsWith(".")&&(r.sourcePath=J.relative(process.cwd(),J.join(process.cwd(),r.sourcePath)));for(let t of e.messages){let o=le(t);o.level==="error"?r.errors.push(o):o.level==="warn"?r.warnings.push(o):r.infos.push(o)}return r}function de(e){for(let r of e){let n=U(r),{destinationPath:t,errors:o,infos:i,sourcePath:a,warnings:s}=n;y.info(`${w.bold("MDAT Report:")}`),y.info(` From: ${w.blue.bold(a)}`),y.info(` To: ${w.blue.bold(t)}`);for(let l of o)y.error(V(a,l));for(let l of s)y.warn(V(a,l));for(let l of i)y.info(V(a,l));o.length===0&&s.length===0?y.info(`No issues found in ${a}`):y.error(`${o.length} errors, ${s.length} warnings found in ${a}`)}}function V(e,r){let{column:n,level:t,line:o,message:i,source:a}=r,s=a?w.gray(`[${a}] `):"",l=o&&n?`:${o}:${n}`:"",d=pe(i,t);return`${s}${d} ${w.whiteBright(e+l)}`}function pe(e,r){return e.replaceAll(/<!--.+-->/g,n=>r==="info"?w.green(n):r==="warn"?w.yellow(n):w.red(n))}import ue from"json5";import{VFileMessage as b}from"vfile-message";function R(e,r,n){var t;try{let o=fe(e.value,n);return o===void 0?void 0:{...o,node:e,parent:r}}catch(o){throw o instanceof b?(o.line=(t=e.position)==null?void 0:t.start.line,o):o instanceof Error?new b(o.message,e):new b("Unknown error",e)}}function fe(e,r){if(!ce(e))return;let{closingPrefix:n,keywordPrefix:t,metaCommentIdentifier:o}=r,i=e.trim(),a=i.replace(/^\s*<!--+\s*/,"").replace(/\s*-*-->\s*$/,""),[s,...l]=a.split(/(\s+|\(|{)/),d=s.startsWith(o)?"meta":t!==""&&!s.startsWith(t)&&!s.startsWith(`${n}${t}`)?"native":s.startsWith(n)?"close":"open";if(d==="meta")return{content:ye(a,o),html:i,type:d};if(d==="native")return{content:a,html:i,type:d};let u=s.replace(new RegExp(`^${n}`),"").replace(new RegExp(`^${t}`),""),f=ge(l.join(""));if(d==="open"||d==="close"){let g={};try{g=ue.parse(f)}catch(c){if(c instanceof Error)throw new b(`Failed to parse comment options "${f}" for keyword "${u}": ${c.message}`)}return{closingPrefix:n,html:i,keyword:u,keywordPrefix:t,options:g,type:d}}}function ce(e){let r=e.trim();return r.startsWith("<!--")&&r.endsWith("-->")}function ge(e){return e=e.trim(),e=e.startsWith("(")?e.slice(1):e,e=e.endsWith(")")?e.slice(0,-1):e,e=e.trim(),!e.startsWith("{")&&!e.startsWith("[")&&(e="{"+e),!e.endsWith("}")&&!e.endsWith("]")&&(e+="}"),e}function ye(e,r){return e=e.trim(),e=e.startsWith(r)?e.slice(r.length):e,e=e.endsWith(r)?e.slice(0,-r.length):e,e}import{z as m}from"zod";function M(e){let r={};for(let[n,t]of Object.entries(e))if(typeof t=="string")r[n]={applicationOrder:0,content:async()=>t,order:void 0,required:!1};else if(typeof t=="function")r[n]={applicationOrder:0,content:async(o,i)=>t(o,i),order:void 0,required:!1};else if(Array.isArray(t))r[n]={applicationOrder:0,content:Object.values(M(Object.fromEntries(t.entries()))),order:void 0,required:!1};else if(typeof t.content=="string"){let o=t.content;r[n]={applicationOrder:t.applicationOrder??0,content:async()=>o,order:t.order??void 0,required:t.required??!1}}else if(Array.isArray(t.content))r[n]={applicationOrder:t.applicationOrder??0,content:Object.values(M(Object.fromEntries(t.content.entries()))),order:t.order??void 0,required:t.required??!1};else{let o=t.content;r[n]={applicationOrder:t.applicationOrder??0,content:async(i,a)=>o(i,a),order:t.order??void 0,required:t.required??!1}}return he(r),r}function P(e){try{v.parse(e)}catch(r){if(r instanceof Error)throw new TypeError(`Error validating rules: ${r.message}`)}}function he(e){try{we.parse(e)}catch(r){if(r instanceof Error)throw new TypeError(`Error validating rules: ${r.message}`)}}var B=m.any(),G=m.any(),Z=m.lazy(()=>m.object({applicationOrder:m.number(),content:m.union([m.function().args(B.optional(),G.optional()).returns(m.promise(m.string())),m.array(Z)]),order:m.number().optional(),required:m.boolean().default(!1)})),K=m.function().args(B.optional(),G.optional()).returns(m.union([m.string(),m.promise(m.string())])),S=m.lazy(()=>m.union([K,m.array(S),m.string(),m.object({applicationOrder:m.number().optional(),content:m.union([K,m.array(S),m.string()]),order:m.number().optional(),required:m.boolean().optional()})])),v=m.record(S).describe("MDAT Rules"),we=m.record(Z).describe("MDAT Rules");async function C(e,r,n,t=!1){if(Array.isArray(e.content)){let o=[];for(let[i,a]of e.content.entries()){let s=Array.isArray(r)?r.at(i):void 0;try{o.push(await C(a,s??{},n))}catch(l){if(t)throw l}}return o.join(`
1
+ import h from"chalk";var D=process?.versions?.node!==void 0,se={verbose:!1,log(...e){if(!this.verbose)return;let r=h.gray("[Log]");D?console.warn(r,...e):console.log(r,...e)},logPrefixed(e,...r){this.info(h.blue(`[${e}]`),...r)},info(...e){if(!this.verbose)return;let r=h.green("[Info]");D?console.warn(r,...e):console.info(r,...e)},infoPrefixed(e,...r){this.info(h.blue(`[${e}]`),...r)},warn(...e){console.warn(h.yellow("[Warning]"),...e)},warnPrefixed(e,...r){this.warn(h.blue(`[${e}]`),...r)},error(...e){console.error(h.red("[Error]"),...e)},errorPrefixed(e,...r){this.error(h.blue(`[${e}]`),...r)}},y=se;import w from"chalk";import L from"node:path";function p(e,r,o,t,n,i){let a,s;n===void 0||typeof n=="number"?(a=n??0,s=i??0):(a=n?.position?.start.line??0,s=n?.position?.start.column??0);let l={place:{end:{column:s,line:a},start:{column:s,line:a}},source:o},d=e.message(t,l);d.fatal=r==="error"?!0:r==="warn"?!1:void 0}function ae(e){return{column:e.column,level:e.fatal?"error":e.fatal===!1?"warn":"info",line:e.line,message:e.reason,source:e.source}}function le(e){return e.map(r=>J(r))}function J(e){let r={destinationPath:e.history.length>0?e.history.at(-1):void 0,errors:[],infos:[],sourcePath:e.history.at(0)??e.path,warnings:[]};r.sourcePath?.startsWith(".")&&(r.sourcePath=L.relative(process.cwd(),L.join(process.cwd(),r.sourcePath)));for(let o of e.messages){let t=ae(o);t.level==="error"?r.errors.push(t):t.level==="warn"?r.warnings.push(t):r.infos.push(t)}return r}function me(e){for(let r of e){let o=J(r),{destinationPath:t,errors:n,infos:i,sourcePath:a,warnings:s}=o;y.info(`${w.bold("MDAT Report:")}`),y.info(` From: ${w.blue.bold(a)}`),y.info(` To: ${w.blue.bold(t)}`);for(let l of n)y.error(V(a,l));for(let l of s)y.warn(V(a,l));for(let l of i)y.info(V(a,l));n.length===0&&s.length===0?y.info(`No issues found in ${a}`):y.error(`${n.length} errors, ${s.length} warnings found in ${a}`)}}function V(e,r){let{column:o,level:t,line:n,message:i,source:a}=r,s=a?w.gray(`[${a}] `):"",l=n&&o?`:${n}:${o}`:"",d=de(i,t);return`${s}${d} ${w.whiteBright(e+l)}`}function de(e,r){return e.replaceAll(/<!--.+-->/g,o=>r==="info"?w.green(o):r==="warn"?w.yellow(o):w.red(o))}import pe from"json5";import{VFileMessage as b}from"vfile-message";function R(e,r,o){try{let t=ue(e.value,o);return t===void 0?void 0:{...t,node:e,parent:r}}catch(t){throw t instanceof b?(t.line=e.position?.start.line,t):t instanceof Error?new b(t.message,e):new b("Unknown error",e)}}function ue(e,r){if(!fe(e))return;let{closingPrefix:o,keywordPrefix:t,metaCommentIdentifier:n}=r,i=e.trim(),a=i.replace(/^\s*<!--+\s*/,"").replace(/\s*-*-->\s*$/,""),[s,...l]=a.split(/(\s+|\(|{)/),d=s.startsWith(n)?"meta":t!==""&&!s.startsWith(t)&&!s.startsWith(`${o}${t}`)?"native":s.startsWith(o)?"close":"open";if(d==="meta")return{content:ge(a,n),html:i,type:d};if(d==="native")return{content:a,html:i,type:d};let u=s.replace(new RegExp(`^${o}`),"").replace(new RegExp(`^${t}`),""),c=ce(l.join(""));if(d==="open"||d==="close"){let g={};try{g=pe.parse(c)}catch(f){if(f instanceof Error)throw new b(`Failed to parse comment options "${c}" for keyword "${u}": ${f.message}`)}return{closingPrefix:o,html:i,keyword:u,keywordPrefix:t,options:g,type:d}}}function fe(e){let r=e.trim();return r.startsWith("<!--")&&r.endsWith("-->")}function ce(e){return e=e.trim(),e=e.startsWith("(")?e.slice(1):e,e=e.endsWith(")")?e.slice(0,-1):e,e=e.trim(),!e.startsWith("{")&&!e.startsWith("[")&&(e="{"+e),!e.endsWith("}")&&!e.endsWith("]")&&(e+="}"),e}function ge(e,r){return e=e.trim(),e=e.startsWith(r)?e.slice(r.length):e,e=e.endsWith(r)?e.slice(0,-r.length):e,e}import{z as m}from"zod";function M(e){let r={};for(let[o,t]of Object.entries(e))if(typeof t=="string")r[o]={applicationOrder:0,content:async()=>t,order:void 0,required:!1};else if(typeof t=="function")r[o]={applicationOrder:0,content:async(n,i)=>t(n,i),order:void 0,required:!1};else if(Array.isArray(t))r[o]={applicationOrder:0,content:Object.values(M(Object.fromEntries(t.entries()))),order:void 0,required:!1};else if(typeof t.content=="string"){let n=t.content;r[o]={applicationOrder:t.applicationOrder??0,content:async()=>n,order:t.order??void 0,required:t.required??!1}}else if(Array.isArray(t.content))r[o]={applicationOrder:t.applicationOrder??0,content:Object.values(M(Object.fromEntries(t.content.entries()))),order:t.order??void 0,required:t.required??!1};else{let n=t.content;r[o]={applicationOrder:t.applicationOrder??0,content:async(i,a)=>n(i,a),order:t.order??void 0,required:t.required??!1}}return ye(r),r}function P(e){try{v.parse(e)}catch(r){if(r instanceof Error)throw new TypeError(`Error validating rules: ${r.message}`)}}function ye(e){try{he.parse(e)}catch(r){if(r instanceof Error)throw new TypeError(`Error validating rules: ${r.message}`)}}var K=m.any(),B=m.any(),G=m.lazy(()=>m.object({applicationOrder:m.number(),content:m.union([m.function().args(K.optional(),B.optional()).returns(m.promise(m.string())),m.array(G)]),order:m.number().optional(),required:m.boolean().default(!1)})),U=m.function().args(K.optional(),B.optional()).returns(m.union([m.string(),m.promise(m.string())])),S=m.lazy(()=>m.union([U,m.array(S),m.string(),m.object({applicationOrder:m.number().optional(),content:m.union([U,m.array(S),m.string()]),order:m.number().optional(),required:m.boolean().optional()})])),v=m.record(S).describe("MDAT Rules"),he=m.record(G).describe("MDAT Rules");async function C(e,r,o,t=!1){if(Array.isArray(e.content)){let n=[];for(let[i,a]of e.content.entries()){let s=Array.isArray(r)?r.at(i):void 0;try{n.push(await C(a,s??{},o))}catch(l){if(t)throw l}}return n.join(`
2
2
 
3
- `)}try{return await e.content(r,n)}catch(o){if(t)throw o}throw new Error("Failed to expand content")}function ke(e){return Me(e)}function Re(e){let r=Object.keys(e);if(r.length!==1)throw new Error(`Expected exactly one rule, found ${r.length}`);return r[0]}function Me(e){let r=Object.values(e);if(r.length===0)throw new Error('Found no entries in a "sole record" record. This should never happen');if(r.length>1)throw new Error('Found multiple entries in "sole record" record. This should never happen');return r[0]}import Q from"chalk";import Ce from"cli-table3";import{CONTINUE as xe,visit as Oe}from"unist-util-visit";async function F(e,r,n){let{closingPrefix:t,keywordPrefix:o,metaCommentIdentifier:i,paranoid:a=!1,rules:s}=n;P(s);let l=M(s),d=[];Oe(e,"html",(u,f,g)=>{if(g===void 0||f===void 0)return xe;let c=R(u,g,{closingPrefix:t,keywordPrefix:o,metaCommentIdentifier:i});if(c!==void 0){let T=c.type==="open"||c.type==="close"?l[c.keyword]:void 0;d.push({...c,rule:T})}}),$e(r,d,l),Ve(r,d),Se(r,d,n),await be(r,d,e),a&&Te(r,d,l),ve(r,d),Pe(r,d,l,n)}async function be(e,r,n){for(let t of r)if(t.type==="open"&&t.rule!==void 0)try{(await C(t.rule,t.options,n,!0)).trim()===""&&p(e,t.rule.required?"error":"warn","check",`${t.html} returned an empty string.`,t.node)}catch(o){o instanceof Error&&p(e,t.rule.required?"error":"warn","check",`Could not get content for ${t.html}. ${o.message}`,t.node)}}function Pe(e,r,n,t){if(t.keywordPrefix==="")return;let o=Object.keys(n);for(let i of r)i.type==="native"&&o.includes(i.content)&&p(e,"warn","check",`Missing prefix: ${i.html}`,i.node)}function ve(e,r){for(let n of r)n.type==="open"&&n.rule===void 0&&p(e,"warn","check",`Missing rule for: ${n.html}`,n.node)}function Te(e,r,n){for(let[t,o]of Object.entries(n))!o.required&&!r.some(i=>i.type==="open"&&i.keyword===t)&&!Y(o,r)&&p(e,"warn","check",`Missing optional: <!-- ${t} -->`)}function $e(e,r,n){for(let[t,o]of Object.entries(n))o.required&&!r.some(i=>i.type==="open"&&i.keyword===t)&&!Y(o,r)&&p(e,"error","check",`Missing required: <!-- ${t} -->`)}function Y(e,r){return r.reduce((n,t)=>{var o;if(Array.isArray((o=t.rule)==null?void 0:o.content))for(let i of t.rule.content)i.content.toString()===e.content.toString()&&(n=!0);return n},!1)}function Ve(e,r){let n=r.filter(s=>{var l;return s.type==="open"&&((l=s.rule)==null?void 0:l.order)!==void 0}),t=[...n].sort((s,l)=>{var f,g;let d=(f=s.rule)==null?void 0:f.order,u=(g=l.rule)==null?void 0:g.order;if(d===void 0||u===void 0)throw new Error("Unexpected undefined rule order");return d-u}),o=X(n),i=X(t),a=new Ce({head:[Q.bold.red("Current Order"),Q.bold.green("Required Order")],style:{compact:!0}});o.join(",")!==i.join(",")&&(a.push(...o.map((s,l)=>[s,i[l]])),p(e,"error","check",`Out of order:
4
- ${a.toString()}`))}function Se(e,r,n){let{addMetaComment:t}=n,o=r.filter(i=>i.type==="meta").length;t&&o!==1&&p(e,"error","check","Missing meta comment"),!t&&o!==0&&p(e,"error","check","Unexpected meta comment"),o>1&&p(e,"error","check","Multiple meta comments")}function X(e){return e.map((r,n)=>{if(r.type==="open"||r.type==="close")return`${n+1}. ${r.html}`;throw new Error("Unexpected comment type")})}import{CONTINUE as k,visit as Fe}from"unist-util-visit";function E(e,r,n){let t;Fe(e,"html",(o,i,a)=>{if(a===void 0||i===void 0)return k;let s=R(o,a,n);if(s===void 0||s.type==="native")return k;if(s.type==="meta")return a.children.splice(i,1),[k,i];if(s.type==="open")return t=s,k;if(s.type==="close"){if(t===void 0)return p(r,"error","clean","Found closing marker without opening marker",o),k;if(t.parent!==s.parent)return p(r,"error","clean","Opening marker doesn't share a parent",o),k;if(t.keyword!==s.keyword)return p(r,"error","clean","Opening marker doesn't share a keyword",o),k;let l=a.children.indexOf(t.node),u=a.children.indexOf(s.node)-l+1;return a.children.splice(l+1,u-1),t=void 0,[k,i-u+1]}})}import{remark as Ee}from"remark";import ze from"remark-gfm";import{CONTINUE as Ne,visit as We}from"unist-util-visit";async function z(e,r,n){let{addMetaComment:t,closingPrefix:o,keywordPrefix:i,metaCommentIdentifier:a,rules:s}=n;P(s);let l=M(s),d=[];We(e,"html",(u,f,g)=>{if(g===void 0||f===void 0)return Ne;let c=R(u,g,{closingPrefix:o,keywordPrefix:i,metaCommentIdentifier:a});c!==void 0&&c.type==="open"&&l[c.keyword]!==void 0&&d.push(c)}),d.sort((u,f)=>l[u.keyword].applicationOrder-l[f.keyword].applicationOrder);for(let u of d){let{closingPrefix:f,html:g,keyword:c,keywordPrefix:T,node:O,options:te,parent:q}=u,oe=l[c],$="";try{$=await C(oe,te,e),$.trim()===""&&p(r,"error","expand",`Got empty content when expanding ${g}`,O)}catch(H){H instanceof Error&&p(r,"error","expand",`Caught error expanding ${g}, Error message: "${H.message}"`,O);continue}let ne=Ee().use(ze).parse($).children,ie={type:"html",value:`<!-- ${f}${T}${c} -->`},se=q.children.indexOf(O);q.children.splice(se+1,0,...ne,ie),p(r,"info","expand",`Expanded: ${g}`,O)}if(t){let f={type:"html",value:`<!--${a} Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. ${a}-->`};e.children.unshift(f)}}import{fromHtml as Ae}from"hast-util-from-html";import{CONTINUE as N,SKIP as Ie,visit as re}from"unist-util-visit";function W(e,r){re(e,"html",(n,t,o)=>{if(o===void 0||t===void 0)return N;let i=je(n);i.length>1&&(p(r,"warn","split","Multiple comments in a single HTML node.",n),o.children.splice(t,1,{children:i,type:"paragraph"}))})}function je(e){let r=Ae(e.value,{fragment:!0}),n=[];return re(r,t=>{var o,i;return t.type==="root"?N:t.type==="text"?(n.push({position:_(t.position,(o=e.position)==null?void 0:o.start),type:"text",value:ee(e,t)}),N):(n.push({position:_(t.position,(i=e.position)==null?void 0:i.start),type:"html",value:ee(e,t)}),Ie)}),n}function _(e,r){if(!(e===void 0||r===void 0))return{end:{column:e.end.column-1+r.column,line:e.end.line-1+r.line,offset:e.end.offset!==void 0&&r.offset!==void 0?e.end.offset+r.offset:void 0},start:{column:e.start.column-1+r.column,line:e.start.line-1+r.line,offset:e.start.offset!==void 0&&r.offset!==void 0?e.start.offset+r.offset:void 0}}}function ee(e,r){if(r.position===void 0)throw new Error("Hast ElementContent node has no position!");return e.value.slice(r.position.start.offset,r.position.end.offset)}async function A(e,r,n){let{addMetaComment:t,closingPrefix:o,keywordPrefix:i,metaCommentIdentifier:a,rules:s}=n;W(e,r),E(e,r,{closingPrefix:o,keywordPrefix:i,metaCommentIdentifier:a}),await z(e,r,{addMetaComment:t,closingPrefix:o,keywordPrefix:i,metaCommentIdentifier:a,rules:s}),await F(e,r,{addMetaComment:t,closingPrefix:o,keywordPrefix:i,metaCommentIdentifier:a,paranoid:!1,rules:s})}import{deepmerge as qe}from"deepmerge-ts";function I(e){return Array.isArray(e)?e.map(r=>r&&typeof r=="object"?I(r):r).filter(r=>r!==void 0):Object.entries(e).map(([r,n])=>[r,n&&typeof n=="object"?I(n):n]).reduce((r,[n,t])=>t===void 0?r:{...r,[n]:t},{})}function j(...e){let r=e.map((n,t)=>t===0?n:I(n));return qe(...r)}import{z as x}from"zod";var He={addMetaComment:!1,closingPrefix:"/",keywordPrefix:"",metaCommentIdentifier:"+",rules:{mdat:"Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat)."}},De=x.object({addMetaComment:x.boolean().optional(),closingPrefix:x.string().optional(),keywordPrefix:x.string().optional(),metaCommentIdentifier:x.string().optional(),rules:v.optional()}).describe("MDAT Options"),Le=function(e){let r=j(He,e);return async function(n,t){await A(n,t,r)}},Je=Le;export{j as deepMergeDefined,Je as default,me as getMdatReports,ke as getSoleRule,Re as getSoleRuleKey,y as log,A as mdat,F as mdatCheck,E as mdatClean,z as mdatExpand,W as mdatSplit,De as optionsSchema,de as reporterMdat,v as rulesSchema};
3
+ `)}try{return await e.content(r,o)}catch(n){if(t)throw n}throw new Error("Failed to expand content")}function we(e){return Re(e)}function ke(e){let r=Object.keys(e);if(r.length!==1)throw new Error(`Expected exactly one rule, found ${r.length}`);return r[0]}function Re(e){let r=Object.values(e);if(r.length===0)throw new Error('Found no entries in a "sole record" record. This should never happen');if(r.length>1)throw new Error('Found multiple entries in "sole record" record. This should never happen');return r[0]}import Z from"chalk";import Me from"cli-table3";import{CONTINUE as Ce,visit as xe}from"unist-util-visit";async function F(e,r,o){let{closingPrefix:t,keywordPrefix:n,metaCommentIdentifier:i,paranoid:a=!1,rules:s}=o;P(s);let l=M(s),d=[];xe(e,"html",(u,c,g)=>{if(g===void 0||c===void 0)return Ce;let f=R(u,g,{closingPrefix:t,keywordPrefix:n,metaCommentIdentifier:i});if(f!==void 0){let T=f.type==="open"||f.type==="close"?l[f.keyword]:void 0;d.push({...f,rule:T})}}),Te(r,d,l),$e(r,d),Ve(r,d,o),await Oe(r,d,e),a&&ve(r,d,l),Pe(r,d),be(r,d,l,o)}async function Oe(e,r,o){for(let t of r)if(t.type==="open"&&t.rule!==void 0)try{(await C(t.rule,t.options,o,!0)).trim()===""&&p(e,t.rule.required?"error":"warn","check",`${t.html} returned an empty string.`,t.node)}catch(n){n instanceof Error&&p(e,t.rule.required?"error":"warn","check",`Could not get content for ${t.html}. ${n.message}`,t.node)}}function be(e,r,o,t){if(t.keywordPrefix==="")return;let n=Object.keys(o);for(let i of r)i.type==="native"&&n.includes(i.content)&&p(e,"warn","check",`Missing prefix: ${i.html}`,i.node)}function Pe(e,r){for(let o of r)o.type==="open"&&o.rule===void 0&&p(e,"warn","check",`Missing rule for: ${o.html}`,o.node)}function ve(e,r,o){for(let[t,n]of Object.entries(o))!n.required&&!r.some(i=>i.type==="open"&&i.keyword===t)&&!X(n,r)&&p(e,"warn","check",`Missing optional: <!-- ${t} -->`)}function Te(e,r,o){for(let[t,n]of Object.entries(o))n.required&&!r.some(i=>i.type==="open"&&i.keyword===t)&&!X(n,r)&&p(e,"error","check",`Missing required: <!-- ${t} -->`)}function X(e,r){return r.reduce((o,t)=>{if(Array.isArray(t.rule?.content))for(let n of t.rule.content)n.content.toString()===e.content.toString()&&(o=!0);return o},!1)}function $e(e,r){let o=r.filter(s=>s.type==="open"&&s.rule?.order!==void 0),t=[...o].sort((s,l)=>{let d=s.rule?.order,u=l.rule?.order;if(d===void 0||u===void 0)throw new Error("Unexpected undefined rule order");return d-u}),n=Q(o),i=Q(t),a=new Me({head:[Z.bold.red("Current Order"),Z.bold.green("Required Order")],style:{compact:!0}});n.join(",")!==i.join(",")&&(a.push(...n.map((s,l)=>[s,i[l]])),p(e,"error","check",`Out of order:
4
+ ${a.toString()}`))}function Ve(e,r,o){let{addMetaComment:t}=o,n=r.filter(i=>i.type==="meta").length;t&&n!==1&&p(e,"error","check","Missing meta comment"),!t&&n!==0&&p(e,"error","check","Unexpected meta comment"),n>1&&p(e,"error","check","Multiple meta comments")}function Q(e){return e.map((r,o)=>{if(r.type==="open"||r.type==="close")return`${o+1}. ${r.html}`;throw new Error("Unexpected comment type")})}import{CONTINUE as k,visit as Se}from"unist-util-visit";function N(e,r,o){let t;Se(e,"html",(n,i,a)=>{if(a===void 0||i===void 0)return k;let s=R(n,a,o);if(s===void 0||s.type==="native")return k;if(s.type==="meta")return a.children.splice(i,1),[k,i];if(s.type==="open")return t=s,k;if(s.type==="close"){if(t===void 0)return p(r,"error","clean","Found closing marker without opening marker",n),k;if(t.parent!==s.parent)return p(r,"error","clean","Opening marker doesn't share a parent",n),k;if(t.keyword!==s.keyword)return p(r,"error","clean","Opening marker doesn't share a keyword",n),k;let l=a.children.indexOf(t.node),u=a.children.indexOf(s.node)-l+1;return a.children.splice(l+1,u-1),t=void 0,[k,i-u+1]}})}import{remark as Fe}from"remark";import Ne from"remark-gfm";import{CONTINUE as Ee,visit as ze}from"unist-util-visit";async function E(e,r,o){let{addMetaComment:t,closingPrefix:n,keywordPrefix:i,metaCommentIdentifier:a,rules:s}=o;P(s);let l=M(s),d=[];ze(e,"html",(u,c,g)=>{if(g===void 0||c===void 0)return Ee;let f=R(u,g,{closingPrefix:n,keywordPrefix:i,metaCommentIdentifier:a});f!==void 0&&f.type==="open"&&l[f.keyword]!==void 0&&d.push(f)}),d.sort((u,c)=>l[u.keyword].applicationOrder-l[c.keyword].applicationOrder);for(let u of d){let{closingPrefix:c,html:g,keyword:f,keywordPrefix:T,node:O,options:re,parent:q}=u,te=l[f],$="";try{$=await C(te,re,e),$.trim()===""&&p(r,"error","expand",`Got empty content when expanding ${g}`,O)}catch(H){H instanceof Error&&p(r,"error","expand",`Caught error expanding ${g}, Error message: "${H.message}"`,O);continue}let oe=Fe().use(Ne).parse($).children,ne={type:"html",value:`<!-- ${c}${T}${f} -->`},ie=q.children.indexOf(O);q.children.splice(ie+1,0,...oe,ne),p(r,"info","expand",`Expanded: ${g}`,O)}if(t){let c={type:"html",value:`<!--${a} Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. ${a}-->`};e.children.unshift(c)}}import{fromHtml as We}from"hast-util-from-html";import{CONTINUE as z,SKIP as Ae,visit as ee}from"unist-util-visit";function W(e,r){ee(e,"html",(o,t,n)=>{if(n===void 0||t===void 0)return z;let i=Ie(o);i.length>1&&(p(r,"warn","split","Multiple comments in a single HTML node.",o),n.children.splice(t,1,{children:i,type:"paragraph"}))})}function Ie(e){let r=We(e.value,{fragment:!0}),o=[];return ee(r,t=>t.type==="root"?z:t.type==="text"?(o.push({position:Y(t.position,e.position?.start),type:"text",value:_(e,t)}),z):(o.push({position:Y(t.position,e.position?.start),type:"html",value:_(e,t)}),Ae)),o}function Y(e,r){if(!(e===void 0||r===void 0))return{end:{column:e.end.column-1+r.column,line:e.end.line-1+r.line,offset:e.end.offset!==void 0&&r.offset!==void 0?e.end.offset+r.offset:void 0},start:{column:e.start.column-1+r.column,line:e.start.line-1+r.line,offset:e.start.offset!==void 0&&r.offset!==void 0?e.start.offset+r.offset:void 0}}}function _(e,r){if(r.position===void 0)throw new Error("Hast ElementContent node has no position!");return e.value.slice(r.position.start.offset,r.position.end.offset)}async function A(e,r,o){let{addMetaComment:t,closingPrefix:n,keywordPrefix:i,metaCommentIdentifier:a,rules:s}=o;W(e,r),N(e,r,{closingPrefix:n,keywordPrefix:i,metaCommentIdentifier:a}),await E(e,r,{addMetaComment:t,closingPrefix:n,keywordPrefix:i,metaCommentIdentifier:a,rules:s}),await F(e,r,{addMetaComment:t,closingPrefix:n,keywordPrefix:i,metaCommentIdentifier:a,paranoid:!1,rules:s})}import{deepmerge as je}from"deepmerge-ts";function I(e){return Array.isArray(e)?e.map(r=>r&&typeof r=="object"?I(r):r).filter(r=>r!==void 0):Object.entries(e).map(([r,o])=>[r,o&&typeof o=="object"?I(o):o]).reduce((r,[o,t])=>t===void 0?r:{...r,[o]:t},{})}function j(...e){let r=e.map((o,t)=>t===0?o:I(o));return je(...r)}import{z as x}from"zod";var qe={addMetaComment:!1,closingPrefix:"/",keywordPrefix:"",metaCommentIdentifier:"+",rules:{mdat:"Powered by the Markdown Autophagic Template system: [mdat](https://github.com/kitschpatrol/mdat)."}},He=x.object({addMetaComment:x.boolean().optional(),closingPrefix:x.string().optional(),keywordPrefix:x.string().optional(),metaCommentIdentifier:x.string().optional(),rules:v.optional()}).describe("MDAT Options"),De=function(e){let r=j(qe,e);return async function(o,t){await A(o,t,r)}},Le=De;export{j as deepMergeDefined,Le as default,le as getMdatReports,we as getSoleRule,ke as getSoleRuleKey,y as log,A as mdat,F as mdatCheck,N as mdatClean,E as mdatExpand,W as mdatSplit,He as optionsSchema,me as reporterMdat,v as rulesSchema};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-mdat",
3
- "version": "0.6.11",
3
+ "version": "0.6.12",
4
4
  "type": "module",
5
5
  "description": "A remark plugin implementing the Markdown Autophagic Template (MDAT) system.",
6
6
  "repository": {