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

This commit is contained in:
沈唁
2020-12-18 08:09:33 +08:00
committed by GitHub
parent bfdc537e92
commit 76c5e685d7
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -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, '-')
+15
View File
@@ -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', () => {
@@ -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`);
});
});