Removes trailing dash from generated slugs in markdown (#3044)

* fixed header slugs in markdown if ends with a dash

* added changeset

* removes trailing dash only if slug was created

* updated test

* updated change level from patch to minor
This commit is contained in:
Rafid Muhymin Wafi 2022-07-16 15:45:41 +06:00 committed by GitHub
parent 6809a0d289
commit 8530cce14f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': minor
---
fixed generated slugs in markdown that ends with a dash

View file

@ -53,7 +53,11 @@ export default function createCollectHeaders() {
node as any
).value = `<${node.tagName} id={${node.properties.id}}>${raw}</${node.tagName}>`;
} else {
node.properties.id = slugger.slug(text);
let slug = slugger.slug(text);
if (slug.endsWith('-')) slug = slug.slice(0, -1);
node.properties.id = slug;
}
}

View file

@ -54,7 +54,7 @@ describe('expressions', () => {
chai
.expect(code)
.to.equal(
'<h1 id="-foo--is-a-shorthand-for--foo-foo-"><code is:raw>{ foo }</code> is a shorthand for <code is:raw>{ foo: foo }</code></h1>'
'<h1 id="-foo--is-a-shorthand-for--foo-foo"><code is:raw>{ foo }</code> is a shorthand for <code is:raw>{ foo: foo }</code></h1>'
);
});