comark 0.3.1 → 0.4.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 (93) hide show
  1. package/dist/internal/frontmatter.d.ts +1 -0
  2. package/dist/internal/frontmatter.js +4 -2
  3. package/dist/internal/parse/auto-close/index.js +69 -31
  4. package/dist/internal/parse/auto-close/table.js +12 -9
  5. package/dist/internal/parse/auto-unwrap.js +6 -10
  6. package/dist/internal/parse/html/html_block_rule.js +10 -16
  7. package/dist/internal/parse/html/html_inline_rule.js +3 -7
  8. package/dist/internal/parse/html/html_re.js +1 -1
  9. package/dist/internal/parse/html/index.d.ts +1 -0
  10. package/dist/internal/parse/html/index.js +15 -3
  11. package/dist/internal/parse/syntax/block-params.d.ts +9 -0
  12. package/dist/internal/parse/syntax/block-params.js +48 -0
  13. package/dist/internal/parse/syntax/brackets.d.ts +8 -0
  14. package/dist/internal/parse/syntax/brackets.js +20 -0
  15. package/dist/internal/parse/syntax/props.d.ts +5 -0
  16. package/dist/internal/parse/syntax/props.js +119 -0
  17. package/dist/internal/parse/token-processor.js +89 -50
  18. package/dist/internal/props-validation.js +4 -9
  19. package/dist/internal/stringify/attributes.d.ts +7 -0
  20. package/dist/internal/stringify/attributes.js +56 -1
  21. package/dist/internal/stringify/handlers/a.js +1 -3
  22. package/dist/internal/stringify/handlers/blockquote.js +19 -4
  23. package/dist/internal/stringify/handlers/code.js +1 -3
  24. package/dist/internal/stringify/handlers/emphesis.js +1 -3
  25. package/dist/internal/stringify/handlers/heading.js +6 -1
  26. package/dist/internal/stringify/handlers/html.js +34 -18
  27. package/dist/internal/stringify/handlers/img.js +1 -3
  28. package/dist/internal/stringify/handlers/li.js +18 -9
  29. package/dist/internal/stringify/handlers/mdc.js +3 -4
  30. package/dist/internal/stringify/handlers/ol.js +12 -2
  31. package/dist/internal/stringify/handlers/p.d.ts +1 -1
  32. package/dist/internal/stringify/handlers/p.js +8 -1
  33. package/dist/internal/stringify/handlers/pre.js +20 -14
  34. package/dist/internal/stringify/handlers/strong.js +1 -3
  35. package/dist/internal/stringify/handlers/table.js +14 -5
  36. package/dist/internal/stringify/handlers/template.js +5 -2
  37. package/dist/internal/stringify/handlers/ul.js +12 -2
  38. package/dist/internal/stringify/state.js +1 -1
  39. package/dist/internal/yaml.js +1 -1
  40. package/dist/parse.d.ts +4 -4
  41. package/dist/parse.js +20 -10
  42. package/dist/plugins/alert.d.ts +1 -1
  43. package/dist/plugins/alert.js +1 -1
  44. package/dist/plugins/binding.d.ts +1 -1
  45. package/dist/plugins/binding.js +1 -3
  46. package/dist/plugins/breaks.d.ts +1 -1
  47. package/dist/plugins/breaks.js +1 -1
  48. package/dist/plugins/emoji.d.ts +1 -1
  49. package/dist/plugins/emoji.js +8 -8
  50. package/dist/plugins/footnotes.d.ts +1 -1
  51. package/dist/plugins/footnotes.js +19 -13
  52. package/dist/plugins/headings.d.ts +19 -8
  53. package/dist/plugins/headings.js +27 -19
  54. package/dist/plugins/highlight.d.ts +2 -12
  55. package/dist/plugins/highlight.js +201 -103
  56. package/dist/plugins/json-render.d.ts +1 -1
  57. package/dist/plugins/json-render.js +5 -9
  58. package/dist/plugins/math.d.ts +1 -1
  59. package/dist/plugins/math.js +4 -6
  60. package/dist/plugins/mermaid.d.ts +1 -1
  61. package/dist/plugins/mermaid.js +6 -20
  62. package/dist/plugins/punctuation.d.ts +1 -1
  63. package/dist/plugins/punctuation.js +5 -6
  64. package/dist/plugins/security.d.ts +1 -1
  65. package/dist/plugins/security.js +2 -2
  66. package/dist/plugins/summary.d.ts +4 -1
  67. package/dist/plugins/syntax.d.ts +49 -0
  68. package/dist/plugins/syntax.js +558 -0
  69. package/dist/plugins/task-list.d.ts +2 -2
  70. package/dist/plugins/task-list.js +11 -8
  71. package/dist/plugins/toc.d.ts +3 -1
  72. package/dist/plugins/toc.js +1 -1
  73. package/dist/types.d.ts +57 -12
  74. package/dist/utils/comark.tmLanguage.d.ts +335 -0
  75. package/dist/utils/comark.tmLanguage.js +597 -0
  76. package/dist/utils/helpers.d.ts +16 -4
  77. package/dist/utils/helpers.js +16 -6
  78. package/dist/utils/index.d.ts +5 -0
  79. package/dist/utils/index.js +25 -3
  80. package/package.json +40 -40
  81. package/skills/comark/references/rendering-svelte.md +51 -7
  82. package/dist/internal/stringify/indent.d.ts +0 -5
  83. package/dist/internal/stringify/indent.js +0 -9
  84. package/dist/vite.d.ts +0 -1
  85. package/dist/vite.js +0 -1
  86. package/skills/skills/comark/AGENTS.md +0 -261
  87. package/skills/skills/comark/SKILL.md +0 -489
  88. package/skills/skills/comark/references/markdown-syntax.md +0 -599
  89. package/skills/skills/comark/references/parsing-ast.md +0 -378
  90. package/skills/skills/comark/references/rendering-react.md +0 -445
  91. package/skills/skills/comark/references/rendering-svelte.md +0 -453
  92. package/skills/skills/comark/references/rendering-vue.md +0 -462
  93. /package/skills/{skills/migrate-mdc-to-comark → migrate-mdc-to-comark}/SKILL.md +0 -0
