Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Nov 21, 2020
1 parent 580a9bd commit 6385b7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
3 changes: 1 addition & 2 deletions src/core/render/tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ export function tree(toc, tpl = '<ul class="app-sub-sidebar">{inner}</ul>') {
}

let innerHTML = '';
let title = '';
toc.forEach(node => {
title = node.title.replace(/(<([^>]+)>)/g, '');
const title = node.title.replace(/(<([^>]+)>)/g, '');
innerHTML += `<li><a class="section-link" href="${node.slug}" title="${title}">${node.title}</a></li>`;
if (node.children) {
innerHTML += tree(node.children, tpl);
Expand Down
46 changes: 22 additions & 24 deletions test/unit/render-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,28 @@ describe('core/render/utils', () => {
});

describe('core/render/tpl', () => {
describe('remove html tag in tree', () => {
test('remove span and img', () => {
const result = tree([
{
level: 2,
slug: '#/cover?id=basic-usage',
title: '<span style="color:red">Basic usage</span>',
},
{
level: 2,
slug: '#/cover?id=custom-background',
title: 'Custom background',
},
{
level: 2,
slug: '#/cover?id=test',
title:
'<img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test',
},
]);
test('remove html tag in tree', () => {
const result = tree([
{
level: 2,
slug: '#/cover?id=basic-usage',
title: '<span style="color:red">Basic usage</span>',
},
{
level: 2,
slug: '#/cover?id=custom-background',
title: 'Custom background',
},
{
level: 2,
slug: '#/cover?id=test',
title:
'<img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test',
},
]);

expect(result).toEqual(
`<ul class="app-sub-sidebar"><li><a class="section-link" href="#/cover?id=basic-usage" title="Basic usage"><span style="color:red">Basic usage</span></a></li><li><a class="section-link" href="#/cover?id=custom-background" title="Custom background">Custom background</a></li><li><a class="section-link" href="#/cover?id=test" title="Test"><img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test</a></li></ul>`
);
});
expect(result).toEqual(
`<ul class="app-sub-sidebar"><li><a class="section-link" href="#/cover?id=basic-usage" title="Basic usage"><span style="color:red">Basic usage</span></a></li><li><a class="section-link" href="#/cover?id=custom-background" title="Custom background">Custom background</a></li><li><a class="section-link" href="#/cover?id=test" title="Test"><img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test</a></li></ul>`
);
});
});

0 comments on commit 6385b7f

Please sign in to comment.