pretty-toc 1.1.3 → 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.
Files changed (3) hide show
  1. package/README.md +37 -1
  2. package/dist/index.mjs +93 -89
  3. 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
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/with-icon.png)
35
+
36
+ - image
37
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/with-image.png)
38
+
39
+ - dot
40
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-dot.png)
41
+
42
+ - decimal
43
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-decimal.png)
44
+
45
+ - nested image
46
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-multiple-image.png)
47
+
12
48
  ## Example
13
49
 
14
50
  ```javascript
@@ -79,7 +115,7 @@ processor: satteri({
79
115
  }),
80
116
  ```
81
117
 
82
- ## options
118
+ ## Options
83
119
 
84
120
  |Property‌|Type|Default Value|Preset Value|Info|
85
121
  |:---|:---|:---|:---|:--|
package/dist/index.mjs CHANGED
@@ -213,107 +213,111 @@ function prettyToc(option) {
213
213
  color: ${darkThemeHighlightColor};
214
214
  }
215
215
  `;
216
- const iframeContent = `<iframe
217
- style="display:none;"
218
- srcdoc="&lt;!DOCTYPE html&gt;
219
- &lt;html&gt;
220
- &lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;/head&gt;
221
- &lt;body&gt;
222
- <strong>Hello from iframe!</strong>
223
- <script is:inline data-astro-rerun>
224
- const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
225
- const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
216
+ const iframeContent = `
217
+ <iframe
218
+ style="display:none;"
219
+ srcdoc="&lt;!DOCTYPE html&gt;
220
+ &lt;html&gt;
221
+ &lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;/head&gt;
222
+ &lt;body&gt;
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
- function syncTocTitle(
228
- locale,
229
- languageMap
230
- ) {
231
- const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
228
+ function syncTocTitle(
229
+ locale,
230
+ languageMap
231
+ ) {
232
+ const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
232
233
 
233
- if (tocSummary) {
234
- const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
235
- const translation =
236
- languageMap[locale] || '${title}' || titleKey;
237
- tocSummary.textContent = translation;
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
- function toggleToc() {
242
- const tocTitle = window.parent.document.querySelector('.toc-title');
243
- if (tocTitle) {
244
- tocTitle.addEventListener('click', function () {
245
- tocTitle.classList.toggle('open');
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
- <\/script>
258
- &lt;/body&gt;
259
- &lt;/html&gt;">
260
- </iframe>`;
253
+
254
+ window.parent.addEventListener('load', function() {
255
+ syncTocTitle(currentLocale, languageMap);
256
+ toggleToc();
257
+ });
258
+ <\/script>
259
+ &lt;/body&gt;
260
+ &lt;/html&gt;">
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 = `<div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul{
266
- list-style-type: none;
267
- counter-reset: toc-counter;
268
- }
269
- li {
270
- counter-increment: toc-counter;
271
- }
272
- .li-marker::before {
273
- content: counters(toc-counter, ".");
274
- }` : "") + (opt.animation && animation !== void 0 ? `.toc-wrapper {
275
- max-height: 2rem;
276
- transition: max-height ${animation.duration} ${animation.timingFunction};
277
- }
278
- .toc-wrapper:has(.toc-title.open) {
279
- max-height: 100vh;
280
- }
281
- ` : "") + (opt.titleMarkerType === "icon" ? `
282
- .toc-title::before {
283
- content: '${closedMarker} ';
284
- display: contents;
285
- font-size: 1rem;
286
- }
287
- .toc-title.open::before {
288
- content: '${openedMarker} ';
289
- display: contents;
290
- font-size: 1rem;
291
- }
292
- ` : "") + (opt.titleMarkerType === "image" ? `
293
- .toc-wrapper > .toc-title, .toc-wrapper > ul {
294
- margin-left: 2rem;
295
- }
296
- .toc-title::before {
297
- content: "";
298
- background: url('${closedMarker}') center / contain no-repeat;
299
- width: ${titleMarkerCssSize};
300
- height: ${titleMarkerCssSize};
301
- position: absolute;
302
- left: -2rem;
303
- top: 50%;
304
- transform: translateY(-50%);
305
- }
306
- .toc-title.open::before {
307
- content: "";
308
- background: url('${openedMarker}') center / contain no-repeat;
309
- width: ${titleMarkerCssSize};
310
- height: ${titleMarkerCssSize};
311
- position: absolute;
312
- left: -2rem;
313
- top: 50%;
314
- transform: translateY(-50%);
315
- }
316
- ` : "")}</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>`;
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pretty-toc",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "description": "A Table of Contents generation plugin for the Satteri markdown parser library.",
6
6
  "keywords": [