Skip to content

Commit 6385b7f

Browse files
committed
Update
1 parent 580a9bd commit 6385b7f

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

Diff for: src/core/render/tpl.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ export function tree(toc, tpl = '<ul class="app-sub-sidebar">{inner}</ul>') {
9090
}
9191

9292
let innerHTML = '';
93-
let title = '';
9493
toc.forEach(node => {
95-
title = node.title.replace(/(<([^>]+)>)/g, '');
94+
const title = node.title.replace(/(<([^>]+)>)/g, '');
9695
innerHTML += `<li><a class="section-link" href="${node.slug}" title="${title}">${node.title}</a></li>`;
9796
if (node.children) {
9897
innerHTML += tree(node.children, tpl);

Diff for: test/unit/render-util.test.js

+22-24
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,28 @@ describe('core/render/utils', () => {
1616
});
1717

1818
describe('core/render/tpl', () => {
19-
describe('remove html tag in tree', () => {
20-
test('remove span and img', () => {
21-
const result = tree([
22-
{
23-
level: 2,
24-
slug: '#/cover?id=basic-usage',
25-
title: '<span style="color:red">Basic usage</span>',
26-
},
27-
{
28-
level: 2,
29-
slug: '#/cover?id=custom-background',
30-
title: 'Custom background',
31-
},
32-
{
33-
level: 2,
34-
slug: '#/cover?id=test',
35-
title:
36-
'<img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test',
37-
},
38-
]);
19+
test('remove html tag in tree', () => {
20+
const result = tree([
21+
{
22+
level: 2,
23+
slug: '#/cover?id=basic-usage',
24+
title: '<span style="color:red">Basic usage</span>',
25+
},
26+
{
27+
level: 2,
28+
slug: '#/cover?id=custom-background',
29+
title: 'Custom background',
30+
},
31+
{
32+
level: 2,
33+
slug: '#/cover?id=test',
34+
title:
35+
'<img src="/docs/_media/favicon.ico" data-origin="/_media/favicon.ico" alt="ico">Test',
36+
},
37+
]);
3938

40-
expect(result).toEqual(
41-
`<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>`
42-
);
43-
});
39+
expect(result).toEqual(
40+
`<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>`
41+
);
4442
});
4543
});

0 commit comments

Comments
 (0)