UNPKG

@vuux/editor

Version:

Vue Nuxt 富文本编辑器

22 lines (21 loc) 3.17 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./defaults.cjs"),a=require("./helpers.cjs"),c=require("./rules.cjs");class u{options;parser;constructor(e){this.options=e||p._defaults}space(e){return""}code({text:e,lang:r,escaped:t}){const n=(r||"").match(c.other.notSpaceStart)?.[0],s=e.replace(c.other.endingNewline,"")+` `;return n?'<pre><code class="language-'+a.escape(n)+'">'+(t?s:a.escape(s,!0))+`</code></pre> `:"<pre><code>"+(t?s:a.escape(s,!0))+`</code></pre> `}blockquote({tokens:e}){return`<blockquote> ${this.parser.parse(e)}</blockquote> `}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:r}){return`<h${r}>${this.parser.parseInline(e)}</h${r}> `}hr(e){return`<hr> `}list(e){const r=e.ordered,t=e.start;let n="";for(let l=0;l<e.items.length;l++){const i=e.items[l];n+=this.listitem(i)}const s=r?"ol":"ul",o=r&&t!==1?' start="'+t+'"':"";return"<"+s+o+`> `+n+"</"+s+`> `}listitem(e){let r="";if(e.task){const t=this.checkbox({checked:!!e.checked});e.loose?e.tokens[0]?.type==="paragraph"?(e.tokens[0].text=t+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type==="text"&&(e.tokens[0].tokens[0].text=t+" "+a.escape(e.tokens[0].tokens[0].text),e.tokens[0].tokens[0].escaped=!0)):e.tokens.unshift({type:"text",raw:t+" ",text:t+" ",escaped:!0}):r+=t+" "}return r+=this.parser.parse(e.tokens,!!e.loose),`<li>${r}</li> `}checkbox({checked:e}){return`<span class="${"li-checked"+(e?" is-checked":"")}">${e?`<svg fill="none" viewBox="0 0 24 24"> <path stroke-linejoin="round" stroke-linecap="round" stroke-width="3" stroke="currentColor" d="M4 12L10 18L20 6" /> </svg>`:""}</span>`}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p> `}table(e){let r="",t="";for(let s=0;s<e.header.length;s++)t+=this.tablecell(e.header[s]);r+=this.tablerow({text:t});let n="";for(let s=0;s<e.rows.length;s++){const o=e.rows[s];t="";for(let l=0;l<o.length;l++)t+=this.tablecell(o[l]);n+=this.tablerow({text:t})}return n&&(n=`<tbody>${n}</tbody>`),`<table> <thead> `+r+`</thead> `+n+`</table> `}tablerow({text:e}){return`<tr> ${e}</tr> `}tablecell(e){const r=this.parser.parseInline(e.tokens),t=e.header?"th":"td";return(e.align?`<${t} align="${e.align}">`:`<${t}>`)+r+`</${t}> `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${a.escape(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:r,tokens:t}){const n=this.parser.parseInline(t),s=a.cleanUrl(e);if(s===null)return n;e=s;let o='<a href="'+e+'"';return r&&(o+=' title="'+a.escape(r)+'"'),o+=">"+n+"</a>",o}image({href:e,title:r,text:t,tokens:n}){n&&(t=this.parser.parseInline(n,this.parser.textRenderer));const s=a.cleanUrl(e);if(s===null)return a.escape(t);e=s;let o=`<img src="${e}" alt="${t}"`;return r&&(o+=` title="${a.escape(r)}"`),o+=">",o}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:a.escape(e.text)}}exports._Renderer=u;