@mdit-vue/plugin-toc 0.12.0 → 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/dist/index.cjs CHANGED
@@ -26,34 +26,32 @@ const createTocBlockRule = ({
26
26
  pattern,
27
27
  containerTag,
28
28
  containerClass
29
- }) => {
30
- return (state, startLine, endLine, silent) => {
31
- if (state.sCount[startLine] - state.blkIndent >= 4) {
32
- return false;
33
- }
34
- const pos = state.bMarks[startLine] + state.tShift[startLine];
35
- const max = state.eMarks[startLine];
36
- const lineFirstToken = state.src.slice(pos, max).split(" ")[0];
37
- if (!pattern.test(lineFirstToken))
38
- return false;
39
- if (silent)
40
- return true;
41
- state.line = startLine + 1;
42
- const tokenOpen = state.push("toc_open", containerTag, 1);
43
- tokenOpen.markup = "";
44
- tokenOpen.map = [startLine, state.line];
45
- if (containerClass) {
46
- tokenOpen.attrSet("class", containerClass);
47
- }
48
- const tokenBody = state.push("toc_body", "", 0);
49
- tokenBody.markup = lineFirstToken;
50
- tokenBody.map = [startLine, state.line];
51
- tokenBody.hidden = true;
52
- const tokenClose = state.push("toc_close", containerTag, -1);
53
- tokenClose.markup = "";
54
- tokenBody.map = [startLine, state.line];
29
+ }) => (state, startLine, endLine, silent) => {
30
+ if (state.sCount[startLine] - state.blkIndent >= 4) {
31
+ return false;
32
+ }
33
+ const pos = state.bMarks[startLine] + state.tShift[startLine];
34
+ const max = state.eMarks[startLine];
35
+ const lineFirstToken = state.src.slice(pos, max).split(" ")[0];
36
+ if (!pattern.test(lineFirstToken))
37
+ return false;
38
+ if (silent)
55
39
  return true;
56
- };
40
+ state.line = startLine + 1;
41
+ const tokenOpen = state.push("toc_open", containerTag, 1);
42
+ tokenOpen.markup = "";
43
+ tokenOpen.map = [startLine, state.line];
44
+ if (containerClass) {
45
+ tokenOpen.attrSet("class", containerClass);
46
+ }
47
+ const tokenBody = state.push("toc_body", "", 0);
48
+ tokenBody.markup = lineFirstToken;
49
+ tokenBody.map = [startLine, state.line];
50
+ tokenBody.hidden = true;
51
+ const tokenClose = state.push("toc_close", containerTag, -1);
52
+ tokenClose.markup = "";
53
+ tokenBody.map = [startLine, state.line];
54
+ return true;
57
55
  };
58
56
 
