mirror of
https://github.com/docsifyjs/docsify.git
synced 2025-12-08 19:55:52 +00:00
fix: title error when sidebar link exists with html tag (#1404)
* fix: title error when sidebar link exists with image * fix #1408 * add test * Update
This commit is contained in:
parent
0806f48531
commit
8ccc202251
@ -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);
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
const { removeAtag } = require(`${SRC_PATH}/core/render/utils`);
|
||||
const { tree } = require(`${SRC_PATH}/core/render/tpl`);
|
||||
|
||||
// Suite
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -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>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user