pretty-toc 1.1.3 → 1.1.5
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 +37 -1
- package/dist/index.mjs +133 -102
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,9 +6,45 @@ A Table of Contents generation plugin for the Satteri markdown parser library.
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
8
8
|
```
|
|
9
|
+
// install with npm
|
|
9
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
|
|
10
23
|
```
|
|
11
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
|
+
|
|
12
48
|
## Example
|
|
13
49
|
|
|
14
50
|
```javascript
|
|
@@ -79,7 +115,7 @@ processor: satteri({
|
|
|
79
115
|
}),
|
|
80
116
|
```
|
|
81
117
|
|
|
82
|
-
##
|
|
118
|
+
## Options
|
|
83
119
|
|
|
84
120
|
|Property|Type|Default Value|Preset Value|Info|
|
|
85
121
|
|:---|:---|:---|:---|:--|
|
package/dist/index.mjs
CHANGED
|
@@ -137,13 +137,6 @@ function prettyToc(option) {
|
|
|
137
137
|
width: fit-content;
|
|
138
138
|
position: relative;
|
|
139
139
|
}
|
|
140
|
-
.toc-title:hover {
|
|
141
|
-
color: ${lightThemeHighlightColor};
|
|
142
|
-
cursor: pointer;
|
|
143
|
-
}
|
|
144
|
-
html.dark .toc-title:hover {
|
|
145
|
-
color: ${darkThemeHighlightColor};
|
|
146
|
-
}
|
|
147
140
|
ul {
|
|
148
141
|
padding-left: 0;
|
|
149
142
|
list-style-type: ${listStyle} ;
|
|
@@ -194,126 +187,164 @@ function prettyToc(option) {
|
|
|
194
187
|
.li-row > a {
|
|
195
188
|
text-decoration: none;
|
|
196
189
|
}
|
|
197
|
-
|
|
190
|
+
@media (hover: hover) {
|
|
191
|
+
.toc-title:hover {
|
|
192
|
+
color: ${lightThemeHighlightColor};
|
|
193
|
+
cursor: pointer;
|
|
194
|
+
}
|
|
195
|
+
html.dark .toc-title:hover {
|
|
196
|
+
color: ${darkThemeHighlightColor};
|
|
197
|
+
}
|
|
198
|
+
.li-row:hover {
|
|
199
|
+
color: ${lightThemeHighlightColor};
|
|
200
|
+
}
|
|
201
|
+
.li-row:hover > .li-marker::before {
|
|
202
|
+
color: ${lightThemeHighlightColor};
|
|
203
|
+
}
|
|
204
|
+
.li-row:hover > a {
|
|
205
|
+
color: ${lightThemeHighlightColor};
|
|
206
|
+
}
|
|
207
|
+
html.dark .li-row:hover {
|
|
208
|
+
color: ${darkThemeHighlightColor};
|
|
209
|
+
}
|
|
210
|
+
html.dark .li-row:hover > .li-marker::before {
|
|
211
|
+
color: ${darkThemeHighlightColor};
|
|
212
|
+
}
|
|
213
|
+
html.dark .li-row:hover > a {
|
|
214
|
+
color: ${darkThemeHighlightColor};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
.toc-title:active {
|
|
198
218
|
color: ${lightThemeHighlightColor};
|
|
219
|
+
cursor: pointer;
|
|
199
220
|
}
|
|
200
|
-
.
|
|
221
|
+
html.dark .toc-title:active {
|
|
222
|
+
color: ${darkThemeHighlightColor};
|
|
223
|
+
}
|
|
224
|
+
.li-row:active {
|
|
225
|
+
color: ${lightThemeHighlightColor};
|
|
226
|
+
}
|
|
227
|
+
.li-row:active > .li-marker::before {
|
|
201
228
|
color: ${lightThemeHighlightColor};
|
|
202
229
|
}
|
|
203
|
-
.li-row:
|
|
230
|
+
.li-row:active > a {
|
|
204
231
|
color: ${lightThemeHighlightColor};
|
|
205
232
|
}
|
|
206
|
-
html.dark .li-row:
|
|
233
|
+
html.dark .li-row:active {
|
|
207
234
|
color: ${darkThemeHighlightColor};
|
|
208
235
|
}
|
|
209
|
-
html.dark .li-row:
|
|
236
|
+
html.dark .li-row:active > .li-marker::before {
|
|
210
237
|
color: ${darkThemeHighlightColor};
|
|
211
238
|
}
|
|
212
|
-
html.dark .li-row:
|
|
239
|
+
html.dark .li-row:active > a {
|
|
213
240
|
color: ${darkThemeHighlightColor};
|
|
214
241
|
}
|
|
215
242
|
`;
|
|
216
|
-
const iframeContent =
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
<
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
243
|
+
const iframeContent = `
|
|
244
|
+
<iframe
|
|
245
|
+
style="display:none;"
|
|
246
|
+
srcdoc="<!DOCTYPE html>
|
|
247
|
+
<html>
|
|
248
|
+
<head><meta charset="utf-8"></head>
|
|
249
|
+
<body>
|
|
250
|
+
<strong>Hello from iframe!</strong>
|
|
251
|
+
<script is:inline data-astro-rerun>
|
|
252
|
+
const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
|
|
253
|
+
const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
|
|
226
254
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
255
|
+
function syncTocTitle(
|
|
256
|
+
locale,
|
|
257
|
+
languageMap
|
|
258
|
+
) {
|
|
259
|
+
const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
|
|
232
260
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
261
|
+
if (tocSummary) {
|
|
262
|
+
const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
|
|
263
|
+
const translation =
|
|
264
|
+
languageMap[locale] || '${title}' || titleKey;
|
|
265
|
+
tocSummary.textContent = translation;
|
|
266
|
+
}
|
|
238
267
|
}
|
|
239
|
-
}
|
|
240
268
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
269
|
+
function toggleToc() {
|
|
270
|
+
const tocTitle = window.parent.document.querySelector('.toc-title');
|
|
271
|
+
if (tocTitle) {
|
|
272
|
+
tocTitle.addEventListener('click', function () {
|
|
273
|
+
tocTitle.classList.toggle('open');
|
|
274
|
+
})
|
|
275
|
+
}
|
|
247
276
|
}
|
|
248
|
-
}
|
|
249
277
|
|
|
250
|
-
syncTocTitle(currentLocale, languageMap);
|
|
251
|
-
toggleToc();
|
|
252
|
-
|
|
253
|
-
window.parent.addEventListener('load', function() {
|
|
254
278
|
syncTocTitle(currentLocale, languageMap);
|
|
255
279
|
toggleToc();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
280
|
+
|
|
281
|
+
window.parent.addEventListener('load', function() {
|
|
282
|
+
syncTocTitle(currentLocale, languageMap);
|
|
283
|
+
toggleToc();
|
|
284
|
+
});
|
|
285
|
+
<\/script>
|
|
286
|
+
</body>
|
|
287
|
+
</html>">
|
|
288
|
+
</iframe>
|
|
289
|
+
`;
|
|
261
290
|
ctx.data.firstHeading = node;
|
|
262
291
|
ctx.data.firstHeadingDepth = depth;
|
|
263
292
|
ctx.data.firstHeadingId = contentSlug;
|
|
264
293
|
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
|
-
|
|
294
|
+
ctx.data.nodeStr = `
|
|
295
|
+
<div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul{
|
|
296
|
+
list-style-type: none;
|
|
297
|
+
counter-reset: toc-counter;
|
|
298
|
+
}
|
|
299
|
+
li {
|
|
300
|
+
counter-increment: toc-counter;
|
|
301
|
+
}
|
|
302
|
+
.li-marker::before {
|
|
303
|
+
content: counters(toc-counter, ".");
|
|
304
|
+
}` : "") + (opt.animation && animation !== void 0 ? `.toc-wrapper {
|
|
305
|
+
max-height: 2rem;
|
|
306
|
+
transition: max-height ${animation.duration} ${animation.timingFunction};
|
|
307
|
+
}
|
|
308
|
+
.toc-wrapper:has(.toc-title.open) {
|
|
309
|
+
max-height: 100vh;
|
|
310
|
+
}
|
|
311
|
+
` : "") + (opt.titleMarkerType === "icon" ? `
|
|
312
|
+
.toc-title::before {
|
|
313
|
+
content: '${closedMarker} ';
|
|
314
|
+
display: contents;
|
|
315
|
+
font-size: 1rem;
|
|
316
|
+
}
|
|
317
|
+
.toc-title.open::before {
|
|
318
|
+
content: '${openedMarker} ';
|
|
319
|
+
display: contents;
|
|
320
|
+
font-size: 1rem;
|
|
321
|
+
}
|
|
322
|
+
` : "") + (opt.titleMarkerType === "image" ? `
|
|
323
|
+
.toc-wrapper > .toc-title, .toc-wrapper > ul {
|
|
324
|
+
margin-left: 2rem;
|
|
325
|
+
}
|
|
326
|
+
.toc-title::before {
|
|
327
|
+
content: "";
|
|
328
|
+
background: url('${closedMarker}') center / contain no-repeat;
|
|
329
|
+
width: ${titleMarkerCssSize};
|
|
330
|
+
height: ${titleMarkerCssSize};
|
|
331
|
+
position: absolute;
|
|
332
|
+
left: -2rem;
|
|
333
|
+
top: 50%;
|
|
334
|
+
transform: translateY(-50%);
|
|
335
|
+
}
|
|
336
|
+
.toc-title.open::before {
|
|
337
|
+
content: "";
|
|
338
|
+
background: url('${openedMarker}') center / contain no-repeat;
|
|
339
|
+
width: ${titleMarkerCssSize};
|
|
340
|
+
height: ${titleMarkerCssSize};
|
|
341
|
+
position: absolute;
|
|
342
|
+
left: -2rem;
|
|
343
|
+
top: 50%;
|
|
344
|
+
transform: translateY(-50%);
|
|
345
|
+
}
|
|
346
|
+
` : "")}</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>
|
|
347
|
+
`;
|
|
317
348
|
} else {
|
|
318
349
|
const indexA = ctx.data.nodeStr?.lastIndexOf(tagSignal);
|
|
319
350
|
if (indexA !== -1) ctx.data.nodeStr = ctx.data.nodeStr?.slice(0, indexA + tagSignalLength + 5) + nodeStr + ctx.data.nodeStr?.slice(indexA + tagSignalLength + 5);
|