-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMDEditor.min.js
1 lines (1 loc) · 1.91 KB
/
MDEditor.min.js
1
const MDEditor=function(e){this.options=e,this.EditorDivs=document.querySelectorAll(this.options.div);const i=()=>{this.EditorDivs.forEach(e=>{let i=e.innerHTML,o=i;i=(i=(i=(i=(i=(i=i.replace(/(\*\*\*(.+)\*\*\*)/g,"<strong><i>$2</i></strong>")).replace(/(\*\*(.+)\*\*)/g,"<strong>$2</strong>")).replace(/(\*(.+)\*)/g,"<i>$2</i>")).replace(/(\_\_\_(.+)\_\_\_)/g,"<strong><i>$2</i></strong>")).replace(/(\_\_(.+)\_\_)/g,"<strong>$2</strong>")).replace(/(\_(.+)\_)/g,"<i>$2</i>"),i=t.headingTags(i),i=t.backQuote(i),i=t.codeTag(i),i=t.horizontalRule(i),i=t.imageTag(i),i=t.linkTag(i),i=t.ulList(i),(i=t.markTag(i))!==o&&(e.innerHTML=i)})};const t={makeEditable:()=>{this.EditorDivs.forEach(e=>{e.contentEditable=!0})},headingTags:e=>!1===this.options.headings?e:e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(/\#\#\#\#\#\#\#\# (.+)/g,"<h8>$1</h8>")).replace(/\#\#\#\#\#\#\# (.+)/g,"<h7>$1</h7>")).replace(/\#\#\#\#\#\# (.+)/g,"<h6>$1</h6>")).replace(/\#\#\#\#\# (.+)/g,"<h5>$1</h5>")).replace(/\#\#\#\# (.+)/g,"<h4>$1</h4>")).replace(/\#\#\# (.+)/g,"<h3>$1</h3>")).replace(/\#\# (.+)/g,"<h2>$1</h2>")).replace(/\# (.+)/g,"<h1>$1</h1>")).replace(/\<br\>/,""),backQuote:e=>!1===this.options.quote?e:e=(e=(e=e.replace(/\;/,"")).replace(/\> (.+)/g,"<blockquote>$1</blockquote>")).replace(/\<br\>/,""),codeTag:e=>!1===this.options.code?e:e=e.replace(/\`(.+)\`/g,"<code>$1</code>"),horizontalRule:e=>!1===this.options.horizontalRule?e:e=e.replace(/\-\-\-/g,"<hr>"),linkTag:e=>!1===this.options.links?e:e=e.replace(/\[(.+)\]\((.+)\)/g,'<a href = "$2">$1</a>'),imageTag:e=>!1===this.options.images?e:e=e.replace(/\!\[(.+)\]\((.+)\)/g,'<img src="$2" alt="$1"></img>'),ulList:e=>!1===this.options.ulList?e:e=e.replace(/(\- )/gm,"• "),markTag:e=>!1===this.options.mark?e:e=e.replace(/\=\=(.+)\=\=/,"<mark>$1</mark>")};this.options.editable&&t.makeEditable(),this.render=i,this.getHTML=(()=>{let e=[];return this.EditorDivs.forEach(t=>{i();let o=t.innerHTML;e.push(o)}),e})};