From cc5c6cd5950f3f0fb688281b0561e2a0dba4b0bf Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sun, 18 Apr 2021 17:43:39 +0200 Subject: [PATCH] support for h1 hyperlink --- src/components/WPAdapter.svelte | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/components/WPAdapter.svelte b/src/components/WPAdapter.svelte index 3794493..877f23c 100644 --- a/src/components/WPAdapter.svelte +++ b/src/components/WPAdapter.svelte @@ -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 = `${el.innerHTML}` + } }) -
+
{@html content}
@@ -102,6 +118,10 @@ margin-left: -0.7rem; } + div :global(.target-link) { + border-bottom: none; + } + div :global(p.has-background) { padding: 0.5em; }