pretty-toc 1.3.1 → 1.3.3

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 CHANGED
@@ -31,19 +31,19 @@ deno add -D pretty-toc
31
31
  ## Screenshots
32
32
 
33
33
  - icon
34
- ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/with-icon.png)
34
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/with-icon.png)
35
35
 
36
36
  - image
37
- ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/with-image.png)
37
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/with-image.png)
38
38
 
39
39
  - dot
40
- ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-dot.png)
40
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-dot.png)
41
41
 
42
42
  - decimal
43
- ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-decimal.png)
43
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-decimal.png)
44
44
 
45
45
  - nested image
46
- ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-multiple-image.png)
46
+ ![](https://github.com/Virgil-N/resource/blob/main/image/pretty-toc/use-multiple-image.png)
47
47
 
48
48
  ## Example
49
49
 
@@ -117,22 +117,22 @@ processor: satteri({
117
117
 
118
118
  ## Options
119
119
 
120
- |Property‌|Type|Default Value|Preset Value|Description|
121
- |:---|:---|:---|:---|:--|
122
- |title|string|Table of Contents|Table of Contents|-|
123
- |openedMarker|string or undefined|undefined|▼|***Note: titleMarkerType must already be set.***|
124
- |closedMarker|string or undefined|undefined|▶︎|***Note: titleMarkerType must already be set.***|
125
- |titleMarkerType|string or undefined|undefined|icon|Value can only be "icon" or "image".|
126
- |titleMarkerCssSize|string or undefined|undefined|fit-content|-|
127
- |listStyle|string or undefined|undefined|decimal|eg. disc, circle, decimal, none... or icon and image|
128
- |icon|string or string[] or undefined|undefined|decimal|listStyle must already be set.|
129
- |image|string or string[] or undefined|undefined|404 image|listStyle must already be set.|
130
- |liMarkerCssSize|string or undefined|undefined|1rem|CSS property value|
131
- |lightThemeHighlightColor|string or undefined|undefined|oklch(0.75 0.1229 12.71)|-|
132
- |darkThemeHighlightColor|string or undefined|undefined|oklch(0.81 0.1004 305.04)|-|
133
- |animation|boolean or { duration: string, timingFunction: string } or undefined|undefined|{ duration: "0.8s", timingFunction: 'ease-in-out' }|-|
134
- |class|{title?: string, ul?: string, li?: string, a?: string} or or undefined|undefined|undefined|eg. {li: "py-1"}|
135
- |globalStyle|string or or undefined|undefined|undefined|eg. "ul {background-color: yellow;}"|
136
- |style|Object{title?: string, ul?: string, li?: string, a?: string} or or undefined|undefined|undefined|eg. {a: "font-style: italic;"}|
137
- |locale|string or undefined|undefined|en-US|eg. "zh-CN" // **Note: The case of the locale variable should match the locale in your page URL.**|
138
- |languageMap|Record<string, string> or undefined|undefined|{"de-DE": "Inhaltsverzeichnis","el-GR": "Περιεχόμενα","en-US": "Contents","es-ES": "Índice","fr-FR": "Sommaire","it-IT": "Indice","ja-JP": "目次","ko-KR": "목차","ru-RU": "Оглавление","th-TH": "สารบัญ","tr-TR": "İçindekiler","zh-CN": "目录","zh-Hant": "目錄"}|eg. {"en-US": "Table of Contents", "ja-JP": "目次"}|
120
+ | Property‌ | Type | Default Value | Preset Value | Description |
121
+ | :----------------------- | :--------------------------------------------------------------------------- | :---------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------- |
122
+ | title | string | Table of Contents | Table of Contents | - |
123
+ | openedMarker | string or undefined | undefined | ▼ | _**Note: titleMarkerType must already be set.**_ |
124
+ | closedMarker | string or undefined | undefined | ▶︎ | _**Note: titleMarkerType must already be set.**_ |
125
+ | titleMarkerType | string or undefined | undefined | icon | Value can only be "icon" or "image". |
126
+ | titleMarkerCssSize | string or undefined | undefined | fit-content | - |
127
+ | listStyle | string or undefined | undefined | decimal | eg. disc, circle, decimal, none... or icon and image |
128
+ | icon | string or string[] or undefined | undefined | decimal | _**Note: listStyle must already be set.**_ |
129
+ | image | string or string[] or undefined | undefined | 404 image | _**Note: listStyle must already be set.**_ |
130
+ | liMarkerCssSize | string or undefined | undefined | 1rem | CSS property value |
131
+ | lightThemeHighlightColor | string or undefined | undefined | oklch(0.75 0.1229 12.71) | - |
132
+ | darkThemeHighlightColor | string or undefined | undefined | oklch(0.81 0.1004 305.04) | - |
133
+ | animation | boolean or { duration: string, timingFunction: string } or undefined | undefined | { duration: "0.8s", timingFunction: 'ease-in-out' } | - |
134
+ | class | {title?: string, ul?: string, li?: string, a?: string} or or undefined | undefined | undefined | eg. {li: "py-1"} |
135
+ | globalStyle | string or or undefined | undefined | undefined | eg. "ul {background-color: yellow;}" |
136
+ | style | Object{title?: string, ul?: string, li?: string, a?: string} or or undefined | undefined | undefined | eg. {a: "font-style: italic;"} |
137
+ | locale | string or undefined | undefined | en-US | eg. "zh-CN" // **Note: The case of the locale variable should match the locale in your page URL.** |
138
+ | languageMap | Record<string, string> or undefined | undefined | {"de-DE": "Inhaltsverzeichnis","el-GR": "Περιεχόμενα","en-US": "Contents","es-ES": "Índice","fr-FR": "Sommaire","it-IT": "Indice","ja-JP": "目次","ko-KR": "목차","ru-RU": "Оглавление","th-TH": "สารบัญ","tr-TR": "İçindekiler","zh-CN": "目录","zh-Hant": "目錄"} | eg. {"en-US": "Table of Contents", "ja-JP": "目次"} |
package/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { HastPluginDefinition } from "satteri";
2
- //#region basic.d.ts
3
2
  interface tagHasProperty {
4
3
  title?: string;
5
4
  ul?: string;
@@ -45,13 +44,10 @@ interface HastOption {
45
44
  /** 标题文本映射 */
46
45
  languageMap?: Record<string, string>;
47
46
  }
48
- //#endregion
49
- //#region src/index.d.ts
50
47
  /**
51
48
  *
52
49
  * @param option 用户传入插件的配置
53
50
  * @returns 插件实例
54
51
  */
55
52
  declare function prettyToc(option?: HastOption): HastPluginDefinition;
56
- //#endregion
57
53
  export { prettyToc as default };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineHastPlugin } from "satteri";
2
2
  import slug from "slug";
3
- //#region src/const.ts
3
+ // src/const.ts
4
4
  const DEFAULT_TITLE = "Table of Contents";
5
5
  const DEFAULT_TITLE_MARKER_TYPE = "icon";
6
6
  const DEFAULT_TITLE_MARKER_CSS_SIZE = "fit-content";
@@ -52,11 +52,9 @@ const DEFAULT_OPTIONS = {
52
52
  locale: DEFALUT_LOCALE,
53
53
  languageMap: DEFAULT_LANGUAGE_MAP
54
54
  };
55
- //#endregion
56
- //#region src/assets/svg/image-not-found.svg
55
+ // src/assets/svg/image-not-found.svg
57
56
  var image_not_found_default = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221em%22%20height%3D%221em%22%20viewBox%3D%220%200%2024%2024%22%3E%20%3Cpath%20d%3D%22M0%200h24v24H0z%22%20fill%3D%22none%22%20%2F%3E%20%3Cpath%20fill%3D%22currentColor%22%20d%3D%22M19%205c1.1%200%202%20.9%202%202v10c0%201.1-.9%202-2%202H5c-1.1%200-2-.9-2-2V7c0-1.1.9-2%202-2zM5%206.5c-.3%200-.5.2-.5.5v10c0%20.3.2.5.5.5h14c.3%200%20.5-.2.5-.5V7c0-.3-.2-.5-.5-.5zm7.01%202.75q.711%200%201.24.364q.533.364.824%201.012q.296.645.296%201.488q0%20.887-.296%201.556q-.292.664-.824%201.036q-.528.368-1.24.368q-.708%200-1.24-.368q-.527-.372-.824-1.036q-.296-.668-.296-1.556q0-.848.296-1.492q.296-.648.824-1.008a2.14%202.14%200%200%201%201.24-.364m-3.484%203.6h.72v.832h-.72v1.28h-.984v-1.28H4.75l3.08-4.32h.696zm9.522%200h.72v.832h-.72v1.28h-.983v-1.28h-2.793l3.08-4.32h.696zm-6.038-2.696q-.568%200-.952.48q-.384.475-.384%201.48q0%20.716.176%201.168q.176.45.476.66q.304.212.684.212t.68-.208q.304-.207.48-.656q.176-.451.176-1.176q0-.996-.384-1.476q-.38-.484-.952-.484M6.33%2012.85h1.212v-1.722zm9.523%200h1.211v-1.722z%22%20%2F%3E%3C%2Fsvg%3E";
58
- //#endregion
59
- //#region src/index.ts
57
+ // src/index.ts
60
58
  /**
61
59
  *
62
60
  * @param option 用户传入插件的配置
@@ -183,7 +181,7 @@ function prettyToc(option) {
183
181
  }
184
182
  }
185
183
  } catch (err) {
186
- throw err;
184
+ console.log("pretty-toc error: ", err);
187
185
  }
188
186
  }
189
187
  }],
@@ -200,116 +198,116 @@ function prettyToc(option) {
200
198
  grid-template-rows: 0fr;
201
199
  overflow: hidden;
202
200
  margin-bottom: 2rem;
203
- }
204
- .toc-wrapper:has(.toc-title.open) {
205
- grid-template-rows: 1fr;
206
- }
207
- .toc-title {
208
- font-size: 1.2rem;
209
- font-weight: 600;
210
- margin: 0 0 0.5rem 0;
211
- width: fit-content;
212
- position: relative;
213
- }
214
- ul {
215
- padding-left: var(--list-indent, 1.5rem);
216
- list-style-type: ${listStyle} ;
217
- list-style-position: inside;
218
- }
219
- ul:not(:has(> li)) {
220
- padding-left: 0;
221
- }
222
- @keyframes fadeIn {
223
- from { opacity: 0; }
224
- to { opacity: 1; }
225
- }
226
- li {
227
- padding: 0;
228
- line-height: 1.5rem;
229
- font-size: 1rem;
230
- animation: fadeIn 0.01s ease-in; // 防止页面刷新瞬间显示"0 javascript"
231
- }
232
- .li-marker {
233
- display: inline-block;
234
- margin-right: 0.5rem;
235
- }
236
- img.li-marker {
237
- width: ${liMarkerCssSize};
238
- height: ${liMarkerCssSize};
239
- margin: 0 0.5rem 0 0;
240
- }
241
- .li-marker::before {
242
- font-size: 1rem;
243
- font-weight: 600;
244
- width: ${liMarkerCssSize};
245
- height: ${liMarkerCssSize};
246
- }
247
- /* 嵌套的 ul 内部,让缩进变量自动叠加 1rem */
248
- ul ul {
249
- --list-indent: calc(var(--list-indent, 1rem) + 1rem);
250
- }
251
- .li-row {
252
- display: inline-flex;
253
- flex-direction: row;
254
- justify-content: flex-start;
255
- align-items: center;
256
- }
257
- .li-row > img {
258
- margin: 0 0.5rem 0 0;
259
- }
260
- .li-row > a {
261
- text-decoration: none;
201
+ &:has(.toc-title.open) {
202
+ grid-template-rows: 1fr;
203
+ }
204
+ .toc-title {
205
+ font-size: 1.2rem;
206
+ font-weight: 600;
207
+ margin: 0 0 0.5rem 0;
208
+ width: fit-content;
209
+ position: relative;
210
+ }
211
+ ul {
212
+ padding-left: var(--list-indent, 1.5rem);
213
+ list-style-type: ${listStyle} ;
214
+ list-style-position: inside;
215
+ }
216
+ ul:not(:has(> li)) {
217
+ padding-left: 0;
218
+ }
219
+ @keyframes fadeIn {
220
+ from { opacity: 0; }
221
+ to { opacity: 1; }
222
+ }
223
+ li {
224
+ padding: 0;
225
+ line-height: 1.5rem;
226
+ font-size: 1rem;
227
+ animation: fadeIn 0.01s ease-in; // 防止页面刷新瞬间显示"0 javascript"
228
+ }
229
+ .li-marker {
230
+ display: inline-block;
231
+ margin-right: 0.5rem;
232
+ }
233
+ img.li-marker {
234
+ width: ${liMarkerCssSize};
235
+ height: ${liMarkerCssSize};
236
+ margin: 0 0.5rem 0 0;
237
+ }
238
+ .li-marker::before {
239
+ font-size: 1rem;
240
+ font-weight: 600;
241
+ width: ${liMarkerCssSize};
242
+ height: ${liMarkerCssSize};
243
+ }
244
+ /* 嵌套的 ul 内部,让缩进变量自动叠加 1rem */
245
+ ul ul {
246
+ --list-indent: calc(var(--list-indent, 1rem) + 1rem);
247
+ }
248
+ .li-row {
249
+ display: inline-flex;
250
+ flex-direction: row;
251
+ justify-content: flex-start;
252
+ align-items: center;
253
+ }
254
+ .li-row > img {
255
+ margin: 0 0.5rem 0 0;
256
+ }
257
+ .li-row > a {
258
+ text-decoration: none;
259
+ }
262
260
  }
263
261
  @media (hover: hover) {
264
- .toc-title:hover {
262
+ .toc-wrapper .toc-title:hover {
265
263
  color: ${lightThemeHighlightColor};
266
264
  cursor: pointer;
267
265
  }
268
- html.dark .toc-title:hover {
266
+ html.dark .toc-wrapper .toc-title:hover {
269
267
  color: ${darkThemeHighlightColor};
270
268
  }
271
- .li-row:hover {
269
+ .toc-wrapper .li-row:hover {
272
270
  color: ${lightThemeHighlightColor};
273
271
  }
274
- .li-row:hover > .li-marker::before {
272
+ .toc-wrapper .li-row:hover > .li-marker::before {
275
273
  color: ${lightThemeHighlightColor};
276
274
  }
277
- .li-row:hover > a {
275
+ .toc-wrapper .li-row:hover > a {
278
276
  color: ${lightThemeHighlightColor};
279
277
  }
280
- html.dark .li-row:hover {
278
+ html.dark .toc-wrapper .li-row:hover {
281
279
  color: ${darkThemeHighlightColor};
282
280
  }
283
- html.dark .li-row:hover > .li-marker::before {
281
+ html.dark .toc-wrapper .li-row:hover > .li-marker::before {
284
282
  color: ${darkThemeHighlightColor};
285
283
  }
286
- html.dark .li-row:hover > a {
284
+ html.dark .toc-wrapper .li-row:hover > a {
287
285
  color: ${darkThemeHighlightColor};
288
286
  }
289
287
  }
290
- .toc-title:active {
288
+ .toc-wrapper .toc-title:active {
291
289
  color: ${lightThemeHighlightColor};
292
290
  cursor: pointer;
293
291
  }
294
- html.dark .toc-title:active {
292
+ html.dark .toc-wrapper .toc-title:active {
295
293
  color: ${darkThemeHighlightColor};
296
294
  }
297
- .li-row:active {
295
+ .toc-wrapper .li-row:active {
298
296
  color: ${lightThemeHighlightColor};
299
297
  }
300
- .li-row:active > .li-marker::before {
298
+ .toc-wrapper .li-row:active > .li-marker::before {
301
299
  color: ${lightThemeHighlightColor};
302
300
  }
303
- .li-row:active > a {
301
+ .toc-wrapper .li-row:active > a {
304
302
  color: ${lightThemeHighlightColor};
305
303
  }
306
- html.dark .li-row:active {
304
+ html.dark .toc-wrapper .li-row:active {
307
305
  color: ${darkThemeHighlightColor};
308
306
  }
309
- html.dark .li-row:active > .li-marker::before {
307
+ html.dark .toc-wrapper .li-row:active > .li-marker::before {
310
308
  color: ${darkThemeHighlightColor};
311
309
  }
312
- html.dark .li-row:active > a {
310
+ html.dark .toc-wrapper .li-row:active > a {
313
311
  color: ${darkThemeHighlightColor};
314
312
  }
315
313
  `;
@@ -366,14 +364,14 @@ function prettyToc(option) {
366
364
  </iframe>
367
365
  `;
368
366
  const totalNodeStr = `
369
- <div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul:has(> li) {
367
+ <div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `.toc-wrapper ul:has(> li) {
370
368
  list-style-type: none;
371
369
  counter-reset: toc-counter;
372
370
  }
373
- li {
371
+ .toc-wrapper li {
374
372
  counter-increment: toc-counter;
375
373
  }
376
- .li-marker::before {
374
+ .toc-wrapper .li-marker::before {
377
375
  content: counters(toc-counter, ".");
378
376
  }` : "") + (opt.animation && animation !== void 0 && typeof animation !== "boolean" ? `.toc-wrapper {
379
377
  max-height: 2rem;
@@ -383,12 +381,12 @@ function prettyToc(option) {
383
381
  max-height: 100vh;
384
382
  }
385
383
  ` : "") + (opt.titleMarkerType === "icon" ? `
386
- .toc-title::before {
384
+ .toc-wrapper .toc-title::before {
387
385
  content: '${closedMarker} ';
388
386
  display: contents;
389
387
  font-size: 1rem;
390
388
  }
391
- .toc-title.open::before {
389
+ .toc-wrapper .toc-title.open::before {
392
390
  content: '${openedMarker} ';
393
391
  display: contents;
394
392
  font-size: 1rem;
@@ -397,7 +395,7 @@ function prettyToc(option) {
397
395
  .toc-wrapper > .toc-title, .toc-wrapper > ul {
398
396
  margin-left: 2rem;
399
397
  }
400
- .toc-title::before {
398
+ .toc-wrapper .toc-title::before {
401
399
  content: "";
402
400
  background: url('${closedMarker}') center / contain no-repeat;
403
401
  width: ${titleMarkerCssSize};
@@ -407,7 +405,7 @@ function prettyToc(option) {
407
405
  top: 50%;
408
406
  transform: translateY(-50%);
409
407
  }
410
- .toc-title.open::before {
408
+ .toc-wrapper .toc-title.open::before {
411
409
  content: "";
412
410
  background: url('${openedMarker}') center / contain no-repeat;
413
411
  width: ${titleMarkerCssSize};
@@ -442,5 +440,4 @@ function concatNodeStr(node, opt) {
442
440
  }
443
441
  return node.content;
444
442
  }
445
- //#endregion
446
443
  export { prettyToc as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pretty-toc",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "type": "module",
5
5
  "description": "A Table of Contents generation plugin for the Satteri markdown parser library.",
6
6
  "keywords": [