-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbetterEmbed.min.js
5 lines (5 loc) · 1.5 KB
/
betterEmbed.min.js
1
2
3
4
5
const PMEregexGetImport=/<!-- embedImport:start:(.*?) -->(.*?)<!-- embedImport:end:(.*?) -->/gs,PMEregexReplaceImport=e=>new RegExp(`<!-- embedImport:start:${e} -->(.*?)<!-- embedImport:end:${e} -->`,"gs"),PMEregexGetImportName=/<!-- embedImport:start:(.*?) -->/g,PMEregexGetEmbedImportName=/^(.*?).md#(.*?) ':include'\)$/gm;function PMEcreateElementFromHTML(e){var t=document.createElement("div");return t.innerHTML=e.trim(),t}function partialMarkdownEmbed(n,e){n.beforeEach(m=>{if(PMEregexGetEmbedImportName.test(m))return m.match(PMEregexGetEmbedImportName).forEach(e=>{var t=e.split(".md#")[1].split(" ':include')")[0],r=e.replace("#"+t,"");m=m.replace(e,`
<!-- embedImport:start:${t} -->
${r}
<!-- embedImport:end:${t} -->
`)}),m}),n.afterEach(a=>{if(PMEregexGetImport.test(a))return a.match(PMEregexGetImport).forEach(e=>{var t,r=PMEcreateElementFromHTML(e);const m=[];for(let e=1;e<6;e++)0===m.length&&0!==(t=r.querySelectorAll("div > h"+e)).length&&t.forEach(e=>m.push(e.id));n.doneEach(()=>{const t=window.location.hash.split("?id=")[0];m.forEach(e=>{document.querySelectorAll(`.section-link[href='${t}?id=${e}']`).forEach(e=>{e.parentElement.nextElementSibling.remove(),e.parentElement.remove()})})});var o=e.match(PMEregexGetImportName)[0].split("\x3c!-- embedImport:start:")[1].split(" --\x3e")[0],e=e.split(`<!-- embed:start:${o} -->`)[1].split(`<!-- embed:end:${o} -->`)[0];a=a.replace(PMEregexReplaceImport(o),e)}),a})}window.$docsify=window.$docsify||{},$docsify.plugins=[partialMarkdownEmbed,...$docsify.plugins||[]];