pretty-toc 1.1.2 → 1.1.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/README.md +41 -2
- package/dist/index.mjs +93 -89
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,50 @@
|
|
|
1
|
+
[](https://github.com/Virgil-N/pretty-toc/actions/workflows/codeql.yml)
|
|
2
|
+
[](https://github.com/Virgil-N/pretty-toc/actions/workflows/verify-and-release.yml)
|
|
3
|
+
|
|
1
4
|
A Table of Contents generation plugin for the Satteri markdown parser library.
|
|
2
5
|
|
|
3
6
|
## Install
|
|
4
7
|
|
|
5
8
|
```
|
|
9
|
+
// install with npm
|
|
6
10
|
npm install pretty-toc --save-dev
|
|
11
|
+
|
|
12
|
+
// install with pnpm
|
|
13
|
+
pnpm install pretty-toc --save-dev
|
|
14
|
+
|
|
15
|
+
// install with yarn
|
|
16
|
+
yarn add -D pretty-toc
|
|
17
|
+
|
|
18
|
+
// install with bun
|
|
19
|
+
bun add -D pretty-toc
|
|
20
|
+
|
|
21
|
+
// install with deno
|
|
22
|
+
deno add -D pretty-toc
|
|
7
23
|
```
|
|
8
24
|
|
|
25
|
+
## Table of Contents
|
|
26
|
+
|
|
27
|
+
- [Screenshots](#Screenshots)
|
|
28
|
+
- [Example](#Example)
|
|
29
|
+
- [Options](#Options)
|
|
30
|
+
|
|
31
|
+
## Screenshots
|
|
32
|
+
|
|
33
|
+
- icon
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
- image
|
|
37
|
+

|
|
38
|
+
|
|
39
|
+
- dot
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
- decimal
|
|
43
|
+

|
|
44
|
+
|
|
45
|
+
- nested image
|
|
46
|
+

|
|
47
|
+
|
|
9
48
|
## Example
|
|
10
49
|
|
|
11
50
|
```javascript
|
|
@@ -76,7 +115,7 @@ processor: satteri({
|
|
|
76
115
|
}),
|
|
77
116
|
```
|
|
78
117
|
|
|
79
|
-
##
|
|
118
|
+
## Options
|
|
80
119
|
|
|
81
120
|
|Property|Type|Default Value|Preset Value|Info|
|
|
82
121
|
|:---|:---|:---|:---|:--|
|
|
@@ -88,7 +127,7 @@ processor: satteri({
|
|
|
88
127
|
|listStyle|string or undefined|undefined|decimal|eg. disc, circle, decimal, none... or icon and image|
|
|
89
128
|
|icon|string or string[] or undefined|undefined|decimal|listStyle must already be set.|
|
|
90
129
|
|image|string or string[] or undefined|undefined|404 image|listStyle must already be set.|
|
|
91
|
-
|liMarkerCssSize|string or undefined|undefined|
|
|
130
|
+
|liMarkerCssSize|string or undefined|undefined|1rem|CSS property value|
|
|
92
131
|
|lightThemeHighlightColor|string or undefined|undefined|oklch(0.75 0.1229 12.71)|-|
|
|
93
132
|
|darkThemeHighlightColor|string or undefined|undefined|oklch(0.81 0.1004 305.04)|-|
|
|
94
133
|
|animation|boolean or { duration: string, timingFunction: string } or undefined|undefined|{ duration: "0.8s", timingFunction: 'ease-in-out' }|-|
|
package/dist/index.mjs
CHANGED
|
@@ -213,107 +213,111 @@ function prettyToc(option) {
|
|
|
213
213
|
color: ${darkThemeHighlightColor};
|
|
214
214
|
}
|
|
215
215
|
`;
|
|
216
|
-
const iframeContent =
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
<
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
216
|
+
const iframeContent = `
|
|
217
|
+
<iframe
|
|
218
|
+
style="display:none;"
|
|
219
|
+
srcdoc="<!DOCTYPE html>
|
|
220
|
+
<html>
|
|
221
|
+
<head><meta charset="utf-8"></head>
|
|
222
|
+
<body>
|
|
223
|
+
<strong>Hello from iframe!</strong>
|
|
224
|
+
<script is:inline data-astro-rerun>
|
|
225
|
+
const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
|
|
226
|
+
const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
|
|
226
227
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
228
|
+
function syncTocTitle(
|
|
229
|
+
locale,
|
|
230
|
+
languageMap
|
|
231
|
+
) {
|
|
232
|
+
const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
|
|
232
233
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
if (tocSummary) {
|
|
235
|
+
const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
|
|
236
|
+
const translation =
|
|
237
|
+
languageMap[locale] || '${title}' || titleKey;
|
|
238
|
+
tocSummary.textContent = translation;
|
|
239
|
+
}
|
|
238
240
|
}
|
|
239
|
-
}
|
|
240
241
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
242
|
+
function toggleToc() {
|
|
243
|
+
const tocTitle = window.parent.document.querySelector('.toc-title');
|
|
244
|
+
if (tocTitle) {
|
|
245
|
+
tocTitle.addEventListener('click', function () {
|
|
246
|
+
tocTitle.classList.toggle('open');
|
|
247
|
+
})
|
|
248
|
+
}
|
|
247
249
|
}
|
|
248
|
-
}
|
|
249
250
|
|
|
250
|
-
syncTocTitle(currentLocale, languageMap);
|
|
251
|
-
toggleToc();
|
|
252
|
-
|
|
253
|
-
window.parent.addEventListener('load', function() {
|
|
254
251
|
syncTocTitle(currentLocale, languageMap);
|
|
255
252
|
toggleToc();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
253
|
+
|
|
254
|
+
window.parent.addEventListener('load', function() {
|
|
255
|
+
syncTocTitle(currentLocale, languageMap);
|
|
256
|
+
toggleToc();
|
|
257
|
+
});
|
|
258
|
+
<\/script>
|
|
259
|
+
</body>
|
|
260
|
+
</html>">
|
|
261
|
+
</iframe>
|
|
262
|
+
`;
|
|
261
263
|
ctx.data.firstHeading = node;
|
|
262
264
|
ctx.data.firstHeadingDepth = depth;
|
|
263
265
|
ctx.data.firstHeadingId = contentSlug;
|
|
264
266
|
ctx.data.firstHeadingIndex = ctx.indexOf(node) ?? 0;
|
|
265
|
-
ctx.data.nodeStr =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
267
|
+
ctx.data.nodeStr = `
|
|
268
|
+
<div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul{
|
|
269
|
+
list-style-type: none;
|
|
270
|
+
counter-reset: toc-counter;
|
|
271
|
+
}
|
|
272
|
+
li {
|
|
273
|
+
counter-increment: toc-counter;
|
|
274
|
+
}
|
|
275
|
+
.li-marker::before {
|
|
276
|
+
content: counters(toc-counter, ".");
|
|
277
|
+
}` : "") + (opt.animation && animation !== void 0 ? `.toc-wrapper {
|
|
278
|
+
max-height: 2rem;
|
|
279
|
+
transition: max-height ${animation.duration} ${animation.timingFunction};
|
|
280
|
+
}
|
|
281
|
+
.toc-wrapper:has(.toc-title.open) {
|
|
282
|
+
max-height: 100vh;
|
|
283
|
+
}
|
|
284
|
+
` : "") + (opt.titleMarkerType === "icon" ? `
|
|
285
|
+
.toc-title::before {
|
|
286
|
+
content: '${closedMarker} ';
|
|
287
|
+
display: contents;
|
|
288
|
+
font-size: 1rem;
|
|
289
|
+
}
|
|
290
|
+
.toc-title.open::before {
|
|
291
|
+
content: '${openedMarker} ';
|
|
292
|
+
display: contents;
|
|
293
|
+
font-size: 1rem;
|
|
294
|
+
}
|
|
295
|
+
` : "") + (opt.titleMarkerType === "image" ? `
|
|
296
|
+
.toc-wrapper > .toc-title, .toc-wrapper > ul {
|
|
297
|
+
margin-left: 2rem;
|
|
298
|
+
}
|
|
299
|
+
.toc-title::before {
|
|
300
|
+
content: "";
|
|
301
|
+
background: url('${closedMarker}') center / contain no-repeat;
|
|
302
|
+
width: ${titleMarkerCssSize};
|
|
303
|
+
height: ${titleMarkerCssSize};
|
|
304
|
+
position: absolute;
|
|
305
|
+
left: -2rem;
|
|
306
|
+
top: 50%;
|
|
307
|
+
transform: translateY(-50%);
|
|
308
|
+
}
|
|
309
|
+
.toc-title.open::before {
|
|
310
|
+
content: "";
|
|
311
|
+
background: url('${openedMarker}') center / contain no-repeat;
|
|
312
|
+
width: ${titleMarkerCssSize};
|
|
313
|
+
height: ${titleMarkerCssSize};
|
|
314
|
+
position: absolute;
|
|
315
|
+
left: -2rem;
|
|
316
|
+
top: 50%;
|
|
317
|
+
transform: translateY(-50%);
|
|
318
|
+
}
|
|
319
|
+
` : "")}</style><h2 data-satteri-toc-title="${title}" class="toc-title ${opt.class?.title ?? ""}" style="${opt.style?.title ?? ""}">${title}</h2><ul class="${opt.class?.ul ?? ""}" style="${opt.style?.ul ?? ""}">${nodeStr}</ul>${iframeContent}</div>
|
|
320
|
+
`;
|
|
317
321
|
} else {
|
|
318
322
|
const indexA = ctx.data.nodeStr?.lastIndexOf(tagSignal);
|
|
319
323
|
if (indexA !== -1) ctx.data.nodeStr = ctx.data.nodeStr?.slice(0, indexA + tagSignalLength + 5) + nodeStr + ctx.data.nodeStr?.slice(indexA + tagSignalLength + 5);
|