@@ -43,7 +43,7 @@ export function searchProps(content, index = 0) {
43
43
  '(': ')',
44
44
  };
45
45
  const quotePairs = {
46
- '\'': '\'',
46
+ "'": "'",
47
47
  '"': '"',
48
48
  '`': '`',
49
49
  };
@@ -67,17 +67,11 @@ export function searchProps(content, index = 0) {
67
67
  }
68
68
  else if (content[index] === '.') {
69
69
  index += 1;
70
- props.push([
71
- 'class',
72
- searchUntil(' #.}'),
73
- ]);
70
+ props.push(['class', searchUntil(' #.}')]);
74
71
  }
75
72
  else if (content[index] === '#') {
76
73
  index += 1;
77
- props.push([
78
- 'id',
79
- searchUntil(' #.}'),
80
- ]);
74
+ props.push(['id', searchUntil(' #.}')]);
81
75
  }
82
76
  else {
83
77
  const start = index;
@@ -91,16 +85,10 @@ export function searchProps(content, index = 0) {
91
85
  const key = content.slice(start, index).trim();
92
86
  if (char === '=') {
93
87
  index += 1;
94
- props.push([
95
- key,
96
- searchValue(),
97
- ]);
88
+ props.push([key, searchValue()]);
98
89
  }
99
90
  else {
100
- props.push([
101
- key,
102
- 'true',
103
- ]);
91
+ props.push([key, 'true']);
104
92
  }
105
93
  }
106
94
  }
@@ -178,7 +166,5 @@ export function searchProps(content, index = 0) {
178
166
  */
179
167
  export default defineComarkPlugin((config = {}) => ({
180
168
  name: 'mermaid',
181
- markdownItPlugins: [
182
- ((md) => markdownItMermaid(md, config)),
183
- ],
169
+ markdownItPlugins: [((md) => markdownItMermaid(md, config))],
184
170
  }));
@@ -63,5 +63,5 @@ export interface PunctuationOptions {
63
63
  * })
64
64
  * ```
65
65
  */
66
- declare const _default: import("comark").ComarkPluginFactory<PunctuationOptions>;
66
+ declare const _default: import("comark").ComarkPluginFactory<PunctuationOptions, {}, {}>;
67
67
  export default _default;
@@ -3,8 +3,7 @@ const DEFAULT_QUOTES = '\u201C\u201D\u2018\u2019'; // ""''
3
3
  /** Tags whose text content should not be transformed */
4
4
  const SKIP_TAGS = new Set(['code', 'pre', 'math', 'script', 'style', 'kbd']);
5
5
  function isWhitespaceOrOpener(ch) {
6
- return ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r'
7
- || ch === '(' || ch === '[' || ch === '{';
6
+ return ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r' || ch === '(' || ch === '[' || ch === '{';
8
7
  }
9
8
  function isLetter(ch) {
10
9
  return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
@@ -117,11 +116,11 @@ function applyPunctuation(text, enableQuotes, dashes, ellipsis, symbols, normali
117
116
  if (enableQuotes) {
118
117
  if (ch === '"') {
119
118
  const prev = i > 0 ? text[i - 1] : ' ';
120
- result += text.slice(last, i) + ((isWhitespaceOrOpener(prev) || i === 0) ? openDouble : closeDouble);
119
+ result += text.slice(last, i) + (isWhitespaceOrOpener(prev) || i === 0 ? openDouble : closeDouble);
121
120
  last = i + 1;
122
121
  continue;
123
122
  }
124
- if (ch === '\'') {
123
+ if (ch === "'") {
125
124
  const prev = i > 0 ? text[i - 1] : ' ';
126
125
  const next = i + 1 < len ? text[i + 1] : '';
127
126
  result += text.slice(last, i);
@@ -130,7 +129,7 @@ function applyPunctuation(text, enableQuotes, dashes, ellipsis, symbols, normali
130
129
  result += closeSingle;
131
130
  }
132
131
  else {
133
- result += (isWhitespaceOrOpener(prev) || i === 0) ? openSingle : closeSingle;
132
+ result += isWhitespaceOrOpener(prev) || i === 0 ? openSingle : closeSingle;
134
133
  }
135
134
  last = i + 1;
136
135
  continue;
@@ -181,7 +180,7 @@ function applyPunctuation(text, enableQuotes, dashes, ellipsis, symbols, normali
181
180
  * ```
