pretty-toc 1.2.4 → 1.3.0

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 +6 -6
  2. package/dist/index.mjs +256 -254
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -82,14 +82,14 @@ processor: satteri({
82
82
  timingFunction: 'ease-in-out'
83
83
  },
84
84
  class: {
85
- summary: "",
85
+ title: "",
86
86
  ul: "",
87
87
  li: "",
88
88
  a: "",
89
89
  },
90
90
  globalStyle: "",
91
91
  style: {
92
- summary: "",
92
+ title: "",
93
93
  ul: "",
94
94
  li: "",
95
95
  a: "",
@@ -117,7 +117,7 @@ processor: satteri({
117
117
 
118
118
  ## Options
119
119
 
120
- |Property‌|Type|Default Value|Preset Value|Info|
120
+ |Property‌|Type|Default Value|Preset Value|Description|
121
121
  |:---|:---|:---|:---|:--|
122
122
  |title|string|Table of Contents|Table of Contents|-|
123
123
  |openedMarker|string or undefined|undefined|▼|***Note: titleMarkerType must already be set.***|
@@ -131,8 +131,8 @@ processor: satteri({
131
131
  |lightThemeHighlightColor|string or undefined|undefined|oklch(0.75 0.1229 12.71)|-|
132
132
  |darkThemeHighlightColor|string or undefined|undefined|oklch(0.81 0.1004 305.04)|-|
133
133
  |animation|boolean or { duration: string, timingFunction: string } or undefined|undefined|{ duration: "0.8s", timingFunction: 'ease-in-out' }|-|
134
- |class|{summary?: string, ul?: string, li?: string, a?: string} or or undefined|undefined|undefined|eg. {summary: "pb-2", li: "py-1"}|
135
- |globalStyle|string or or undefined|undefined|undefined|eg. "summary {background-color: yellow;}"|
136
- |style|Object{summary?: string, ul?: string, li?: string, a?: string} or or undefined|undefined|undefined|eg. {a: "font-style: italic;"}|
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
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
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.mjs CHANGED
@@ -63,6 +63,18 @@ var image_not_found_default = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F
63
63
  * @returns 插件实例
64
64
  */
65
65
  function prettyToc(option) {
66
+ const opt = option ?? DEFAULT_OPTIONS;
67
+ const lightThemeHighlightColor = opt.lightThemeHighlightColor || "oklch(0.75 0.1229 12.71)";
68
+ const darkThemeHighlightColor = opt.darkThemeHighlightColor || "oklch(0.81 0.1004 305.04)";
69
+ const titleMarkerCssSize = opt.titleMarkerCssSize || "fit-content";
70
+ const openedMarker = opt.openedMarker || "▼";
71
+ const closedMarker = opt.closedMarker || "▶︎";
72
+ const liMarkerCssSize = opt.liMarkerCssSize || "1rem";
73
+ let title = opt.title || "Table of Contents";
74
+ let listStyle = DEFAULT_LIST_STYLE;
75
+ let animation = void 0;
76
+ let headingTree = void 0;
77
+ let firstHeading = {};
66
78
  return defineHastPlugin({
67
79
  name: "prettyToc",
68
80
  element: [{
@@ -75,24 +87,14 @@ function prettyToc(option) {
75
87
  "h6"
76
88
  ],
77
89
  visit(node, ctx) {
78
- const opt = option ?? DEFAULT_OPTIONS;
79
90
  try {
80
91
  const depth = parseInt(node.tagName.slice(-1), 10);
81
92
  const content = ctx.textContent(node);
82
93
  const contentSlug = slug(content) + (/* @__PURE__ */ new Date()).getTime();
83
- let title = opt.title || "Table of Contents";
84
94
  if (opt.languageMap) title = opt.languageMap[opt.locale ?? "en-US"] || "Table of Contents";
85
95
  else title = DEFAULT_LANGUAGE_MAP[opt.locale ?? "en-US"] || "Table of Contents";
86
- let listStyle = DEFAULT_LIST_STYLE;
87
96
  if (opt.listStyle === "icon" || opt.listStyle === "image" || opt.listStyle === "decimal") listStyle = "none";
88
97
  else if (opt.listStyle !== void 0) listStyle = opt.listStyle;
89
- const lightThemeHighlightColor = opt.lightThemeHighlightColor || "oklch(0.75 0.1229 12.71)";
90
- const darkThemeHighlightColor = opt.darkThemeHighlightColor || "oklch(0.81 0.1004 305.04)";
91
- const titleMarkerCssSize = opt.titleMarkerCssSize || "fit-content";
92
- const openedMarker = opt.openedMarker || "▼";
93
- const closedMarker = opt.closedMarker || "▶︎";
94
- const liMarkerCssSize = opt.liMarkerCssSize || "1rem";
95
- let animation = void 0;
96
98
  if (typeof opt.animation === "object" && opt.animation !== void 0) animation = opt.animation ?? DEFAULT_ANIMATION;
97
99
  else if (opt.animation === true) animation = DEFAULT_ANIMATION;
98
100
  else animation = void 0;
@@ -117,18 +119,18 @@ function prettyToc(option) {
117
119
  }
118
120
  let nodeStr = `<li id="li-${contentSlug}" class="${opt.class?.li ?? ""}" style="${opt.style?.li ?? ""}" data-depth=${depth}><div class="li-row">${marker}<a href="#${contentSlug}" class="${opt.class?.a ?? ""}" style="${opt.style?.a ?? ""}">${content}</a></div></li>`;
119
121
  ctx.setProperty(node, "id", contentSlug);
120
- if (ctx.data.nodeTree === void 0) {
121
- ctx.data.firstHeading = node;
122
- ctx.data.firstHeadingDepth = depth;
123
- ctx.data.firstHeadingId = contentSlug;
124
- ctx.data.firstHeadingIndex = ctx.indexOf(node) ?? 0;
122
+ if (headingTree === void 0) {
123
+ firstHeading.headingText = ctx.textContent(node);
124
+ firstHeading.headingDepth = depth;
125
+ firstHeading.headingId = contentSlug;
126
+ firstHeading.headingIndex = ctx.indexOf(node) ?? 0;
125
127
  const rootNode = {
126
128
  depth: 0,
127
129
  content: "",
128
130
  children: [],
129
131
  parent: void 0
130
132
  };
131
- ctx.data.nodeTree = {
133
+ headingTree = {
132
134
  rootNode,
133
135
  previousNode: rootNode
134
136
  };
@@ -139,21 +141,21 @@ function prettyToc(option) {
139
141
  children: [],
140
142
  parent: rootNode
141
143
  };
142
- ctx.data.nodeTree.rootNode.children.push(currentNode);
143
- ctx.data.nodeTree.previousNode = currentNode;
144
+ headingTree.rootNode.children.push(currentNode);
145
+ headingTree.previousNode = currentNode;
144
146
  } else for (let i = 1; i <= depth; i++) {
145
147
  const currentNode = {
146
148
  depth: i,
147
149
  content: i === depth ? nodeStr : "",
148
150
  children: [],
149
- parent: ctx.data.nodeTree.previousNode
151
+ parent: headingTree.previousNode
150
152
  };
151
- ctx.data.nodeTree.previousNode.children.push(currentNode);
152
- ctx.data.nodeTree.previousNode = currentNode;
153
+ headingTree.previousNode.children.push(currentNode);
154
+ headingTree.previousNode = currentNode;
153
155
  }
154
156
  } else {
155
157
  let hasFound = false;
156
- let nextSearchNode = ctx.data.nodeTree.rootNode;
158
+ let nextSearchNode = headingTree.rootNode;
157
159
  searchNode: while (!hasFound) if (nextSearchNode.depth + 1 === depth) {
158
160
  const currentNode = {
159
161
  depth,
@@ -162,7 +164,7 @@ function prettyToc(option) {
162
164
  parent: nextSearchNode
163
165
  };
164
166
  nextSearchNode.children.push(currentNode);
165
- ctx.data.nodeTree.previousNode = currentNode;
167
+ headingTree.previousNode = currentNode;
166
168
  hasFound = true;
167
169
  break searchNode;
168
170
  } else if (nextSearchNode.children.length > 0) {
@@ -180,249 +182,249 @@ function prettyToc(option) {
180
182
  continue searchNode;
181
183
  }
182
184
  }
183
- let parent = ctx.parent(node);
184
- while (parent.type !== "root" && parent !== void 0) {
185
- const p = ctx.parent(parent);
186
- if (p) parent = p;
187
- else break;
188
- }
189
- if (parent.type === "root") {
190
- const collectedNodeStr = concatNodeStr(ctx.data.nodeTree.rootNode, opt);
191
- const baseStyle = `
192
- .toc-wrapper {
193
- display: grid;
194
- grid-template-rows: 0fr;
195
- overflow: hidden;
196
- margin-bottom: 2rem;
197
- }
198
- .toc-wrapper:has(.toc-title.open) {
199
- grid-template-rows: 1fr;
200
- }
201
- .toc-title {
202
- font-size: 1.2rem;
203
- font-weight: 600;
204
- margin: 0 0 0.5rem 0;
205
- width: fit-content;
206
- position: relative;
207
- }
208
- ul {
209
- padding-left: var(--list-indent, 1.5rem);
210
- list-style-type: ${listStyle} ;
211
- list-style-position: inside;
212
- }
213
- ul:not(:has(> li)) {
214
- padding-left: 0;
215
- }
216
- @keyframes fadeIn {
217
- from { opacity: 0; }
218
- to { opacity: 1; }
219
- }
220
- li {
221
- padding: 0;
222
- line-height: 1.5rem;
223
- font-size: 1rem;
224
- animation: fadeIn 0.01s ease-in; // 防止页面刷新瞬间显示"0 javascript"
225
- }
226
- .li-marker {
227
- display: inline-block;
228
- margin-right: 0.5rem;
229
- }
230
- img.li-marker {
231
- width: ${liMarkerCssSize};
232
- height: ${liMarkerCssSize};
233
- margin: 0 0.5rem 0 0;
234
- }
235
- .li-marker::before {
236
- font-size: 1rem;
237
- font-weight: 600;
238
- width: ${liMarkerCssSize};
239
- height: ${liMarkerCssSize};
240
- }
241
- /* 嵌套的 ul 内部,让缩进变量自动叠加 1rem */
242
- ul ul {
243
- --list-indent: calc(var(--list-indent, 1rem) + 1rem);
244
- }
245
- .li-row {
246
- display: inline-flex;
247
- flex-direction: row;
248
- justify-content: flex-start;
249
- align-items: center;
250
- }
251
- .li-row > img {
252
- margin: 0 0.5rem 0 0;
253
- }
254
- .li-row > a {
255
- text-decoration: none;
256
- }
257
- @media (hover: hover) {
258
- .toc-title:hover {
259
- color: ${lightThemeHighlightColor};
260
- cursor: pointer;
261
- }
262
- html.dark .toc-title:hover {
263
- color: ${darkThemeHighlightColor};
264
- }
265
- .li-row:hover {
266
- color: ${lightThemeHighlightColor};
267
- }
268
- .li-row:hover > .li-marker::before {
269
- color: ${lightThemeHighlightColor};
270
- }
271
- .li-row:hover > a {
272
- color: ${lightThemeHighlightColor};
273
- }
274
- html.dark .li-row:hover {
275
- color: ${darkThemeHighlightColor};
276
- }
277
- html.dark .li-row:hover > .li-marker::before {
278
- color: ${darkThemeHighlightColor};
185
+ } catch (err) {
186
+ throw err;
187
+ }
188
+ }
189
+ }],
190
+ before() {
191
+ headingTree = void 0;
192
+ firstHeading = {};
193
+ },
194
+ after(root, ctx) {
195
+ if (headingTree !== void 0) {
196
+ const collectedNodeStr = concatNodeStr(headingTree.rootNode, opt);
197
+ const baseStyle = `
198
+ .toc-wrapper {
199
+ display: grid;
200
+ grid-template-rows: 0fr;
201
+ overflow: hidden;
202
+ 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;
262
+ }
263
+ @media (hover: hover) {
264
+ .toc-title:hover {
265
+ color: ${lightThemeHighlightColor};
266
+ cursor: pointer;
267
+ }
268
+ html.dark .toc-title:hover {
269
+ color: ${darkThemeHighlightColor};
270
+ }
271
+ .li-row:hover {
272
+ color: ${lightThemeHighlightColor};
273
+ }
274
+ .li-row:hover > .li-marker::before {
275
+ color: ${lightThemeHighlightColor};
276
+ }
277
+ .li-row:hover > a {
278
+ color: ${lightThemeHighlightColor};
279
+ }
280
+ html.dark .li-row:hover {
281
+ color: ${darkThemeHighlightColor};
282
+ }
283
+ html.dark .li-row:hover > .li-marker::before {
284
+ color: ${darkThemeHighlightColor};
285
+ }
286
+ html.dark .li-row:hover > a {
287
+ color: ${darkThemeHighlightColor};
288
+ }
289
+ }
290
+ .toc-title:active {
291
+ color: ${lightThemeHighlightColor};
292
+ cursor: pointer;
293
+ }
294
+ html.dark .toc-title:active {
295
+ color: ${darkThemeHighlightColor};
296
+ }
297
+ .li-row:active {
298
+ color: ${lightThemeHighlightColor};
299
+ }
300
+ .li-row:active > .li-marker::before {
301
+ color: ${lightThemeHighlightColor};
302
+ }
303
+ .li-row:active > a {
304
+ color: ${lightThemeHighlightColor};
305
+ }
306
+ html.dark .li-row:active {
307
+ color: ${darkThemeHighlightColor};
308
+ }
309
+ html.dark .li-row:active > .li-marker::before {
310
+ color: ${darkThemeHighlightColor};
311
+ }
312
+ html.dark .li-row:active > a {
313
+ color: ${darkThemeHighlightColor};
314
+ }
315
+ `;
316
+ const iframeContent = `
317
+ <iframe
318
+ style="display:none;"
319
+ srcdoc="&lt;!DOCTYPE html&gt;
320
+ &lt;html&gt;
321
+ &lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;/head&gt;
322
+ &lt;body&gt;
323
+ <script is:inline data-astro-rerun>
324
+ const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
325
+ const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
326
+
327
+ function syncTocTitle(
328
+ locale,
329
+ languageMap
330
+ ) {
331
+ const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
332
+
333
+ if (tocSummary) {
334
+ const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
335
+ const translation =
336
+ languageMap[locale] || '${title}' || titleKey;
337
+ tocSummary.textContent = translation;
338
+ }
279
339
  }
280
- html.dark .li-row:hover > a {
281
- color: ${darkThemeHighlightColor};
340
+
341
+ function toggleToc() {
342
+ const tocTitle = window.parent.document.querySelector('.toc-title');
343
+ if (tocTitle) {
344
+ tocTitle.addEventListener('click', function () {
345
+ tocTitle.classList.toggle('open');
346
+ })
347
+ }
282
348
  }
349
+
350
+ window.addEventListener('load', function() {
351
+ if (window.parent.document.readyState === 'complete') {
352
+ syncTocTitle(currentLocale, languageMap);
353
+ toggleToc();
354
+ } else {
355
+ window.parent.document.addEventListener('readystatechange', event => {
356
+ if (event.target.readyState === 'complete') {
357
+ syncTocTitle(currentLocale, languageMap);
358
+ toggleToc();
359
+ }
360
+ });
361
+ }
362
+ });
363
+ <\/script>
364
+ &lt;/body&gt;
365
+ &lt;/html&gt;">
366
+ </iframe>
367
+ `;
368
+ const totalNodeStr = `
369
+ <div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul:has(> li) {
370
+ list-style-type: none;
371
+ counter-reset: toc-counter;
283
372
  }
284
- .toc-title:active {
285
- color: ${lightThemeHighlightColor};
286
- cursor: pointer;
373
+ li {
374
+ counter-increment: toc-counter;
287
375
  }
288
- html.dark .toc-title:active {
289
- color: ${darkThemeHighlightColor};
376
+ .li-marker::before {
377
+ content: counters(toc-counter, ".");
378
+ }` : "") + (opt.animation && animation !== void 0 && typeof animation !== "boolean" ? `.toc-wrapper {
379
+ max-height: 2rem;
380
+ transition: max-height ${animation.duration} ${animation.timingFunction};
290
381
  }
291
- .li-row:active {
292
- color: ${lightThemeHighlightColor};
382
+ .toc-wrapper:has(.toc-title.open) {
383
+ max-height: 100vh;
293
384
  }
294
- .li-row:active > .li-marker::before {
295
- color: ${lightThemeHighlightColor};
385
+ ` : "") + (opt.titleMarkerType === "icon" ? `
386
+ .toc-title::before {
387
+ content: '${closedMarker} ';
388
+ display: contents;
389
+ font-size: 1rem;
296
390
  }
297
- .li-row:active > a {
298
- color: ${lightThemeHighlightColor};
391
+ .toc-title.open::before {
392
+ content: '${openedMarker} ';
393
+ display: contents;
394
+ font-size: 1rem;
299
395
  }
300
- html.dark .li-row:active {
301
- color: ${darkThemeHighlightColor};
396
+ ` : "") + (opt.titleMarkerType === "image" ? `
397
+ .toc-wrapper > .toc-title, .toc-wrapper > ul {
398
+ margin-left: 2rem;
302
399
  }
303
- html.dark .li-row:active > .li-marker::before {
304
- color: ${darkThemeHighlightColor};
400
+ .toc-title::before {
401
+ content: "";
402
+ background: url('${closedMarker}') center / contain no-repeat;
403
+ width: ${titleMarkerCssSize};
404
+ height: ${titleMarkerCssSize};
405
+ position: absolute;
406
+ left: -2rem;
407
+ top: 50%;
408
+ transform: translateY(-50%);
305
409
  }
306
- html.dark .li-row:active > a {
307
- color: ${darkThemeHighlightColor};
410
+ .toc-title.open::before {
411
+ content: "";
412
+ background: url('${openedMarker}') center / contain no-repeat;
413
+ width: ${titleMarkerCssSize};
414
+ height: ${titleMarkerCssSize};
415
+ position: absolute;
416
+ left: -2rem;
417
+ top: 50%;
418
+ transform: translateY(-50%);
308
419
  }
309
- `;
310
- const iframeContent = `
311
- <iframe
312
- style="display:none;"
313
- srcdoc="&lt;!DOCTYPE html&gt;
314
- &lt;html&gt;
315
- &lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;&lt;/head&gt;
316
- &lt;body&gt;
317
- <script is:inline data-astro-rerun>
318
- const currentLocale = window.parent.location.pathname.split('/')[1] || '${opt.locale || "en-US"}';
319
- const languageMap = ${JSON.stringify(opt.languageMap).replaceAll("\"", "'")} || ${JSON.stringify(DEFAULT_LANGUAGE_MAP).replaceAll("\"", "'")};
320
-
321
- function syncTocTitle(
322
- locale,
323
- languageMap
324
- ) {
325
- const tocSummary = window.parent.document.querySelector('[data-satteri-toc-title]');
326
-
327
- if (tocSummary) {
328
- const titleKey = tocSummary.getAttribute('data-satteri-toc-title');
329
- const translation =
330
- languageMap[locale] || '${title}' || titleKey;
331
- tocSummary.textContent = translation;
332
- }
333
- }
334
-
335
- function toggleToc() {
336
- const tocTitle = window.parent.document.querySelector('.toc-title');
337
- if (tocTitle) {
338
- tocTitle.addEventListener('click', function () {
339
- tocTitle.classList.toggle('open');
340
- })
341
- }
342
- }
343
-
344
- window.addEventListener('load', function() {
345
- if (window.parent.document.readyState === 'complete') {
346
- syncTocTitle(currentLocale, languageMap);
347
- toggleToc();
348
- } else {
349
- window.parent.document.addEventListener('readystatechange', event => {
350
- if (event.target.readyState === 'complete') {
351
- syncTocTitle(currentLocale, languageMap);
352
- toggleToc();
353
- }
354
- });
355
- }
356
- });
357
- <\/script>
358
- &lt;/body&gt;
359
- &lt;/html&gt;">
360
- </iframe>
361
- `;
362
- ctx.data.nodeStr = `
363
- <div class="toc-wrapper"><style>${baseStyle + (opt.globalStyle ?? "") + (opt.listStyle === "decimal" ? `ul:has(> li) {
364
- list-style-type: none;
365
- counter-reset: toc-counter;
366
- }
367
- li {
368
- counter-increment: toc-counter;
369
- }
370
- .li-marker::before {
371
- content: counters(toc-counter, ".");
372
- }` : "") + (opt.animation && animation !== void 0 ? `.toc-wrapper {
373
- max-height: 2rem;
374
- transition: max-height ${animation.duration} ${animation.timingFunction};
375
- }
376
- .toc-wrapper:has(.toc-title.open) {
377
- max-height: 100vh;
378
- }
379
- ` : "") + (opt.titleMarkerType === "icon" ? `
380
- .toc-title::before {
381
- content: '${closedMarker} ';
382
- display: contents;
383
- font-size: 1rem;
384
- }
385
- .toc-title.open::before {
386
- content: '${openedMarker} ';
387
- display: contents;
388
- font-size: 1rem;
389
- }
390
- ` : "") + (opt.titleMarkerType === "image" ? `
391
- .toc-wrapper > .toc-title, .toc-wrapper > ul {
392
- margin-left: 2rem;
393
- }
394
- .toc-title::before {
395
- content: "";
396
- background: url('${closedMarker}') center / contain no-repeat;
397
- width: ${titleMarkerCssSize};
398
- height: ${titleMarkerCssSize};
399
- position: absolute;
400
- left: -2rem;
401
- top: 50%;
402
- transform: translateY(-50%);
403
- }
404
- .toc-title.open::before {
405
- content: "";
406
- background: url('${openedMarker}') center / contain no-repeat;
407
- width: ${titleMarkerCssSize};
408
- height: ${titleMarkerCssSize};
409
- position: absolute;
410
- left: -2rem;
411
- top: 50%;
412
- transform: translateY(-50%);
413
- }
414
- ` : "")}</style><h2 data-satteri-toc-title="${title}" class="toc-title ${opt.class?.title ?? ""}" style="${opt.style?.title ?? ""}">${title}</h2>${collectedNodeStr}${iframeContent}</div>
415
- `;
416
- ctx.replaceNode(parent.children[ctx.data.firstHeadingIndex], {
417
- type: "raw",
418
- value: ctx.data.nodeStr + `<h${ctx.data.firstHeadingDepth} id="${ctx.data.firstHeadingId}">${ctx.data.firstHeading && ctx.textContent(ctx.data.firstHeading)}</h${ctx.data.firstHeadingDepth}>`
419
- });
420
- }
421
- } catch (err) {
422
- throw err;
423
- }
420
+ ` : "")}</style><h2 data-satteri-toc-title="${title}" class="toc-title ${opt.class?.title ?? ""}" style="${opt.style?.title ?? ""}">${title}</h2>${collectedNodeStr}${iframeContent}</div>
421
+ `;
422
+ if (firstHeading.headingIndex !== void 0) ctx.replaceNode(root.children[firstHeading.headingIndex], {
423
+ type: "raw",
424
+ value: totalNodeStr + `<h${firstHeading.headingDepth} id="${firstHeading.headingId}">${firstHeading.headingText || ""}</h${firstHeading.headingDepth}>`
425
+ });
424
426
  }
425
- }]
427
+ }
426
428
  });
427
429
  }
428
430
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pretty-toc",
3
- "version": "1.2.4",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "A Table of Contents generation plugin for the Satteri markdown parser library.",
6
6
  "keywords": [
@@ -49,13 +49,13 @@
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@types/slug": "^5.0.9",
52
- "satteri": "^0.9.5",
52
+ "satteri": "^0.10.5",
53
53
  "slug": "^12.0.1"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@rollup/plugin-url": "^8.0.2",
57
- "@types/hast": "^3.0.4",
58
- "@types/node": "^26.1.1",
57
+ "@types/hast": "^3.0.5",
58
+ "@types/node": "^26.4.1",
59
59
  "bumpp": "^11.1.0",
60
60
  "tsdown": "^0.22.5",
61
61
  "typescript": "^7.0.2",