Skip to content

Commit a278a1b

Browse files
committed
Clean up markdown heading elements
1 parent 86ac9dc commit a278a1b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

render-markdown.html

+15-1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ <h1>Render Markdown</h1>
201201
Array.from(
202202
preview.querySelectorAll('a.heading-link')
203203
).forEach(el => el.replaceWith(el.firstChild));
204+
// Clean up markdown-heading elements
205+
Array.from(
206+
preview.querySelectorAll('div.markdown-heading')
207+
).forEach(el => {
208+
const heading = el.querySelector('.heading-element');
209+
if (heading) {
210+
console.log(heading);
211+
const id = heading.innerText.toLowerCase().replace(/[^a-z0-9]+/g, '-');
212+
const tag = heading.tagName;
213+
heading.setAttribute('id', id);
214+
heading.removeAttribute('class');
215+
el.parentNode.replaceChild(heading, el);
216+
}
217+
});
204218
// Output it to the textarea
205219
output.value = preview.innerHTML.replace(
206220
/<h([1-6])>\n/g, '<h$1>'
@@ -243,4 +257,4 @@ <h1>Render Markdown</h1>
243257
</script>
244258

245259
</body>
246-
</html>
260+
</html>

0 commit comments

Comments
 (0)