turnish 1.6.0 → 1.6.2
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.cjs +20 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +15 -15
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +69 -68
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +16 -16
- package/dist/index.umd.js.map +1 -1
- package/dist/types/index.d.ts +6 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";class
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class ce extends Error{reason;filename;line;column;source;constructor(e,n,i,r,s){super(`${e}:${i}:${r}: ${n}`),this.reason=n,this.filename=e,this.line=i,this.column=r,this.source=s}}class le{start;end;source;constructor(e,n,i){this.start=e,this.end=n,this.source=i}}var f;(function(t){t.stylesheet="stylesheet",t.rule="rule",t.declaration="declaration",t.comment="comment",t.container="container",t.charset="charset",t.document="document",t.customMedia="custom-media",t.fontFace="font-face",t.host="host",t.import="import",t.keyframes="keyframes",t.keyframe="keyframe",t.layer="layer",t.media="media",t.namespace="namespace",t.page="page",t.startingStyle="starting-style",t.supports="supports"})(f||(f={}));const U=(t,e,n)=>{let i=n,r=1e4;do{const s=e.map(c=>t.indexOf(c,i));s.push(t.indexOf("\\",i));const l=s.filter(c=>c!==-1);if(l.length===0)return-1;const u=Math.min(...l);if(t[u]!=="\\")return u;i=u+2,r--}while(r>0);throw new Error("Too many escaping")},M=(t,e,n)=>{let i=n,r=1e4;do{const s=e.map(c=>t.indexOf(c,i));s.push(t.indexOf("(",i)),s.push(t.indexOf('"',i)),s.push(t.indexOf("'",i)),s.push(t.indexOf("\\",i));const l=s.filter(c=>c!==-1);if(l.length===0)return-1;const u=Math.min(...l);switch(t[u]){case"\\":i=u+2;break;case"(":{const c=M(t,[")"],u+1);if(c===-1)return-1;i=c+1}break;case'"':{const c=U(t,['"'],u+1);if(c===-1)return-1;i=c+1}break;case"'":{const c=U(t,["'"],u+1);if(c===-1)return-1;i=c+1}break;default:return u}r--}while(r>0);throw new Error("Too many escaping")},w=/\/\*[^]*?(?:\*\/|$)/g;function T(t){return t?t.trim():""}function v(t,e){const n=t&&typeof t.type=="string",i=n?t:e;for(const r in t){const s=t[r];Array.isArray(s)?s.forEach(l=>{v(l,i)}):s&&typeof s=="object"&&v(s,i)}return n&&Object.defineProperty(t,"parent",{configurable:!0,writable:!0,enumerable:!1,value:e||null}),t}class ue{level=0;indentation=" ";compress=!1;constructor(e){typeof e?.indent=="string"&&(this.indentation=e?.indent),e?.compress&&(this.compress=!0)}emit(e,n){return e}indent(e){return this.level=this.level||1,e?(this.level+=e,""):Array(this.level).join(this.indentation)}visit(e){switch(e.type){case f.stylesheet:return this.stylesheet(e);case f.rule:return this.rule(e);case f.declaration:return this.declaration(e);case f.comment:return this.comment(e);case f.container:return this.container(e);case f.charset:return this.charset(e);case f.document:return this.document(e);case f.customMedia:return this.customMedia(e);case f.fontFace:return this.fontFace(e);case f.host:return this.host(e);case f.import:return this.import(e);case f.keyframes:return this.keyframes(e);case f.keyframe:return this.keyframe(e);case f.layer:return this.layer(e);case f.media:return this.media(e);case f.namespace:return this.namespace(e);case f.page:return this.page(e);case f.startingStyle:return this.startingStyle(e);case f.supports:return this.supports(e)}}mapVisit(e,n){let i="";n=n||"";for(let r=0,s=e.length;r<s;r++)i+=this.visit(e[r]),n&&r<s-1&&(i+=this.emit(n));return i}compile(e){return this.compress?e.stylesheet.rules.map(this.visit,this).join(""):this.stylesheet(e)}stylesheet(e){return this.mapVisit(e.stylesheet.rules,`
|
|
2
2
|
|
|
3
3
|
`)}comment(e){return this.compress?this.emit("",e.position):this.emit(`${this.indent()}/*${e.comment}*/`,e.position)}container(e){return this.compress?this.emit(`@container ${e.container}`,e.position)+this.emit("{")+this.mapVisit(e.rules)+this.emit("}"):this.emit(`${this.indent()}@container ${e.container}`,e.position)+this.emit(` {
|
|
4
4
|
${this.indent(1)}`)+this.mapVisit(e.rules,`
|
|
@@ -46,57 +46,57 @@ ${this.indent(1)}`)+this.mapVisit(e.rules,`
|
|
|
46
46
|
`)+this.emit(this.indent(-1))+this.emit(`
|
|
47
47
|
${this.indent()}}`)}declaration(e){return this.compress?this.emit(`${e.property}:${e.value}`,e.position)+this.emit(";"):e.property==="grid-template-areas"?this.emit(this.indent())+this.emit(e.property+": "+e.value.split(`
|
|
48
48
|
`).join(`
|
|
49
|
-
`.padEnd(22)+this.indent()),e.position)+this.emit(";"):this.emit(this.indent())+this.emit(`${e.property}: ${e.value}`,e.position)+this.emit(";")}}const
|
|
50
|
-
`);i=~y?h.length-y:i+h.length})(o),t=t.slice(o.length),a}function E(){const a=/^\s*/.exec(t);a&&m(a)}function d(a){a=a||[];let o
|
|
51
|
-
`;)e--;return t.substring(0,e)}function q(t){return Y(K(t))}const
|
|
52
|
-
`):""}function
|
|
49
|
+
`.padEnd(22)+this.indent()),e.position)+this.emit(";"):this.emit(this.indent())+this.emit(`${e.property}: ${e.value}`,e.position)+this.emit(";")}}const me=(t,e)=>{e=e||{};let n=1,i=1;function r(){const a={line:n,column:i};return o=>(o.position=new le(a,{line:n,column:i},e?.source||""),E(),o)}const s=[];function l(a){const o=new ce(e?.source||"",a,n,i,t);if(!e?.silent)throw o;s.push(o)}function u(){const a=/^{\s*/.exec(t);return!!a&&(m(a),!0)}function c(){const a=/^}/.exec(t);return!!a&&(m(a),!0)}function g(){let a;const o=[];for(E(),d(o);t.length&&t.charAt(0)!=="}"&&(a=oe()||ae(),a);)o.push(a),d(o);return o}function m(a){const o=a[0];return(function(h){const p=h.match(/\n/g);p&&(n+=p.length);const y=h.lastIndexOf(`
|
|
50
|
+
`);i=~y?h.length-y:i+h.length})(o),t=t.slice(o.length),a}function E(){const a=/^\s*/.exec(t);a&&m(a)}function d(a){a=a||[];let o=R();for(;o;)a.push(o),o=R();return a}function R(){const a=r();if(t.charAt(0)!=="/"||t.charAt(1)!=="*")return;const o=/^\/\*[^]*?\*\//.exec(t);return o?(m(o),a({type:f.comment,comment:o[0].slice(2,-2)})):l("End of comment missing")}function V(){const a=/^([^{]+)/.exec(t);if(a)return m(a),((o,h)=>{const p=[];let y=0;for(;y<o.length;){const N=M(o,h,y);if(N===-1)return p.push(o.substring(y)),p;p.push(o.substring(y,N)),y=N+1}return p})(T(a[0]).replace(w,""),[","]).map(o=>T(o))}function $(){const a=r(),o=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/.exec(t);if(!o)return;m(o);const h=T(o[0]),p=/^:\s*/.exec(t);if(!p)return l("property missing ':'");m(p);let y="";const N=M(t,[";","}"]);N!==-1&&(y=t.substring(0,N),m([y]),y=T(y).replace(w,""));const b=a({type:f.declaration,property:h.replace(w,""),value:y}),_=/^[;\s]*/.exec(t);return _&&m(_),b}function H(){const a=[];if(!u())return l("missing '{'");d(a);let o=$();for(;o;)a.push(o),d(a),o=$();return c()?a:l("missing '}'")}function F(){const a=[],o=r();let h=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(t);for(;h;){const p=m(h);a.push(p[1]);const y=/^,\s*/.exec(t);y&&m(y),h=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(t)}if(a.length)return o({type:f.keyframe,values:a,declarations:H()||[]})}const ie=C("import"),re=C("charset"),se=C("namespace");function C(a){const o=new RegExp("^@"+a+`\\s*((?::?[^;'"]|"(?:\\\\"|[^"])*?"|'(?:\\\\'|[^'])*?')+)(?:;|$)`);return()=>{const h=r(),p=o.exec(t);if(!p)return;const y=m(p),N={type:a};return N[a]=y[1].trim(),h(N)}}function oe(){if(t[0]==="@")return(function(){const a=r(),o=/^@([-\w]+)?keyframes\s*/.exec(t);if(!o)return;const h=m(o)[1],p=/^([-\w]+)\s*/.exec(t);if(!p)return l("@keyframes missing name");const y=m(p)[1];if(!u())return l("@keyframes missing '{'");let N=d(),b=F();for(;b;)N.push(b),N=N.concat(d()),b=F();return c()?a({type:f.keyframes,name:y,vendor:h,keyframes:N}):l("@keyframes missing '}'")})()||(function(){const a=r(),o=/^@media *([^{]+)/.exec(t);if(!o)return;const h=T(m(o)[1]);if(!u())return l("@media missing '{'");const p=d().concat(g());return c()?a({type:f.media,media:h,rules:p}):l("@media missing '}'")})()||(function(){const a=r(),o=/^@custom-media\s+(--\S+)\s+([^{;\s][^{;]*);/.exec(t);if(!o)return;const h=m(o);return a({type:f.customMedia,name:T(h[1]),media:T(h[2])})})()||(function(){const a=r(),o=/^@supports *([^{]+)/.exec(t);if(!o)return;const h=T(m(o)[1]);if(!u())return l("@supports missing '{'");const p=d().concat(g());return c()?a({type:f.supports,supports:h,rules:p}):l("@supports missing '}'")})()||ie()||re()||se()||(function(){const a=r(),o=/^@([-\w]+)?document *([^{]+)/.exec(t);if(!o)return;const h=m(o),p=T(h[1]),y=T(h[2]);if(!u())return l("@document missing '{'");const N=d().concat(g());return c()?a({type:f.document,document:y,vendor:p,rules:N}):l("@document missing '}'")})()||(function(){const a=r(),o=/^@page */.exec(t);if(!o)return;m(o);const h=V()||[];if(!u())return l("@page missing '{'");let p=d(),y=$();for(;y;)p.push(y),p=p.concat(d()),y=$();return c()?a({type:f.page,selectors:h,declarations:p}):l("@page missing '}'")})()||(function(){const a=r(),o=/^@host\s*/.exec(t);if(!o)return;if(m(o),!u())return l("@host missing '{'");const h=d().concat(g());return c()?a({type:f.host,rules:h}):l("@host missing '}'")})()||(function(){const a=r(),o=/^@font-face\s*/.exec(t);if(!o)return;if(m(o),!u())return l("@font-face missing '{'");let h=d(),p=$();for(;p;)h.push(p),h=h.concat(d()),p=$();return c()?a({type:f.fontFace,declarations:h}):l("@font-face missing '}'")})()||(function(){const a=r(),o=/^@container *([^{]+)/.exec(t);if(!o)return;const h=T(m(o)[1]);if(!u())return l("@container missing '{'");const p=d().concat(g());return c()?a({type:f.container,container:h,rules:p}):l("@container missing '}'")})()||(function(){const a=r(),o=/^@starting-style\s*/.exec(t);if(!o)return;if(m(o),!u())return l("@starting-style missing '{'");const h=d().concat(g());return c()?a({type:f.startingStyle,rules:h}):l("@starting-style missing '}'")})()||(function(){const a=r(),o=/^@layer *([^{;@]+)/.exec(t);if(!o)return;const h=T(m(o)[1]);if(!u()){const y=/^[;\s]*/.exec(t);return y&&m(y),a({type:f.layer,layer:h})}const p=d().concat(g());return c()?a({type:f.layer,layer:h,rules:p}):l("@layer missing '}'")})()}function ae(){const a=r(),o=V();return o?(d(),a({type:f.rule,selectors:o,declarations:H()||[]})):l("selector missing")}return v((function(){const a=g();return{type:f.stylesheet,stylesheet:{source:e?.source,rules:a,parsingErrors:s}}})())},he=(t,e)=>new ue(e||{}).compile(t);var fe={parse:me,stringify:he};function pe(t,e){const n=t;return n.isBlock=B(n),n.isCode=n.nodeName==="CODE"||n.parentNode?.isCode,n.isBlank=de(n),n.flankingWhitespace=ge(n,e),n}function de(t){return!X(t)&&!Te(t)&&/^\s*$/i.test(t.textContent||"")&&!ke(t)&&!xe(t)}function ge(t,e){const n=t;if(n.isBlock||e.preformattedCode&&n.isCode)return{leading:"",trailing:""};const i=ye(t.textContent||"");return i.leadingAscii&&j("left",t,e)&&(i.leading=i.leadingNonAscii),i.trailingAscii&&j("right",t,e)&&(i.trailing=i.trailingNonAscii),{leading:i.leading,trailing:i.trailing}}function ye(t){const e=t.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);return e?{leading:e[1],leadingAscii:e[2],leadingNonAscii:e[3],trailing:e[4],trailingNonAscii:e[5],trailingAscii:e[6]}:{leading:"",leadingAscii:"",leadingNonAscii:"",trailing:"",trailingNonAscii:"",trailingAscii:""}}function j(t,e,n){let i,r,s;return t==="left"?(i=e.previousSibling,r=/ $/):(i=e.nextSibling,r=/^ /),i&&(i.nodeType===3?s=r.test(i.nodeValue||""):n.preformattedCode&&i.nodeName==="CODE"?s=!1:i.nodeType===1&&!B(i)&&(s=r.test(i.textContent||""))),s||!1}const x={Element:1,Text:3,CDATASection:4,Comment:8};function L(t,e){return Array(e+1).join(t)}function K(t){return t.replace(/^\n*/,"")}function Y(t){let e=t.length;for(;e>0&&t[e-1]===`
|
|
51
|
+
`;)e--;return t.substring(0,e)}function q(t){return Y(K(t))}const Ne=["ADDRESS","ARTICLE","ASIDE","AUDIO","BLOCKQUOTE","BODY","CANVAS","CENTER","DD","DIR","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","FRAMESET","H1","H2","H3","H4","H5","H6","HEADER","HGROUP","HR","HTML","ISINDEX","LI","MAIN","MENU","NAV","NOFRAMES","NOSCRIPT","OL","OUTPUT","P","PRE","SECTION","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","UL"];function B(t){return P(t,Ne)}const Q=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function X(t){return P(t,Q)}function ke(t){return Z(t,Q)}const J=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"],Ee=["P","BR","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","UL","OL","LI","PRE","CODE","HR","A","EM","I","STRONG","B","IMG","DIV","SPAN","TABLE","THEAD","TBODY","TR","TH","TD"];function Te(t){return P(t,J)}function xe(t){return Z(t,J)}function P(t,e){return e.indexOf(t.nodeName)>=0}function Z(t,e){return e.some(function(n){return t.nodeType!==x.Element?!1:t.getElementsByTagName(n).length})}function ee(t){return t?t.replace(/(\n+\s*)+/g,`
|
|
52
|
+
`):""}function Re(t){return ee(t).replace(/[\t\r\n]+/g," ").replace(/ {2,}/g," ").trim()}function A(t){return ee(t).replace(/[\t\r\n]+/g," ")}function $e(t){const e=t.parentNode;return e?e.nodeType===x.Element&&e.classList&&e.classList.contains("code")&&e.nodeName==="TD"&&t.nodeName==="PRE":!1}function be(t){if(t.nodeName!=="PRE"||t.nodeType!==x.Element)return!1;const e=t.getAttribute("style");if(!e)return!1;const n=fe.parse("pre {"+e+"}");if(!n.stylesheet.rules.length)return!1;const i=n.stylesheet.rules[0];if(!("declarations"in i)||!i.declarations)return!1;const r=i.declarations.find(l=>"property"in l?l.property.toLowerCase()==="font-family":!1);return!r||"value"in r&&!r.value?!1:"value"in r&&r.value.split(",").map(l=>l.trim().toLowerCase()).indexOf("monospace")>=0}function te(t){return $e(t)||be(t)?!0:t.nodeName==="PRE"&&t.firstChild&&t.firstChild.nodeName==="CODE"||!1}const k={};k.paragraph={filter:"p",replacement:function(t){return`
|
|
53
53
|
|
|
54
54
|
`+t+`
|
|
55
55
|
|
|
56
|
-
`}};
|
|
57
|
-
`}};
|
|
56
|
+
`}};k.lineBreak={filter:"br",replacement:function(t,e,n){return n.br+`
|
|
57
|
+
`}};k.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(t,e,n){const i=Number(e.nodeName.charAt(1));if(n.headingStyle==="setext"&&i<3){const r=L(i===1?"=":"-",t.length);return`
|
|
58
58
|
|
|
59
59
|
`+t+`
|
|
60
60
|
`+r+`
|
|
61
61
|
|
|
62
62
|
`}else return`
|
|
63
63
|
|
|
64
|
-
`+
|
|
64
|
+
`+L("#",i)+" "+t+`
|
|
65
65
|
|
|
66
|
-
`}};
|
|
66
|
+
`}};k.blockquote={filter:"blockquote",replacement:function(t){return t=q(t).replace(/^/gm,"> "),`
|
|
67
67
|
|
|
68
68
|
`+t+`
|
|
69
69
|
|
|
70
|
-
`}};
|
|
70
|
+
`}};k.list={filter:["ul","ol"],replacement:function(t,e){const n=e.parentNode;return n.nodeName==="LI"&&n.lastElementChild===e?`
|
|
71
71
|
`+t:`
|
|
72
72
|
|
|
73
73
|
`+t+`
|
|
74
74
|
|
|
75
|
-
`}};
|
|
75
|
+
`}};k.listItem={filter:"li",replacement:function(t,e,n){let i=n.bulletListMarker+" ".repeat(n.listMarkerSpaceCount);const r=e.parentNode;if(r.nodeName==="OL"){const d=r.getAttribute("start"),R=Array.prototype.indexOf.call(r.children,e);i=(d?Number(d)+R:R+1)+"."+" ".repeat(n.listMarkerSpaceCount)}const s=/\n$/.test(t);if(t=q(t)+(s?`
|
|
76
76
|
`:""),e.childNodes.length>0&&Array.from(e.childNodes).every(d=>d.nodeType===x.Text&&/^\s*$/.test(d.nodeValue||"")||d.nodeType===x.Element&&["UL","OL"].includes(d.nodeName))&&t.trim()!=="")return t+(e.nextSibling?`
|
|
77
77
|
`:"");let u=0,c=r;for(;c;){if(c.nodeName==="UL"||c.nodeName==="OL"){const d=c.parentNode;d&&d.nodeName==="LI"&&u++}c=c.parentNode}let g=n.listItemIndent==="tab"?" ":" ".repeat(n.listItemIndentSpaceCount),m=g.repeat(u);const E=/\n(?!\s*(?:\d+\.\s|[-+*]\s))/gm;return t=t.replace(E,`
|
|
78
78
|
`+g),m+i+t+(e.nextSibling?`
|
|
79
|
-
`:"")}};
|
|
79
|
+
`:"")}};k.indentedCodeBlock={filter:function(t,e){return!!(e&&e.codeBlockStyle==="indented"&&t.nodeName==="PRE"&&t.firstChild&&t.firstChild.nodeName==="CODE")},replacement:function(t,e){return!e||!e.firstChild?"":`
|
|
80
80
|
|
|
81
81
|
`+e.firstChild.textContent.replace(/\n/g,`
|
|
82
82
|
`)+`
|
|
83
83
|
|
|
84
|
-
`}};
|
|
84
|
+
`}};k.fencedCodeBlock={filter:function(t,e){return!!(e&&e.codeBlockStyle==="fenced"&&t.nodeName==="PRE")},replacement:function(t,e,n){const i=e,r=i.firstChild,s=r&&r.nodeName==="CODE"?r:i,u=((s.getAttribute("class")||"").match(/(?:lang|language)-(\S+)/)||[null,""])[1],c=s.textContent||"",g=n.fence?.charAt(0)||"`";let m=3;const E=new RegExp("^"+g+"{3,}","gm");let d;for(;d=E.exec(c);)d[0].length>=m&&(m=d[0].length+1);const R=L(g,m);return`
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
`+R+u+`
|
|
87
87
|
`+c.replace(/\n$/,"")+`
|
|
88
|
-
|
|
88
|
+
`+R+`
|
|
89
89
|
|
|
90
|
-
`}};
|
|
90
|
+
`}};k.horizontalRule={filter:"hr",replacement:function(t,e,n){return`
|
|
91
91
|
|
|
92
92
|
`+n.hr+`
|
|
93
93
|
|
|
94
|
-
`}};
|
|
94
|
+
`}};k.inlineLink={filter:function(t,e){return!!(e?.linkStyle==="inlined"&&t.nodeName==="A"&&t.getAttribute("href"))},replacement:function(t,e){const n=Re(t);let i=e.getAttribute("href")?.replace(/([()])/g,"\\$1"),r;const s=e.getAttribute("title");return s?r=' "'+A(s).replace(/"/g,'\\"')+'"':r="","["+n+"]("+i+r+")"}};const D={filter:function(t,e){return!!(e&&e.linkStyle==="referenced"&&t.nodeName==="A"&&t.getAttribute("href"))},replacement:function(t,e,n){const i=D,r=e.getAttribute("href");let s;const l=e.getAttribute("title");l?s=' "'+A(l)+'"':s="";const u=r+s;let c,g;switch(n.linkReferenceStyle){case"collapsed":c="["+t+"][]",g="["+t+"]: "+u;break;case"shortcut":c="["+t+"]",g="["+t+"]: "+u;break;default:{let m;const E=i.urlReferenceIdMap.get(u);n.linkReferenceDeduplication==="full"&&E?(m=E,g="["+m+"]: "+r+s):(m=i.references.length+1,i.urlReferenceIdMap.set(u,m),g="["+m+"]: "+r+s,i.references.push(g)),c="["+t+"]["+m+"]";break}}return n.linkReferenceStyle!=="full"&&(n.linkReferenceDeduplication==="full"?i.urlReferenceIdMap.has(u)||(i.urlReferenceIdMap.set(u,1),i.references.push(g)):i.references.push(g)),c},references:[],urlReferenceIdMap:new Map,append:()=>{const t=D;let e="";return t.references&&t.references.length&&(e=`
|
|
95
95
|
|
|
96
96
|
`+t.references.join(`
|
|
97
97
|
`)+`
|
|
98
98
|
|
|
99
|
-
`,t.references=[],t.urlReferenceIdMap=new Map),e}};
|
|
99
|
+
`,t.references=[],t.urlReferenceIdMap=new Map),e}};k.referenceLink=D;k.emphasis={filter:["em","i"],replacement:(t,e,n)=>(t=t.trim(),t?n.emDelimiter+t+n.emDelimiter:"")};k.strong={filter:["strong","b"],replacement:(t,e,n)=>(t=t.trim(),t?n.strongDelimiter+t+n.strongDelimiter:"")};k.code={filter:t=>{const e=t.parentNode,n=te(e);return t.nodeName==="CODE"&&!n},replacement:t=>{const e=t.replace(/\r?\n|\r/g," "),n=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"";let i="`";const r=e.match(/`+/gm)||[];for(;r.includes(i);)i=i+"`";return i+n+e+n+i}};k.image={filter:"img",replacement:function(t,e){const n=e.getAttribute("alt"),i=n?A(n):"",r=e.getAttribute("src")||"",s=e.getAttribute("title"),l=s?A(s):"",u=l?' "'+l+'"':"";return r?"":""}};class ne{options;_keep;_remove;blankRule;keepReplacement;markdownIncludingHtmlReplacement;defaultRule;array;constructor(e){this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.markdownIncludingHtmlReplacement=e.markdownIncludingHtmlReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[];for(const n in e.rules)this.array.push(e.rules[n])}add(e,n){this.array.unshift(n)}keep(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})}remove(e){this._remove.unshift({filter:e,replacement:function(){return""}})}forNode(e){if(e.isBlank)return this.blankRule;if(this.options.htmlRetentionMode==="preserveAll"&&this.isUnsupportedElement(e))return{replacement:this.keepReplacement};if(this.options.htmlRetentionMode==="markdownIncludingHtml"&&this.isUnsupportedElement(e))return{replacement:this.markdownIncludingHtmlReplacement};let n;return(n=O(this.array,e,this.options))||(n=O(this._keep,e,this.options))||(n=O(this._remove,e,this.options))?n:this.defaultRule}isUnsupportedElement(e){const n=e.nodeName;if(n==="PRE"&&e.firstChild&&e.firstChild.nodeName==="CODE"){const i=e.firstChild;if(i.attributes&&i.attributes.length>0){for(let r=0;r<i.attributes.length;r++)if(i.attributes[r].name.toLowerCase()!=="class")return!0}}if(e.attributes&&e.attributes.length>0)switch(n){case"IMG":for(let r=0;r<e.attributes.length;r++){const s=e.attributes[r].name.toLowerCase();if(s!=="src"&&s!=="alt"&&s!=="title")return!0}return!1;case"A":for(let r=0;r<e.attributes.length;r++){const s=e.attributes[r].name.toLowerCase();if(s!=="href"&&s!=="title")return!0}return!1;case"CODE":const i=e.parentNode;if(i&&i.nodeName==="PRE"){for(let r=0;r<e.attributes.length;r++)if(e.attributes[r].name.toLowerCase()!=="class")return!0;return!1}default:return!0}return Ee.indexOf(n)===-1}forEach(e){for(let n=0;n<this.array.length;n++)e(this.array[n],n)}}function O(t,e,n){for(let i=0;i<t.length;i++){const r=t[i];if(Ae(r,e,n))return r}}function Ae(t,e,n){const i=t.filter;if(typeof i=="string"){if(i===e.nodeName.toLowerCase())return!0}else if(Array.isArray(i)){if(i.indexOf(e.nodeName.toLowerCase())>-1)return!0}else if(typeof i=="function"){if(i(e,n))return!0}else throw new TypeError("`filter` needs to be a string, array, or function");return!1}function Ce(t){const e=t.element,n=t.isBlock,i=t.isVoid,r=t.isPre||function(g){return g.nodeName==="PRE"};if(!e.firstChild||r(e))return;let s=null,l=!1,u=null,c=z(u,e,r);for(;c!==e;){if(c.nodeType===x.Text||c.nodeType===x.CDATASection){const m=c;let E=m.data.replace(/[ \r\n\t]+/g," ");if((!s||/ $/.test(s.data))&&!l&&E[0]===" "&&(E=E.substr(1)),!E){c=S(c);continue}m.data=E,s=m}else if(c.nodeType===x.Element)n(c)||c.nodeName==="BR"?(s&&(s.data=s.data.replace(/ $/,"")),s=null,l=!1):i(c)||r(c)?(s=null,l=!0):s&&(l=!1);else{c=S(c);continue}const g=z(u,c,r);u=c,c=g}s&&(s.data=s.data.replace(/ $/,""),s.data||S(s))}function S(t){const e=t.nextSibling??t.parentNode;return t.parentNode&&t.parentNode.removeChild(t),e}function z(t,e,n){return t&&t.parentNode===e||n(e)?e.nextSibling??e.parentNode:e.firstChild??e.nextSibling??e.parentNode}const I=typeof window<"u"?window:typeof globalThis<"u"?globalThis:{};function we(){const t=typeof I.DOMParser<"u"?I.DOMParser:void 0;let e=!1;if(!t)return!1;try{new t().parseFromString("","text/html")&&(e=!0)}catch{}return e}class W{parseFromString(e,n){throw new Error("Not implemented")}}function Oe(){if(typeof window<"u"&&typeof document<"u"&&(typeof process>"u"||process.browser),typeof window<"u"){class t extends W{parseFromString(n,i){const r=document.implementation.createHTMLDocument("");return r.open(),r.write(n),r.close(),r}}return new t}else{const t=require("@mixmark-io/domino");class e extends W{parseFromString(i,r){return t.createDocument(i)}}return new e}}const Se=()=>we()?new I.DOMParser:Oe();function Me(t,{preformattedCode:e}){let n;return typeof t=="string"?n=Le().parseFromString('<x-turnish id="turnish-root">'+t+"</x-turnish>","text/html").getElementById("turnish-root"):n=t.cloneNode(!0),Ce({element:n,isBlock:B,isVoid:X,isPre:e?De:void 0}),n}let ve;function Le(){return ve??=Se()}function De(t){return t.nodeName==="PRE"||t.nodeName==="CODE"}const Ie=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/_/g,"\\_"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/<([^>]*)>/g,"\\<$1\\>"],[/^>/g,"\\>"],[/^(\d+)\. /g,"$1\\. "]],Be={rules:k,headingStyle:"atx",hr:"---",bulletListMarker:"-",listMarkerSpaceCount:1,listItemIndent:"space",listItemIndentSpaceCount:4,codeBlockStyle:"fenced",fence:"```",emDelimiter:"*",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",linkReferenceDeduplication:"full",br:" ",preformattedCode:!1,htmlRetentionMode:"standard",blankReplacement:(t,e)=>e.isBlock?`
|
|
100
100
|
|
|
101
101
|
`:"",keepReplacement:(t,e)=>e.isBlock?`
|
|
102
102
|
|
|
@@ -112,7 +112,7 @@ ${this.indent()}}`)}declaration(e){return this.compress?this.emit(`${e.property}
|
|
|
112
112
|
|
|
113
113
|
`+t+`
|
|
114
114
|
|
|
115
|
-
`:t}};class Pe{options;rules;constructor(e){this.options=Object.assign({},Be,e),this.rules=new
|
|
115
|
+
`:t}};class Pe{options;rules;constructor(e){this.options=Object.assign({},Be,e),this.rules=new ne(this.options)}render(e){if(!Ve(e))throw new TypeError(e+" is not a string, or an element/document/fragment node.");if(e==="")return"";const n=this.process(Me(e,this.options));return this.postProcess(n)}use(e){if(Array.isArray(e))for(let n=0;n<e.length;n++)this.use(e[n]);else if(typeof e=="function")e(this);else throw new TypeError("plugin must be a Function or an Array of Functions");return this}addRule(e,n){return this.rules.add(e,n),this}keep(e){return this.rules.keep(e),this}remove(e){return this.rules.remove(e),this}escape(e){return Ie.reduce(function(n,i){return n.replace(i[0],i[1])},e)}process(e){return Array.from(e.childNodes).reduce((n,i)=>{const r=pe(i,this.options);let s="";if(r.nodeType===x.Text){let l=r.nodeValue??"";if(i.previousSibling&&i.previousSibling.nodeType===x.Element){const u=i.previousSibling;u.nodeName==="INPUT"&&u.getAttribute("type")==="checkbox"&&(l=l.replace(/^\s+/,""))}s=r.isCode?l:this.escape(l)}else r.nodeType===x.Element&&(s=this.replacementForNode(r));return G(n,s)},"")}postProcess(e){for(const n of this.rules.array)n.append&&(e=G(e,n.append(this.options)));return e.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}replacementForNode(e){const n=this.rules.forNode(e);let i=this.process(e);const r=e.flankingWhitespace;return(r.leading||r.trailing)&&(i=i.trim()),r.leading+n.replacement(i,e,this.options)+r.trailing}}function G(t,e){const n=Y(t),i=K(e),r=Math.max(t.length-n.length,e.length-i.length),s=`
|
|
116
116
|
|
|
117
|
-
`.substring(0,r);return n+s+i}function Ve(t){return t!=null&&(typeof t=="string"||t.nodeType&&(t.nodeType===1||t.nodeType===9||t.nodeType===11))}
|
|
117
|
+
`.substring(0,r);return n+s+i}function Ve(t){return t!=null&&(typeof t=="string"||t.nodeType&&(t.nodeType===1||t.nodeType===9||t.nodeType===11))}exports.NodeTypes=x;exports.Rules=ne;exports.default=Pe;exports.isCodeBlock=te;
|
|
118
118
|
//# sourceMappingURL=index.cjs.map
|