@mdit-vue/plugin-headers 0.11.2 → 0.12.1

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
@@ -59,6 +59,18 @@ console.log(env.headers);
59
59
 
60
60
  When using this plugin with [markdown-it-anchor](https://github.com/valeriangalliat/markdown-it-anchor) (recommended), this option should be a subset of markdown-it-anchor's `level` option to ensure the header slugs are existed.
61
61
 
62
+ ### shouldAllowNested
63
+
64
+ - Type: `boolean`
65
+
66
+ - Default: `false`
67
+
68
+ - Details:
69
+
70
+ Should allow headers inside nested blocks or not.
71
+
72
+ If set to `true`, headers inside blockquote, list, etc. would also be extracted.
73
+
62
74
  ### slugify
63
75
 
64
76
  - Type: `(str: string) => string`
package/dist/index.cjs CHANGED
@@ -2,12 +2,18 @@
2
2
 
3
3
  const shared = require('@mdit-vue/shared');
4
4
 
5
- const headersPlugin = (md, { level = [2, 3], slugify = shared.slugify, format } = {}) => {
5
+ const headersPlugin = (md, {
6
+ level = [2, 3],
7
+ shouldAllowNested = false,
8
+ slugify = shared.slugify,
9
+ format
10
+ } = {}) => {
6
11
  const render = md.renderer.render.bind(md.renderer);
7
12
  md.renderer.render = (tokens, options, env) => {
8
13
  env.headers = shared.resolveHeadersFromTokens(tokens, {
9
14
  level,
10
15
  shouldAllowHtml: false,
16
+ shouldAllowNested,
11
17
  shouldEscapeText: false,
12
18
  slugify,
13
19
  format
@@ -0,0 +1,54 @@
1
+ import MarkdownIt from 'markdown-it';
2
+ import { MarkdownItHeader } from '@mdit-vue/types';
3
+ export { MarkdownItHeader } from '@mdit-vue/types';
4
+
5
+ /**
6
+ * Options of @mdit-vue/plugin-headers
7
+ */
8
+ interface HeadersPluginOptions {
9
+ /**
10
+ * A custom slugification function
11
+ *
12
+ * Should use the same slugify function with markdown-it-anchor
13
+ * to ensure the link is matched
14
+ */
15
+ slugify?: (str: string) => string;
16
+ /**
17
+ * A function for formatting header title
18
+ */
19
+ format?: (str: string) => string;
20
+ /**
21
+ * Heading level that going to be extracted
22
+ *
23
+ * Should be a subset of markdown-it-anchor's `level` option
24
+ * to ensure the slug is existed
25
+ *
26
+ * @default [2,3]
27
+ */
28
+ level?: number[];
29
+ /**
30
+ * Should allow headers inside nested blocks or not
31
+ *
32
+ * If set to `true`, headers inside blockquote, list, etc. would also be extracted.
33
+ *
34
+ * @default false
35
+ */
36
+ shouldAllowNested?: boolean;
37
+ }
38
+ declare module '@mdit-vue/types' {
39
+ interface MarkdownItEnv {
40
+ /**
41
+ * The headers that extracted by `@mdit-vue/plugin-headers`
42
+ */
43
+ headers?: MarkdownItHeader[];
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Get markdown headers info
49
+ *
50
+ * Extract them into env
51
+ */
52
+ declare const headersPlugin: MarkdownIt.PluginWithOptions<HeadersPluginOptions>;
53
+
54
+ export { type HeadersPluginOptions, headersPlugin };
@@ -0,0 +1,54 @@
1
+ import MarkdownIt from 'markdown-it';
2
+ import { MarkdownItHeader } from '@mdit-vue/types';
3
+ export { MarkdownItHeader } from '@mdit-vue/types';
4
+
5
+ /**
6
+ * Options of @mdit-vue/plugin-headers
7
+ */
8
+ interface HeadersPluginOptions {
9
+ /**
10
+ * A custom slugification function
11
+ *
12
+ * Should use the same slugify function with markdown-it-anchor
13
+ * to ensure the link is matched
14
+ */
15
+ slugify?: (str: string) => string;
16
+ /**
17
+ * A function for formatting header title
18
+ */
19
+ format?: (str: string) => string;
20
+ /**
21
+ * Heading level that going to be extracted
22
+ *
23
+ * Should be a subset of markdown-it-anchor's `level` option
24
+ * to ensure the slug is existed
25
+ *
26
+ * @default [2,3]
27
+ */
28
+ level?: number[];
29
+ /**
30
+ * Should allow headers inside nested blocks or not
31
+ *
32
+ * If set to `true`, headers inside blockquote, list, etc. would also be extracted.
33
+ *
34
+ * @default false
35
+ */
36
+ shouldAllowNested?: boolean;
37
+ }
38
+ declare module '@mdit-vue/types' {
39
+ interface MarkdownItEnv {
40
+ /**
41
+ * The headers that extracted by `@mdit-vue/plugin-headers`
42
+ */
43
+ headers?: MarkdownItHeader[];
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Get markdown headers info
49
+ *
50
+ * Extract them into env
51
+ */
52
+ declare const headersPlugin: MarkdownIt.PluginWithOptions<HeadersPluginOptions>;
53
+
54
+ export { type HeadersPluginOptions, headersPlugin };
package/dist/index.d.ts CHANGED
@@ -26,6 +26,14 @@ interface HeadersPluginOptions {
26
26
  * @default [2,3]
27
27
  */
28
28
  level?: number[];
29
+ /**
30
+ * Should allow headers inside nested blocks or not
31
+ *
32
+ * If set to `true`, headers inside blockquote, list, etc. would also be extracted.
33
+ *
34
+ * @default false
35
+ */
36
+ shouldAllowNested?: boolean;
29
37
  }
30
38
  declare module '@mdit-vue/types' {
31
39
  interface MarkdownItEnv {
@@ -43,4 +51,4 @@ declare module '@mdit-vue/types' {
43
51
  */
44
52
  declare const headersPlugin: MarkdownIt.PluginWithOptions<HeadersPluginOptions>;
45
53
 
46
- export { HeadersPluginOptions, headersPlugin };
54
+ export { type HeadersPluginOptions, headersPlugin };
package/dist/index.mjs CHANGED
@@ -1,11 +1,17 @@
1
1
  import { resolveHeadersFromTokens, slugify } from '@mdit-vue/shared';
2
2
 
3
- const headersPlugin = (md, { level = [2, 3], slugify: slugify$1 = slugify, format } = {}) => {
3
+ const headersPlugin = (md, {
4
+ level = [2, 3],
5
+ shouldAllowNested = false,
6
+ slugify: slugify$1 = slugify,
7
+ format
8
+ } = {}) => {
4
9
  const render = md.renderer.render.bind(md.renderer);
5
10
  md.renderer.render = (tokens, options, env) => {
6
11
  env.headers = resolveHeadersFromTokens(tokens, {
7
12
  level,
8
13
  shouldAllowHtml: false,
14
+ shouldAllowNested,
9
15
  shouldEscapeText: false,
10
16
  slugify: slugify$1,
11
17
  format
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/plugin-headers",
3
- "version": "0.11.2",
3
+ "version": "0.12.1",
4
4
  "description": "A markdown-it plugin to get markdown headers",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -38,16 +38,16 @@
38
38
  "test": "vitest"
39
39
  },
40
40
  "dependencies": {
41
- "@mdit-vue/shared": "0.11.2",
42
- "@mdit-vue/types": "0.11.0",
43
- "@types/markdown-it": "^12.2.3",
41
+ "@mdit-vue/shared": "0.12.1",
42
+ "@mdit-vue/types": "0.12.0",
43
+ "@types/markdown-it": "^13.0.0",
44
44
  "markdown-it": "^13.0.1"
45
45
  },
46
46
  "devDependencies": {
47
- "markdown-it-anchor": "^8.6.6"
47
+ "markdown-it-anchor": "^8.6.7"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"
51
51
  },
52
- "gitHead": "676ec4ca8704d709e7a47f7f6d41ff3f70dc2356"
52
+ "gitHead": "198a71b2e4175a92843609a63d2a848bddb71740"
53
53
  }