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

fix: slugs are still broken when headings contain html #1443

Merged
merged 2 commits into from
Dec 18, 2020
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 src/core/render/slugify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function slugify(str) {
let slug = str
.trim()
.replace(/[A-Z]+/g, lower)
.replace(/<[^>\d]+>/g, '')
.replace(/<[^>]+>/g, '')
.replace(re, '')
.replace(/\s/g, '-')
.replace(/-+/g, '-')
Expand Down
15 changes: 15 additions & 0 deletions test/unit/render-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { removeAtag } = require('../../src/core/render/utils');

const { tree } = require(`../../src/core/render/tpl`);

const { slugify } = require(`../../src/core/render/slugify`);

// Suite
// -----------------------------------------------------------------------------
describe('core/render/utils', () => {
Expand Down Expand Up @@ -42,3 +44,16 @@ describe('core/render/tpl', () => {
);
});
});

describe('core/render/slugify', () => {
test('slugify()', () => {
const result = slugify(
`Bla bla bla <svg aria-label="broken" class="broken" viewPort="0 0 1 1"><circle cx="0.5" cy="0.5"/></svg>`
);
const result2 = slugify(
`Another <span style="font-size: 1.2em" class="foo bar baz">broken <span class="aaa">example</span></span>`
);
expect(result).toEqual(`bla-bla-bla-`);
expect(result2).toEqual(`another-broken-example`);
});
});