Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes trailing dash from generated slugs in markdown #3044

Merged
merged 7 commits into from
Jul 16, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-bears-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact that this could break some existing URL hashes means that we'll need to:

  • think this through a bit more than normal: we want to make this change once and only once, if we can help it.
  • time it with other breaking changes, if we have any to go out together
  • message it as a potentially breaking change in the changelog

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. You are right Fred. But then should it be a minor or major change? Will there be a v0.27?

---

fixed generated slugs in markdown that ends with a dash
6 changes: 5 additions & 1 deletion packages/markdown/remark/src/rehype-collect-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/remark/test/expressions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>'
);
});

Expand Down