59
57
  const tocPlugin = (md, {
@@ -0,0 +1,109 @@
1
+ import { MarkdownItHeader } from '@mdit-vue/types';
2
+ import ParserBlock from 'markdown-it/lib/parser_block.js';
3
+ import MarkdownIt from 'markdown-it';
4
+
5
+ /**
6
+ * Options of @mdit-vue/plugin-toc
7
+ */
8
+ interface TocPluginOptions {
9
+ /**
10
+ * The pattern serving as the TOC placeholder in your markdown
11
+ *
12
+ * @default /^\[\[toc\]\]$/i
13
+ */
14
+ pattern?: RegExp;
15
+ /**
16
+ * A custom slugification function
17
+ *
18
+ * Should use the same slugify function with markdown-it-anchor
19
+ * to ensure the link is matched
20
+ */
21
+ slugify?: (str: string) => string;
22
+ /**
23
+ * A function for formatting headings
24
+ */
25
+ format?: (str: string) => string;
26
+ /**
27
+ * Heading level that going to be included in the TOC
28
+ *
29
+ * Should be a subset of markdown-it-anchor's `level` option
30
+ * to ensure the link is existed
31
+ *
32
+ * @default [2,3]
33
+ */
34
+ level?: number[];
35
+ /**
36
+ * Should allow headers inside nested blocks or not
37
+ *
38
+ * If set to `true`, headers inside blockquote, list, etc. would also be included.
39
+ *
40
+ * @default false
41
+ */
42
+ shouldAllowNested?: boolean;
43
+ /**
44
+ * HTML tag of the TOC container
45
+ *
46
+ * @default 'nav'
47
+ */
48
+ containerTag?: string;
49
+ /**
50
+ * The class for the TOC container
51
+ *
52
+ * @default 'table-of-contents'
53
+ */
54
+ containerClass?: string;
55
+ /**
56
+ * HTML tag of the TOC list
57
+ *
58
+ * @default 'ul'
59
+ */
60
+ listTag?: 'ul' | 'ol';
61
+ /**
62
+ * The class for the TOC list
63
+ *
64
+ * @default ''
65
+ */
66
+ listClass?: string;
67
+ /**
68
+ * The class for the `<li>` tag
69
+ *
70
+ * @default ''
71
+ */
72
+ itemClass?: string;
73
+ /**
74
+ * The tag of the link inside `<li>` tag
75
+ *
76
+ * @default 'a'
77
+ */
78
+ linkTag?: 'a' | 'router-link';
79
+ /**
80
+ * The class for the link inside the `<li>` tag
81
+ *
82
+ * @default ''
83
+ */
84
+ linkClass?: string;
85
+ }
86
+
87
+ type RenderHeadersFn = (headers: MarkdownItHeader[]) => string;
88
+ declare const createRenderHeaders: ({ listTag, listClass, itemClass, linkTag, linkClass, }: Pick<Required<TocPluginOptions>, 'listTag' | 'listClass' | 'itemClass' | 'linkTag' | 'linkClass'>) => RenderHeadersFn;
89
+
90
+ /**
91
+ * Forked and modified from markdown-it-toc-done-right
92
+ *
93
+ * - remove the `inlineOptions` support
94
+ * - use markdown-it default renderer to render token whenever possible
95
+ *
96
+ * @see https://github.com/nagaozen/markdown-it-toc-done-right
97
+ */
98
+ declare const createTocBlockRule: ({ pattern, containerTag, containerClass, }: Pick<Required<TocPluginOptions>, 'pattern' | 'containerTag' | 'containerClass'>) => ParserBlock.RuleBlock;
99
+
100
+ /**
101
+ * Generate table of contents
102
+ *
103
+ * Forked and modified from markdown-it-toc-done-right:
104
+ *
105
+ * @see https://github.com/nagaozen/markdown-it-toc-done-right
106
+ */
107
+ declare const tocPlugin: MarkdownIt.PluginWithOptions<TocPluginOptions>;
108
+
109
+ export { type TocPluginOptions, createRenderHeaders, createTocBlockRule, tocPlugin };
@@ -0,0 +1,109 @@
1
+ import { MarkdownItHeader } from '@mdit-vue/types';
2
+ import ParserBlock from 'markdown-it/lib/parser_block.js';
3
+ import MarkdownIt from 'markdown-it';
4
+
5
+ /**
6
+ * Options of @mdit-vue/plugin-toc
7
+ */
8
+ interface TocPluginOptions {
9
+ /**
10
+ * The pattern serving as the TOC placeholder in your markdown
11
+ *
12
+ * @default /^\[\[toc\]\]$/i
13
+ */
14
+ pattern?: RegExp;
15
+ /**
16
+ * A custom slugification function
17
+ *
18
+ * Should use the same slugify function with markdown-it-anchor
19
+ * to ensure the link is matched
20
+ */
21
+ slugify?: (str: string) => string;
22
+ /**
23
+ * A function for formatting headings
24
+ */
25
+ format?: (str: string) => string;
26
+ /**
27
+ * Heading level that going to be included in the TOC
28
+ *
29
+ * Should be a subset of markdown-it-anchor's `level` option
30
+ * to ensure the link is existed
31
+ *
32
+ * @default [2,3]
33
+ */
34
+ level?: number[];
35
+ /**
36
+ * Should allow headers inside nested blocks or not
37
+ *
38
+ * If set to `true`, headers inside blockquote, list, etc. would also be included.
39
+ *
40
+ * @default false
41
+ */
42
+ shouldAllowNested?: boolean;
43
+ /**
44
+ * HTML tag of the TOC container
45
+ *
46
+ * @default 'nav'
47
+ */
48
+ containerTag?: string;
49
+ /**
50
+ * The class for the TOC container
51
+ *
52
+ * @default 'table-of-contents'
53
+ */
54
+ containerClass?: string;
55
+ /**
56
+ * HTML tag of the TOC list
57
+ *
58
+ * @default 'ul'
59
+ */
60
+ listTag?: 'ul' | 'ol';
61
+ /**
62
+ * The class for the TOC list
63
+ *
64
+ * @default ''
65
+ */
66
+ listClass?: string;
67
+ /**
68
+ * The class for the `<li>` tag
69
+ *
70
+ * @default ''
71
+ */
72
+ itemClass?: string;
73
+ /**
74
+ * The tag of the link inside `<li>` tag
75
+ *
76
+ * @default 'a'
77
+ */
78
+ linkTag?: 'a' | 'router-link';
79
+ /**
80
+ * The class for the link inside the `<li>` tag
81
+ *
82
+ * @default ''
83
+ */
84
+ linkClass?: string;
85
+ }
86
+
87
+ type RenderHeadersFn = (headers: MarkdownItHeader[]) => string;
88
+ declare const createRenderHeaders: ({ listTag, listClass, itemClass, linkTag, linkClass, }: Pick<Required<TocPluginOptions>, 'listTag' | 'listClass' | 'itemClass' | 'linkTag' | 'linkClass'>) => RenderHeadersFn;
89
+
90
+ /**
91
+ * Forked and modified from markdown-it-toc-done-right
92
+ *
93
+ * - remove the `inlineOptions` support
94
+ * - use markdown-it default renderer to render token whenever possible
95
+ *
96
+ * @see https://github.com/nagaozen/markdown-it-toc-done-right
97
+ */
98
+ declare const createTocBlockRule: ({ pattern, containerTag, containerClass, }: Pick<Required<TocPluginOptions>, 'pattern' | 'containerTag' | 'containerClass'>) => ParserBlock.RuleBlock;
99
+
100
+ /**
101
+ * Generate table of contents
102
+ *
103
+ * Forked and modified from markdown-it-toc-done-right:
104
+ *
105
+ * @see https://github.com/nagaozen/markdown-it-toc-done-right
106
+ */
107
+ declare const tocPlugin: MarkdownIt.PluginWithOptions<TocPluginOptions>;
108
+
109
+ export { type TocPluginOptions, createRenderHeaders, createTocBlockRule, tocPlugin };
package/dist/index.d.ts CHANGED
@@ -106,4 +106,4 @@ declare const createTocBlockRule: ({ pattern, containerTag, containerClass, }: P
106
106
  */
107
107
  declare const tocPlugin: MarkdownIt.PluginWithOptions<TocPluginOptions>;
108
108
 
109
- export { TocPluginOptions, createRenderHeaders, createTocBlockRule, tocPlugin };
109
+ export { type TocPluginOptions, createRenderHeaders, createTocBlockRule, tocPlugin };
package/dist/index.mjs CHANGED
@@ -24,34 +24,32 @@ const createTocBlockRule = ({
24
24
  pattern,
25
25
  containerTag,
26
26
  containerClass
27
- }) => {
28
- return (state, startLine, endLine, silent) => {
29
- if (state.sCount[startLine] - state.blkIndent >= 4) {
30
- return false;
31
- }
32
- const pos = state.bMarks[startLine] + state.tShift[startLine];
33
- const max = state.eMarks[startLine];
34
- const lineFirstToken = state.src.slice(pos, max).split(" ")[0];
35
- if (!pattern.test(lineFirstToken))
36
- return false;
37
- if (silent)
38
- return true;
39
- state.line = startLine + 1;
40
- const tokenOpen = state.push("toc_open", containerTag, 1);
41
- tokenOpen.markup = "";
42
- tokenOpen.map = [startLine, state.line];
43
- if (containerClass) {
44
- tokenOpen.attrSet("class", containerClass);
45
- }
46
- const tokenBody = state.push("toc_body", "", 0);
47
- tokenBody.markup = lineFirstToken;
48
- tokenBody.map = [startLine, state.line];
49
- tokenBody.hidden = true;
50
- const tokenClose = state.push("toc_close", containerTag, -1);
51
- tokenClose.markup = "";
52
- tokenBody.map = [startLine, state.line];
27
+ }) => (state, startLine, endLine, silent) => {
28
+ if (state.sCount[startLine] - state.blkIndent >= 4) {
29
+ return false;
30
+ }
31
+ const pos = state.bMarks[startLine] + state.tShift[startLine];
32
+ const max = state.eMarks[startLine];
33
+ const lineFirstToken = state.src.slice(pos, max).split(" ")[0];
34
+ if (!pattern.test(lineFirstToken))
35
+ return false;
36
+ if (silent)
53
37
  return true;
54
- };
38
+ state.line = startLine + 1;
39
+ const tokenOpen = state.push("toc_open", containerTag, 1);
40
+ tokenOpen.markup = "";
41
+ tokenOpen.map = [startLine, state.line];
42
+ if (containerClass) {
43
+ tokenOpen.attrSet("class", containerClass);
44
+ }
45
+ const tokenBody = state.push("toc_body", "", 0);
46
+ tokenBody.markup = lineFirstToken;
47
+ tokenBody.map = [startLine, state.line];
48
+ tokenBody.hidden = true;
49
+ const tokenClose = state.push("toc_close", containerTag, -1);
50
+ tokenClose.markup = "";
51
+ tokenBody.map = [startLine, state.line];
52
+ return true;
55
53
  };
56
54
 
57
55
  const tocPlugin = (md, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdit-vue/plugin-toc",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "A markdown-it plugin to generate table-of-contents that compatible with Vue.js",
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.12.0",
41
+ "@mdit-vue/shared": "0.12.1",
42
42
  "@mdit-vue/types": "0.12.0",
43
- "@types/markdown-it": "^12.2.3",
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": "986b6023d3460cadefd409cd5d4b6445af3a05bd"
52
+ "gitHead": "198a71b2e4175a92843609a63d2a848bddb71740"
53
53
  }