pretty-toc 0.1.6 → 0.1.7

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
@@ -80,7 +80,7 @@ processor: satteri({
80
80
  |lightThemeHighlightColor|string|eg. "oklch(0.75 0.1229 12.71)"|
81
81
  |darkThemeHighlightColor|string|eg. "oklch(0.81 0.1004 305.04)"|
82
82
  |class|{summary?: string, ul?: string, li?: string, a?: string}|eg. {summary: "pb-2", li: "py-1"}|
83
- |globalStyle|string|-|
84
- |style|Object{summary?: string, ul?: string, li?: string, a?: string}||
83
+ |globalStyle|string|eg. "summary {background-color: yellow;}"|
84
+ |style|Object{summary?: string, ul?: string, li?: string, a?: string}|eg. {a: "font-style: italic;"}|
85
85
  |locale|string|eg. "zh-CN" // **Note: The case of the locale variable should match the locale in your page URL.**|
86
86
  |languageMap|Record<string, string>|eg. {"en-US": "Table of Contents", "ja-JP": "目次"}|
package/dist/index.mjs CHANGED
@@ -82,7 +82,9 @@ function prettyToc(option) {
82
82
  break;
83
83
  default: marker = "";
84
84
  }
85
- const 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><span data-depth='${depth}' style="display: none;"></span></li>`;
85
+ const tagSignal = `<span data-depth='${depth}' style="display: none;"></span>`;
86
+ const tagSignalLength = tagSignal.length;
87
+ const 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>${tagSignal}</li>`;
86
88
  ctx.setProperty(node, "id", contentSlug);
87
89
  let parent = ctx.parent(node);
88
90
  while (parent.type !== "root" && parent !== void 0) {
@@ -220,8 +222,8 @@ function prettyToc(option) {
220
222
  content: counters(toc-counter, ".");
221
223
  }` : "")}</style><summary data-satteri-toc-title="${opt.languageMap?.[opt.locale ?? "en-US"] ?? defaultTitle}" class="${opt.class?.summary ?? ""}" style="${opt.style?.summary ?? ""}">${opt.languageMap?.[opt.locale ?? "en-US"] ?? defaultTitle}</summary><ul class="${opt.class?.ul ?? ""}" style="${opt.style?.ul ?? ""}">${nodeStr}</ul>${iframeContent}</details>`;
222
224
  } else {
223
- const indexA = ctx.data.nodeStr?.lastIndexOf(`<span data-depth='${depth}' style="display: none;"></span>`);
224
- if (indexA !== -1) ctx.data.nodeStr = ctx.data.nodeStr?.slice(0, indexA + 56) + nodeStr + ctx.data.nodeStr?.slice(indexA + 56);
225
+ const indexA = ctx.data.nodeStr?.lastIndexOf(tagSignal);
226
+ if (indexA !== -1) ctx.data.nodeStr = ctx.data.nodeStr?.slice(0, indexA + tagSignalLength + 5) + nodeStr + ctx.data.nodeStr?.slice(indexA + tagSignalLength + 5);
225
227
  else if (depth > 1) {
226
228
  let indexB = -1;
227
229
  for (let i = depth; i > 0; i--) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pretty-toc",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "description": "A Table of Contents generation plugin for the Satteri markdown parser library.",
6
6
  "keywords": [