@mdit-vue/shared 0.11.0 → 0.12.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.
package/dist/index.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  const htmlEscapeMap = {
6
4
  "&": "&",
7
5
  "<": "&lt;",
@@ -40,7 +38,8 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
40
38
  titleTokenTypes.push("html_inline");
41
39
  }
42
40
  const titleTokens = children.filter(
43
- (item) => titleTokenTypes.includes(item.type) && !item.meta?.isPermalinkSymbol
41
+ (item) => titleTokenTypes.includes(item.type) && // filter permalink symbol that generated by markdown-it-anchor
42
+ !item.meta?.isPermalinkSymbol
44
43
  );
45
44
  return titleTokens.reduce((result, item) => {
46
45
  if (shouldEscapeText) {
@@ -55,6 +54,7 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
55
54
  const resolveHeadersFromTokens = (tokens, {
56
55
  level,
57
56
  shouldAllowHtml,
57
+ shouldAllowNested,
58
58
  shouldEscapeText,
59
59
  slugify,
60
60
  format
@@ -78,6 +78,9 @@ const resolveHeadersFromTokens = (tokens, {
78
78
  if (token?.type !== "heading_open") {
79
79
  continue;
80
80
  }
81
+ if (token?.level !== 0 && !shouldAllowNested) {
82
+ continue;
83
+ }
81
84
  const headerLevel = Number.parseInt(token.tag.slice(1), 10);
82
85
  if (!level.includes(headerLevel)) {
83
86
  continue;
package/dist/index.d.ts CHANGED
@@ -39,6 +39,12 @@ interface ResolveHeadersOptions extends ResolveTitleOptions {
39
39
  * Heading level that going to be resolved
40
40
  */
41
41
  level: number[];
42
+ /**
43
+ * Should allow headers inside nested blocks or not
44
+ *
45
+ * If set to `true`, headers inside blockquote, list, etc. would also be resolved.
46
+ */
47
+ shouldAllowNested: boolean;
42
48
  /**
43
49
  * A custom slugification function
44
50
  *
@@ -53,7 +59,7 @@ interface ResolveHeadersOptions extends ResolveTitleOptions {
53
59
  /**
54
60
  * Resolve headers from markdown-it tokens
55
61
  */
56
- declare const resolveHeadersFromTokens: (tokens: Token[], { level, shouldAllowHtml, shouldEscapeText, slugify, format, }: ResolveHeadersOptions) => MarkdownItHeader[];
62
+ declare const resolveHeadersFromTokens: (tokens: Token[], { level, shouldAllowHtml, shouldAllowNested, shouldEscapeText, slugify, format, }: ResolveHeadersOptions) => MarkdownItHeader[];
57
63
 
58
64
  /**
59
65
  * Default slugification function
package/dist/index.mjs CHANGED
@@ -36,7 +36,8 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
36
36
  titleTokenTypes.push("html_inline");
37
37
  }
38
38
  const titleTokens = children.filter(
39
- (item) => titleTokenTypes.includes(item.type) && !item.meta?.isPermalinkSymbol
39
+ (item) => titleTokenTypes.includes(item.type) && // filter permalink symbol that generated by markdown-it-anchor
40
+ !item.meta?.isPermalinkSymbol
40
41
  );
41
42
  return titleTokens.reduce((result, item) => {
42
43
  if (shouldEscapeText) {
@@ -51,6 +52,7 @@ const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) =>
51
52
  const resolveHeadersFromTokens = (tokens, {
52
53
  level,
53
54
  shouldAllowHtml,
55
+ shouldAllowNested,
54
56
  shouldEscapeText,
55
57
  slugify,
56
58
  format
@@ -74,6 +76,9 @@ const resolveHeadersFromTokens = (tokens, {
74
76
  if (token?.type !== "heading_open") {
75
77
  continue;
76
78
  }
79
+ if (token?.level !== 0 && !shouldAllowNested) {
80
+ continue;
81
+ }
77
82
  const headerLevel = Number.parseInt(token.tag.slice(1), 10);
78
83
  if (!level.includes(headerLevel)) {
79
84
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/shared",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Shared utils and types of mdit-vue",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -36,12 +36,12 @@
36
36
  "test": "vitest"
37
37
  },
38
38
  "dependencies": {
39
- "@mdit-vue/types": "0.11.0",
39
+ "@mdit-vue/types": "0.12.0",
40
40
  "@types/markdown-it": "^12.2.3",
41
41
  "markdown-it": "^13.0.1"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public"
45
45
  },
46
- "gitHead": "6e4f18dacc06e0aa5d3108df8925f6b0aa885150"
46
+ "gitHead": "986b6023d3460cadefd409cd5d4b6445af3a05bd"
47
47
  }