@shelf/table-of-contents 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers/anchorize.js +2 -3
- package/lib/helpers/toc.js +8 -5
- package/package.json +1 -1
package/lib/helpers/anchorize.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { template } from 'lodash-es';
|
|
2
2
|
import { decodeHTML } from 'entities';
|
|
3
3
|
import { getSettings } from '../default-settings.js';
|
|
4
4
|
import { untag } from './untag.js';
|
|
@@ -29,7 +29,6 @@ export function anchorize(src, settingsOverride) {
|
|
|
29
29
|
const untaggedHeader = untag(header);
|
|
30
30
|
const decodedHeader = decodeHTML(untaggedHeader);
|
|
31
31
|
const normalizedHeader = decodedHeader.replace(/\u00a0/g, ' ');
|
|
32
|
-
const displayText = escapeHtml(normalizedHeader);
|
|
33
32
|
const normalizedText = normalizeAnchorText(normalizedHeader);
|
|
34
33
|
const anchorSource = normalizedText || normalizedHeader.trim();
|
|
35
34
|
let data;
|
|
@@ -43,7 +42,7 @@ export function anchorize(src, settingsOverride) {
|
|
|
43
42
|
// Header HTML contents.
|
|
44
43
|
header: header,
|
|
45
44
|
// Un-tagged header HTML contents.
|
|
46
|
-
text:
|
|
45
|
+
text: normalizedHeader,
|
|
47
46
|
// Unique anchor name for this header.
|
|
48
47
|
anchor: unique(names, anchor(anchorSource)),
|
|
49
48
|
// All HTML (including tags) matched by the "headers" RegExp.
|
package/lib/helpers/toc.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { template } from 'lodash-es';
|
|
1
|
+
import { escape as escapeHtml, template } from 'lodash-es';
|
|
2
2
|
import { getSettings } from '../default-settings.js';
|
|
3
3
|
export function toc(headers, settingsOverride) {
|
|
4
4
|
settingsOverride = getSettings(settingsOverride);
|
|
@@ -21,14 +21,17 @@ export function toc(headers, settingsOverride) {
|
|
|
21
21
|
if (levels.length === 0 || header.level > levels[0]) {
|
|
22
22
|
levels.unshift(header.level);
|
|
23
23
|
header.depth = levels.length;
|
|
24
|
-
|
|
25
|
-
tocs
|
|
24
|
+
const templateData = { ...header, text: escapeHtml(header.text) };
|
|
25
|
+
tocs[cursor] += templates.openUL(templateData);
|
|
26
|
+
tocs.push(templates.closeLI(templateData) + templates.closeUL(templateData));
|
|
27
|
+
tocs[cursor] += templates.openLI(templateData);
|
|
26
28
|
}
|
|
27
29
|
else {
|
|
28
30
|
header.depth = levels.length;
|
|
29
|
-
|
|
31
|
+
const templateData = { ...header, text: escapeHtml(header.text) };
|
|
32
|
+
tocs[cursor] += templates.closeLI(templateData);
|
|
33
|
+
tocs[cursor] += templates.openLI(templateData);
|
|
30
34
|
}
|
|
31
|
-
tocs[cursor] += templates.openLI(header);
|
|
32
35
|
});
|
|
33
36
|
// eslint-disable-next-line new-cap
|
|
34
37
|
return templates.TOC({ toc: tocs.join('') });
|