-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
560 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "zero-md", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"authors": [ | ||
"Jason Lee <[email protected]>" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "zero-md", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"authors": [ | ||
"Jason Lee <[email protected]>" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<script>(function(){window.customElements.define("zero-md",class extends HTMLElement{get version(){return"v1.3.2"}get src(){return this.getAttribute("src")}get manualRender(){return this.hasAttribute("manual-render")}get noShadow(){return this.hasAttribute("no-shadow")}get markedUrl(){return this.getAttribute("marked-url")||window.ZeroMd.config.markedUrl}get prismUrl(){return this.getAttribute("prism-url")||window.ZeroMd.config.prismUrl}get cssUrls(){let a=this.getAttribute("css-urls");return a?JSON.parse(a):window.ZeroMd.config.cssUrls}constructor(){super(),window.ZeroMd=window.ZeroMd||{},window.ZeroMd.config=window.ZeroMd.config||{},window.ZeroMd.config.markedUrl=window.ZeroMd.config.markedUrl||"https://cdn.jsdelivr.net/npm/marked@0/marked.min.js",window.ZeroMd.config.prismUrl=window.ZeroMd.config.prismUrl||"https://cdn.jsdelivr.net/npm/prismjs@1/prism.min.js",window.ZeroMd.config.cssUrls=window.ZeroMd.config.cssUrls||["https://cdn.jsdelivr.net/npm/github-markdown-css@2/github-markdown.min.css","https://cdn.jsdelivr.net/npm/prismjs@1/themes/prism.min.css"],window.ZeroMd.cache=window.ZeroMd.cache||{}}connectedCallback(){this.addEventListener("click",this._hijackLinks.bind(this)),this.addEventListener("zero-md-rendered",function a(){this.removeEventListener("zero-md-rendered",a),window.setTimeout(()=>{this._scrollTo(window.location.hash)})}.bind(this)),this.manualRender||this.render(),this._fire("zero-md-ready")}_fire(a){this.dispatchEvent(new CustomEvent(a,{bubbles:!0,composed:!0}))}_ajaxGet(a){return new Promise((b,c)=>{if(!a)return void c(a);let d=new XMLHttpRequest,e=b=>{console.warn("[zero-md] Error getting file",a),c(b)};d.open("GET",a,!0),d.onload=()=>{200<=d.status&&400>d.status?b(d.responseText):e(d)},d.onerror=a=>e(a),d.send()})}_loadScript(a,b,c,...d){return new Promise((e,f)=>{if("undefined"!==b)return void e();if(window.ZeroMd.cache.hasOwnProperty(c))window.addEventListener(c,function a(){window.removeEventListener(c,a),e()});else{window.ZeroMd.cache[c]=!0;let b=document.createElement("script");for(let a of d)b.setAttribute(a,"");b.onload=()=>{this._fire(c),e()},b.onerror=b=>{console.warn("[zero-md] Error loading script",a),f(b)},b.src=a,document.head.appendChild(b)}})}_getStylesheet(a){return new Promise((b,c)=>{window.ZeroMd.cache[a]?window.ZeroMd.cache[a].loaded?b(window.ZeroMd.cache[a].data):window.addEventListener(a,function c(){window.removeEventListener(a,c),b(window.ZeroMd.cache[a].data)}):(window.ZeroMd.cache[a]={loaded:!1,data:""},this._ajaxGet(a).then(c=>{window.ZeroMd.cache[a].data=c,window.ZeroMd.cache[a].loaded=!0,this._fire(a),b(c)},a=>c(a)))})}_getInputs(){return new Promise((a,b)=>{let c=this.querySelector("template")&&this.querySelector("template").content.querySelector("xmp")||!1;return c?void a(c.textContent):void this._ajaxGet(this.src).then(b=>a(b)).catch(a=>b(a))})}_prismHighlight(a,b){return window.Prism.highlight(a,this._detectLang(a,b))}_detectLang(a,b){return b?window.Prism.languages.hasOwnProperty(b)?window.Prism.languages[b]:"es"===b.substr(0,2)?window.Prism.languages.javascript:"c"===b?window.Prism.langauges.clike:window.Prism.languages.markup:a.match(/^\s*</)?window.Prism.languages.markup:window.Prism.languages.javascript}_stampDom(a){let b=this.querySelectorAll("[class^=markdown]");if(b&&b.forEach(a=>this.removeChild(a)),this.shadowRoot&&(this.shadowRoot.innerHTML=""),this.noShadow)this.insertAdjacentHTML("afterbegin",a);else{let b=this.shadowRoot||this.attachShadow({mode:"open"});b.innerHTML=a}}_buildMd(){return new Promise((a,b)=>{Promise.all([this._getInputs(),this._loadScript(this.markedUrl,typeof window.marked,"zero-md-marked-ready","async"),this._loadScript(this.prismUrl,typeof window.Prism,"zero-md-prism-ready","async","data-manual")]).then(b=>{a("<div class=\"markdown-body\">"+window.marked(b[0],{highlight:this._prismHighlight.bind(this)})+"</div>")},a=>{b(a)})})}_buildStyles(){return new Promise(a=>{let b="<style class=\"markdown-style\">:host{display:block;position:relative;contain:content;}",c="</style>",d=this.querySelector("template")&&this.querySelector("template").content.querySelector("style")||!1;return d?void a("<style class=\"markdown-style\">:host{display:block;position:relative;contain:content;}"+d.textContent+c):void(Array.isArray(this.cssUrls)&&this.cssUrls.length?Promise.all(this.cssUrls.map(a=>this._getStylesheet(a))).then(d=>a(b+d.join("")+c)).catch(()=>a(b+c)):(console.warn("[zero-md] No styles are defined"),a("<style class=\"markdown-style\">:host{display:block;position:relative;contain:content;}"+c)))})}_scrollTo(a){if(a&&this.shadowRoot){let b=this.shadowRoot.getElementById(a.substr(1));b&&b.scrollIntoView()}}_hijackLinks(a){let b=a.path||a.composedPath();if("A"===b[0].tagName){const c=b[0];c.hash&&c.origin+c.pathname===window.location.origin+window.location.pathname&&(a.metaKey?window.open(c.href,"_blank"):(this._scrollTo(c.hash),window.location=c.href),a.preventDefault())}}render(){Promise.all([this._buildStyles(),this._buildMd()]).then(a=>{this._stampDom(a[0]+a[1]),this._fire("zero-md-rendered")})}})})(window,document);</script> | ||
<script>(function(){window.customElements.define("zero-md",class extends HTMLElement{get version(){return"v1.3.3"}get src(){return this.getAttribute("src")}get manualRender(){return this.hasAttribute("manual-render")}get noShadow(){return this.hasAttribute("no-shadow")}get markedUrl(){return this.getAttribute("marked-url")||window.ZeroMd.config.markedUrl}get prismUrl(){return this.getAttribute("prism-url")||window.ZeroMd.config.prismUrl}get cssUrls(){let a=this.getAttribute("css-urls");return a?JSON.parse(a):window.ZeroMd.config.cssUrls}constructor(){super(),window.ZeroMd=window.ZeroMd||{},window.ZeroMd.config=window.ZeroMd.config||{},window.ZeroMd.config.markedUrl=window.ZeroMd.config.markedUrl||"https://cdn.jsdelivr.net/npm/marked@0/marked.min.js",window.ZeroMd.config.prismUrl=window.ZeroMd.config.prismUrl||"https://cdn.jsdelivr.net/npm/prismjs@1/prism.min.js",window.ZeroMd.config.cssUrls=window.ZeroMd.config.cssUrls||["https://cdn.jsdelivr.net/npm/github-markdown-css@2/github-markdown.min.css","https://cdn.jsdelivr.net/npm/prismjs@1/themes/prism.min.css"],window.ZeroMd.cache=window.ZeroMd.cache||{}}connectedCallback(){this.addEventListener("click",this._hijackLinks.bind(this)),this.addEventListener("zero-md-rendered",function a(){this.removeEventListener("zero-md-rendered",a),window.setTimeout(()=>{this._scrollTo(window.location.hash)})}.bind(this)),this.manualRender||this.render(),this._fire("zero-md-ready")}_fire(a){this.dispatchEvent(new CustomEvent(a,{bubbles:!0,composed:!0}))}_ajaxGet(a){return new Promise((b,c)=>{if(!a)return void c(a);let d=new XMLHttpRequest,e=b=>{console.warn("[zero-md] Error getting file",a),c(b)};d.open("GET",a,!0),d.onload=()=>{200<=d.status&&400>d.status?b(d.responseText):e(d)},d.onerror=a=>e(a),d.send()})}_loadScript(a,b,c,...d){return new Promise((e,f)=>{if("undefined"!==b)return void e();if(window.ZeroMd.cache.hasOwnProperty(c))window.addEventListener(c,function a(){window.removeEventListener(c,a),e()});else{window.ZeroMd.cache[c]=!0;let b=document.createElement("script");for(let a of d)b.setAttribute(a,"");b.onload=()=>{this._fire(c),e()},b.onerror=b=>{console.warn("[zero-md] Error loading script",a),f(b)},b.src=a,document.head.appendChild(b)}})}_getStylesheet(a){return new Promise((b,c)=>{window.ZeroMd.cache[a]?window.ZeroMd.cache[a].loaded?b(window.ZeroMd.cache[a].data):window.addEventListener(a,function c(){window.removeEventListener(a,c),b(window.ZeroMd.cache[a].data)}):(window.ZeroMd.cache[a]={loaded:!1,data:""},this._ajaxGet(a).then(c=>{window.ZeroMd.cache[a].data=c,window.ZeroMd.cache[a].loaded=!0,this._fire(a),b(c)},a=>c(a)))})}_getInputs(){return new Promise((a,b)=>{let c=this.querySelector("template")&&this.querySelector("template").content.querySelector("xmp")||!1;return c?void a(c.textContent):void this._ajaxGet(this.src).then(b=>a(b)).catch(a=>b(a))})}_prismHighlight(a,b){return window.Prism.highlight(a,this._detectLang(a,b))}_detectLang(a,b){return b?window.Prism.languages.hasOwnProperty(b)?window.Prism.languages[b]:"es"===b.substr(0,2)?window.Prism.languages.javascript:"c"===b?window.Prism.languages.clike:window.Prism.languages.markup:a.match(/^\s*</)?window.Prism.languages.markup:window.Prism.languages.javascript}_stampDom(a){let b=this.querySelectorAll("[class^=markdown]");if(b&&b.forEach(a=>this.removeChild(a)),this.shadowRoot&&(this.shadowRoot.innerHTML=""),this.noShadow)this.insertAdjacentHTML("afterbegin",a);else{let b=this.shadowRoot||this.attachShadow({mode:"open"});b.innerHTML=a}}_buildMd(){return new Promise((a,b)=>{Promise.all([this._getInputs(),this._loadScript(this.markedUrl,typeof window.marked,"zero-md-marked-ready","async"),this._loadScript(this.prismUrl,typeof window.Prism,"zero-md-prism-ready","async","data-manual")]).then(b=>{a("<div class=\"markdown-body\">"+window.marked(b[0],{highlight:this._prismHighlight.bind(this)})+"</div>")},a=>{b(a)})})}_buildStyles(){return new Promise(a=>{let b="<style class=\"markdown-style\">:host{display:block;position:relative;contain:content;}",c="</style>",d=this.querySelector("template")&&this.querySelector("template").content.querySelector("style")||!1;return d?void a("<style class=\"markdown-style\">:host{display:block;position:relative;contain:content;}"+d.textContent+c):void(Array.isArray(this.cssUrls)&&this.cssUrls.length?Promise.all(this.cssUrls.map(a=>this._getStylesheet(a))).then(d=>a(b+d.join("")+c)).catch(()=>a(b+c)):(console.warn("[zero-md] No styles are defined"),a("<style class=\"markdown-style\">:host{display:block;position:relative;contain:content;}"+c)))})}_scrollTo(a){if(a&&this.shadowRoot){let b=this.shadowRoot.getElementById(a.substr(1));b&&b.scrollIntoView()}}_hijackLinks(a){let b=a.path||a.composedPath();if("A"===b[0].tagName){const c=b[0];c.hash&&c.origin+c.pathname===window.location.origin+window.location.pathname&&(a.metaKey?window.open(c.href,"_blank"):(this._scrollTo(c.hash),window.location=c.href),a.preventDefault())}}render(){Promise.all([this._buildStyles(),this._buildMd()]).then(a=>{this._stampDom(a[0]+a[1]),this._fire("zero-md-rendered")})}})})(window,document);</script> |
Oops, something went wrong.