Skip to content

Commit

Permalink
Merge branch 'develop' into feat/vue-options
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records committed Nov 23, 2020
2 parents 7878c60 + 8ccc202 commit 90b67e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/render/tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export function tree(toc, tpl = '<ul class="app-sub-sidebar">{inner}</ul>') {

let innerHTML = '';
toc.forEach(node => {
innerHTML += `<li><a class="section-link" href="${node.slug}" title="${node.title}">${node.title}</a></li>`;
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
28 changes: 28 additions & 0 deletions test/unit/render-util.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { removeAtag } = require('../../src/core/render/utils');
const { tree } = require(`../../src/core/render/tpl`);

// Suite
// -----------------------------------------------------------------------------
Expand All @@ -13,3 +14,30 @@ describe('core/render/utils', () => {
});
});
});

describe('core/render/tpl', () => {
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>`
);
});
});

0 comments on commit 90b67e2

Please sign in to comment.