mirror of
https://github.com/cupcakearmy/nicco.io.git
synced 2024-12-22 08:06:29 +00:00
support for h1 hyperlink
This commit is contained in:
parent
f2c6561efa
commit
cc5c6cd595
@ -25,12 +25,28 @@
|
|||||||
|
|
||||||
export let content
|
export let content
|
||||||
|
|
||||||
|
function encodeTextToUrl(text) {
|
||||||
|
return text
|
||||||
|
.replace(/[^A-Za-z ]/, '')
|
||||||
|
.replace('/ +/', ' ')
|
||||||
|
.replace(' ', '-')
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
hljs.highlightAll()
|
hljs.highlightAll()
|
||||||
|
|
||||||
|
const selector = [1, 2, 3, 4, 5, 6]
|
||||||
|
.map((i) => `div.adapter h${i}`)
|
||||||
|
.join(', ')
|
||||||
|
const elements = window.document.querySelectorAll(selector)
|
||||||
|
for (const el of elements) {
|
||||||
|
const hash = encodeTextToUrl(el.textContent)
|
||||||
|
el.innerHTML = `<a class="target-link" name="${hash}" href="${window.location.pathname}#${hash}">${el.innerHTML}</a>`
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div class="adapter">
|
||||||
{@html content}
|
{@html content}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -102,6 +118,10 @@
|
|||||||
margin-left: -0.7rem;
|
margin-left: -0.7rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div :global(.target-link) {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
div :global(p.has-background) {
|
div :global(p.has-background) {
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user