Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/plugins/helper/toc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tocObj, escapeHTML, encodeURL } from 'hexo-util';
import { tocObj, escapeHTML } from 'hexo-util';

interface Options {
min_depth?: number;
Expand Down Expand Up @@ -51,7 +51,7 @@ function tocHelper(str: string, options: Options = {}) {
for (let i = 0, len = data.length; i < len; i++) {
const el = data[i];
const { level, id, text } = el;
const href = id ? `#${encodeURL(id)}` : null;
const href = id ? `#${encodeURI(id)}` : null;

if (!el.unnumbered) {
lastNumber[level - 1]++;
Expand Down
15 changes: 10 additions & 5 deletions test/scripts/helpers/toc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { encodeURL, escapeHTML } from 'hexo-util';
import { escapeHTML } from 'hexo-util';
import toc from '../../../lib/plugins/helper/toc';

describe('toc', () => {
Expand Down Expand Up @@ -389,22 +389,27 @@ describe('toc', () => {
const des = de.replace(/-/g, ' ');
const ru = 'Я-люблю-русский';
const rus = ru.replace(/-/g, ' ');
const special = '%20';
const input = [
`<h1 id="${zh}">${zhs}</h1>`,
`<h1 id="${de}">${des}</h1>`,
`<h1 id="${ru}">${rus}</h1>`
`<h1 id="${ru}">${rus}</h1>`,
`<h1 id="${special}">${special}</h1>`
].join('');

const expected = [
`<ol class="${className}">`,
`<li class="${className}-item ${className}-level-1">`,
`<a class="${className}-link" href="#${encodeURL(zh)}"><span class="${className}-text">${zhs}</span></a>`,
`<a class="${className}-link" href="#${encodeURI(zh)}"><span class="${className}-text">${zhs}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a class="${className}-link" href="#${encodeURL(de)}"><span class="${className}-text">${des}</span></a>`,
`<a class="${className}-link" href="#${encodeURI(de)}"><span class="${className}-text">${des}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a class="${className}-link" href="#${encodeURL(ru)}"><span class="${className}-text">${rus}</span></a>`,
`<a class="${className}-link" href="#${encodeURI(ru)}"><span class="${className}-text">${rus}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a class="${className}-link" href="#${encodeURI(special)}"><span class="${className}-text">${special}</span></a>`,
'</li></ol>'
].join('');

Expand Down
Loading