Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/repl-sdk/src/compilers/markdown/heading-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function extractText(children) {
* @param {string} value
*/
function formatDefaultId(value) {
return kebabCase(value.replaceAll(/\\s+/g, ' ').trim());
return kebabCase(value.replaceAll(/\s+/g, ' ').trim());
}

/**
Expand Down
18 changes: 18 additions & 0 deletions packages/repl-sdk/src/compilers/markdown/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,24 @@ describe('default features', () => {
});
});

describe('heading ids', () => {
it('collapses runs of whitespace in the heading text', async () => {
const result = await parseMarkdown(`## Hello World `, { ...defaults });

// Only the id is normalized; the rendered text keeps the author's spacing.
expect(result.text).toContain('id="hello-world"');
});

it('treats a literal \\s in a heading as text, not as whitespace', async () => {
// The regex in formatDefaultId used to be /\\s+/g -- a literal backslash
// followed by `s`, rather than whitespace -- so `\s` here was replaced with
// a space and the `s` vanished from the id.
const result = await parseMarkdown(`## a \\s b`, { ...defaults });

expect(result.text).toContain('id="a-s-b"');
});
});

describe('options', () => {
describe('remarkPlugins', () => {
it('works', async () => {
Expand Down
Loading