FIX: Generate valid heading ids (#14840)

This commit is contained in:
Bianca Nenciu 2021-11-08 20:44:46 +02:00 committed by GitHub
parent 9ddb3a9ca6
commit 7fb693c8f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -701,6 +701,16 @@ eviltrout</p>
); );
}); });
test("Heading anchors are valid", function (assert) {
assert.cooked(
"# One\n\n# 1\n\n# $$",
'<h1><a name="one-1" class="anchor" href="#one-1"></a>One</h1>\n' +
'<h1><a name="h-1-2" class="anchor" href="#h-1-2"></a>1</h1>\n' +
'<h1><a name="h-3" class="anchor" href="#h-3"></a>$$</h1>',
"It will bold the heading"
);
});
test("bold and italics", function (assert) { test("bold and italics", function (assert) {
assert.cooked( assert.cooked(
'a "**hello**"', 'a "**hello**"',

View File

@ -39,7 +39,11 @@ export function setup(helper) {
.replace(/^-+/, "") .replace(/^-+/, "")
.replace(/-+$/, ""); .replace(/-+$/, "");
slug = `${slug || "heading"}-${++headingId}`; if (slug.match(/^[^a-z]/)) {
slug = `h-${slug}`;
}
slug = `${slug || "h"}-${++headingId}`;
linkOpen.attrSet("name", slug); linkOpen.attrSet("name", slug);
linkOpen.attrSet("class", "anchor"); linkOpen.attrSet("class", "anchor");