mirror of
https://github.com/aljazceru/pear-docs.git
synced 2025-12-17 14:34:19 +01:00
@@ -68,10 +68,20 @@ customElements.define('docs-viewer', class extends HTMLElement {
|
||||
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] })
|
||||
}
|
||||
|
||||
patchSyntax(input) {
|
||||
// remove backticks inside link, example: [`hypercore`] -> [hypercore]
|
||||
let output = input.replace(/\[`([^`]+)`\]/g, "[$1]")
|
||||
|
||||
// remove gitbook embed syntax
|
||||
output = output.replace(/{% embed url="([^"]+)" %}\s*(.*?)\s*{% embeded %}/g, '> [$2]($1)')
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
async load (page = '/') {
|
||||
if (page === '/') page = this.entry
|
||||
const html = await fetch(page)
|
||||
const text = await marked.parse((await html.text()).replace(/\[`([^`]+)`\]/g, "[$1]")) // remove backticks inside link, example: [`hypercore`] -> [hypercore]
|
||||
const text = await marked.parse(this.patchSyntax(await html.text()))
|
||||
this.panel.querySelector('slot').innerHTML = text
|
||||
this.panel.style.display = ''
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user