mirror of
https://github.com/cupcakearmy/nicco.io.git
synced 2024-12-21 23:56:26 +00:00
support for h1 hyperlink
This commit is contained in:
parent
f2c6561efa
commit
cc5c6cd595
@ -25,12 +25,28 @@
|
||||
|
||||
export let content
|
||||
|
||||
function encodeTextToUrl(text) {
|
||||
return text
|
||||
.replace(/[^A-Za-z ]/, '')
|
||||
.replace('/ +/', ' ')
|
||||
.replace(' ', '-')
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
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>
|
||||
|
||||
<div>
|
||||
<div class="adapter">
|
||||
{@html content}
|
||||
</div>
|
||||
|
||||
@ -102,6 +118,10 @@
|
||||
margin-left: -0.7rem;
|
||||
}
|
||||
|
||||
div :global(.target-link) {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
div :global(p.has-background) {
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user