182
181
  */
183
182
  export default defineComarkPlugin((options = {}) => {
184
- const { quotes = true, dashes = true, ellipsis = true, symbols = true, normalize = true, } = options;
183
+ const { quotes = true, dashes = true, ellipsis = true, symbols = true, normalize = true } = options;
185
184
  // Resolve quote characters
186
185
  let enableQuotes;
187
186
  let openDouble;
@@ -6,5 +6,5 @@ interface SecurityOptions extends PropsValidationOptions {
6
6
  */
7
7
  blockedTags?: string[];
8
8
  }
9
- declare const _default: import("comark").ComarkPluginFactory<SecurityOptions>;
9
+ declare const _default: import("comark").ComarkPluginFactory<SecurityOptions, {}, {}>;
10
10
  export default _default;
@@ -3,7 +3,7 @@ import { visit } from "../utils/index.js";
3
3
  import { validateProps } from "../internal/props-validation.js";
4
4
  export default defineComarkPlugin((options = {}) => {
5
5
  const { blockedTags = [], allowedLinkPrefixes, allowedImagePrefixes, allowedProtocols, defaultOrigin, allowDataImages, } = options;
6
- const dropSet = new Set(blockedTags.map(t => t.toLowerCase()));
6
+ const dropSet = new Set(blockedTags.map((t) => t.toLowerCase()));
7
7
  const propsOptions = {
8
8
  allowedLinkPrefixes,
9
9
  allowedImagePrefixes,
@@ -14,7 +14,7 @@ export default defineComarkPlugin((options = {}) => {
14
14
  return {
15
15
  name: 'security',
16
16
  post(state) {
17
- visit(state.tree, node => typeof node !== 'string' && node[0] !== null, (node) => {
17
+ visit(state.tree, (node) => typeof node !== 'string' && node[0] !== null, (node) => {
18
18
  const element = node;
19
19
  // return false to remove the node from the tree
20
20
  if (dropSet.has(element[0].toLowerCase())) {
@@ -1,4 +1,7 @@
1
+ import type { ComarkNode } from 'comark';
1
2
  declare const _default: import("comark").ComarkPluginFactory<{
2
3
  delimiter?: string;
3
- }>;
4
+ }, {
5
+ summary: ComarkNode[];
6
+ }, {}>;
4
7
  export default _default;
@@ -0,0 +1,49 @@
1
+ import type { MarkdownItPluginWithOptions } from '../types.ts';
2
+ export interface SyntaxOptions {
3
+ /**
4
+ * Enable block component syntax.
5
+ *
6
+ * @see https://comark.dev/syntax/components#block
7
+ * @default true
8
+ */
9
+ blockComponent?: boolean;
10
+ /**
11
+ * Enable inline props syntax.
12
+ *
13
+ * @see https://comark.dev/syntax/attributes
14
+ * @default true
15
+ */
16
+ inlineProps?: boolean;
17
+ /**
18
+ * Enable inline span syntax.
19
+ *
20
+ * @see https://comark.dev/syntax/attributes#span-attributes
21
+ * @default true
22
+ */
23
+ inlineSpan?: boolean;
24
+ /**
25
+ * Enable inline component syntax.
26
+ *
27
+ * @see https://comark.dev/syntax/components#inline
28
+ * @default true
29
+ */
30
+ inlineComponent?: boolean;
31
+ /**
32
+ * Enable inline binding syntax (`{{ value }}` and `{{ value || default }}`).
33
+ *
34
+ * Off by default — opt in here, or use the standalone `plugins/binding.ts` plugin.
35
+ *
36
+ * @see https://comark.dev/syntax/components#data-binding
37
+ * @default false
38
+ */
39
+ inlineBinding?: boolean;
40
+ /**
41
+ * The tag name used to render an inline binding.
42
+ *
43
+ * @default 'binding'
44
+ */
45
+ bindingTag?: string;
46
+ }
47
+ declare const _default: import("../types.ts").ComarkPluginFactory<SyntaxOptions, {}, {}>;
48
+ export default _default;
49
+ export declare const markdownItComark: MarkdownItPluginWithOptions<SyntaxOptions>;