@milkdown/preset-commonmark 6.5.3 → 7.0.0-next.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 (153) hide show
  1. package/lib/composed/commands.d.ts +3 -0
  2. package/lib/composed/commands.d.ts.map +1 -0
  3. package/lib/composed/index.d.ts +6 -0
  4. package/lib/composed/index.d.ts.map +1 -0
  5. package/lib/composed/inputrules.d.ts +3 -0
  6. package/lib/composed/inputrules.d.ts.map +1 -0
  7. package/lib/composed/keymap.d.ts +3 -0
  8. package/lib/composed/keymap.d.ts.map +1 -0
  9. package/lib/composed/plugins.d.ts +2 -0
  10. package/lib/composed/plugins.d.ts.map +1 -0
  11. package/lib/composed/schema.d.ts +3 -0
  12. package/lib/composed/schema.d.ts.map +1 -0
  13. package/lib/index.d.ts +4 -29
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.es.js +1101 -1386
  16. package/lib/index.es.js.map +1 -1
  17. package/lib/mark/emphasis.d.ts +5 -0
  18. package/lib/mark/emphasis.d.ts.map +1 -0
  19. package/lib/mark/index.d.ts +3 -4
  20. package/lib/mark/index.d.ts.map +1 -1
  21. package/lib/mark/inline-code.d.ts +5 -0
  22. package/lib/mark/inline-code.d.ts.map +1 -0
  23. package/lib/mark/link.d.ts +8 -10
  24. package/lib/mark/link.d.ts.map +1 -1
  25. package/lib/mark/strong.d.ts +4 -2
  26. package/lib/mark/strong.d.ts.map +1 -1
  27. package/lib/node/blockquote.d.ts +6 -2
  28. package/lib/node/blockquote.d.ts.map +1 -1
  29. package/lib/node/bullet-list.d.ts +5 -2
  30. package/lib/node/bullet-list.d.ts.map +1 -1
  31. package/lib/node/code-block.d.ts +10 -0
  32. package/lib/node/code-block.d.ts.map +1 -0
  33. package/lib/node/doc.d.ts +1 -1
  34. package/lib/node/doc.d.ts.map +1 -1
  35. package/lib/node/hardbreak.d.ts +4 -6
  36. package/lib/node/hardbreak.d.ts.map +1 -1
  37. package/lib/node/heading.d.ts +7 -12
  38. package/lib/node/heading.d.ts.map +1 -1
  39. package/lib/node/hr.d.ts +4 -2
  40. package/lib/node/hr.d.ts.map +1 -1
  41. package/lib/node/image.d.ts +10 -11
  42. package/lib/node/image.d.ts.map +1 -1
  43. package/lib/node/index.d.ts +6 -8
  44. package/lib/node/index.d.ts.map +1 -1
  45. package/lib/node/list-item.d.ts +6 -7
  46. package/lib/node/list-item.d.ts.map +1 -1
  47. package/lib/node/ordered-list.d.ts +5 -2
  48. package/lib/node/ordered-list.d.ts.map +1 -1
  49. package/lib/node/paragraph.d.ts +4 -2
  50. package/lib/node/paragraph.d.ts.map +1 -1
  51. package/lib/node/text.d.ts +1 -1
  52. package/lib/node/text.d.ts.map +1 -1
  53. package/lib/plugin/hardbreak-clear-mark-plugin.d.ts +2 -0
  54. package/lib/plugin/hardbreak-clear-mark-plugin.d.ts.map +1 -0
  55. package/lib/plugin/hardbreak-filter-plugin.d.ts +3 -0
  56. package/lib/plugin/hardbreak-filter-plugin.d.ts.map +1 -0
  57. package/lib/plugin/index.d.ts +9 -3
  58. package/lib/plugin/index.d.ts.map +1 -1
  59. package/lib/plugin/{inline-nodes-cursor.d.ts → inline-nodes-cursor-plugin.d.ts} +2 -3
  60. package/lib/plugin/inline-nodes-cursor-plugin.d.ts.map +1 -0
  61. package/lib/plugin/{inline-sync → inline-sync-plugin}/config.d.ts +2 -2
  62. package/lib/plugin/inline-sync-plugin/config.d.ts.map +1 -0
  63. package/lib/plugin/{inline-sync → inline-sync-plugin}/context.d.ts +1 -2
  64. package/lib/plugin/inline-sync-plugin/context.d.ts.map +1 -0
  65. package/lib/plugin/inline-sync-plugin/index.d.ts +3 -0
  66. package/lib/plugin/inline-sync-plugin/index.d.ts.map +1 -0
  67. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts +2 -0
  68. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +1 -0
  69. package/lib/plugin/{inline-sync → inline-sync-plugin}/regexp.d.ts +0 -0
  70. package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +1 -0
  71. package/lib/plugin/{inline-sync → inline-sync-plugin}/replacer.d.ts +1 -1
  72. package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +1 -0
  73. package/lib/plugin/{inline-sync → inline-sync-plugin}/utils.d.ts +0 -0
  74. package/lib/plugin/inline-sync-plugin/utils.d.ts.map +1 -0
  75. package/lib/plugin/remark-add-order-in-list-plugin.d.ts +2 -0
  76. package/lib/plugin/remark-add-order-in-list-plugin.d.ts.map +1 -0
  77. package/lib/plugin/remark-inline-link-plugin.d.ts +2 -0
  78. package/lib/plugin/remark-inline-link-plugin.d.ts.map +1 -0
  79. package/lib/plugin/remark-line-break.d.ts +2 -0
  80. package/lib/plugin/remark-line-break.d.ts.map +1 -0
  81. package/lib/plugin/sync-heading-id-plugin.d.ts +2 -0
  82. package/lib/plugin/sync-heading-id-plugin.d.ts.map +1 -0
  83. package/lib/plugin/sync-list-order-plugin.d.ts +2 -0
  84. package/lib/plugin/sync-list-order-plugin.d.ts.map +1 -0
  85. package/package.json +14 -7
  86. package/src/composed/commands.ts +30 -0
  87. package/src/composed/index.ts +6 -0
  88. package/src/composed/inputrules.ts +12 -0
  89. package/src/composed/keymap.ts +19 -0
  90. package/src/composed/plugins.ts +21 -0
  91. package/src/composed/schema.ts +54 -0
  92. package/src/index.ts +5 -52
  93. package/src/mark/emphasis.ts +42 -0
  94. package/src/mark/index.ts +3 -10
  95. package/src/mark/inline-code.ts +64 -0
  96. package/src/mark/link.ts +87 -247
  97. package/src/mark/strong.ts +35 -36
  98. package/src/node/blockquote.ts +32 -33
  99. package/src/node/bullet-list.ts +56 -56
  100. package/src/node/code-block.ts +93 -0
  101. package/src/node/doc.ts +17 -22
  102. package/src/node/hardbreak.ts +60 -117
  103. package/src/node/heading.ts +158 -281
  104. package/src/node/hr.ts +51 -57
  105. package/src/node/image.ts +102 -209
  106. package/src/node/index.ts +6 -35
  107. package/src/node/list-item.ts +81 -142
  108. package/src/node/ordered-list.ts +64 -65
  109. package/src/node/paragraph.ts +48 -50
  110. package/src/node/text.ts +13 -16
  111. package/src/plugin/hardbreak-clear-mark-plugin.ts +44 -0
  112. package/src/plugin/hardbreak-filter-plugin.ts +31 -0
  113. package/src/plugin/index.ts +12 -14
  114. package/src/plugin/{inline-nodes-cursor.ts → inline-nodes-cursor-plugin.ts} +4 -4
  115. package/src/plugin/{inline-sync → inline-sync-plugin}/config.ts +4 -3
  116. package/src/plugin/{inline-sync → inline-sync-plugin}/context.ts +4 -6
  117. package/src/plugin/inline-sync-plugin/index.ts +4 -0
  118. package/src/plugin/{inline-sync/index.ts → inline-sync-plugin/inline-sync-plugin.ts} +9 -11
  119. package/src/plugin/{inline-sync → inline-sync-plugin}/regexp.ts +0 -0
  120. package/src/plugin/{inline-sync → inline-sync-plugin}/replacer.ts +3 -3
  121. package/src/plugin/{inline-sync → inline-sync-plugin}/utils.ts +0 -0
  122. package/src/plugin/remark-add-order-in-list-plugin.ts +15 -0
  123. package/src/plugin/remark-inline-link-plugin.ts +5 -0
  124. package/src/plugin/remark-line-break.ts +41 -0
  125. package/src/plugin/sync-heading-id-plugin.ts +53 -0
  126. package/src/plugin/sync-list-order-plugin.ts +57 -0
  127. package/lib/mark/code-inline.d.ts +0 -3
  128. package/lib/mark/code-inline.d.ts.map +0 -1
  129. package/lib/mark/em.d.ts +0 -3
  130. package/lib/mark/em.d.ts.map +0 -1
  131. package/lib/node/code-fence.d.ts +0 -7
  132. package/lib/node/code-fence.d.ts.map +0 -1
  133. package/lib/plugin/add-order-in-list.d.ts +0 -3
  134. package/lib/plugin/add-order-in-list.d.ts.map +0 -1
  135. package/lib/plugin/filter-html.d.ts +0 -3
  136. package/lib/plugin/filter-html.d.ts.map +0 -1
  137. package/lib/plugin/inline-nodes-cursor.d.ts.map +0 -1
  138. package/lib/plugin/inline-sync/config.d.ts.map +0 -1
  139. package/lib/plugin/inline-sync/context.d.ts.map +0 -1
  140. package/lib/plugin/inline-sync/index.d.ts +0 -6
  141. package/lib/plugin/inline-sync/index.d.ts.map +0 -1
  142. package/lib/plugin/inline-sync/regexp.d.ts.map +0 -1
  143. package/lib/plugin/inline-sync/replacer.d.ts.map +0 -1
  144. package/lib/plugin/inline-sync/utils.d.ts.map +0 -1
  145. package/lib/supported-keys.d.ts +0 -23
  146. package/lib/supported-keys.d.ts.map +0 -1
  147. package/src/mark/code-inline.ts +0 -66
  148. package/src/mark/em.ts +0 -42
  149. package/src/node/code-fence.ts +0 -245
  150. package/src/plugin/add-order-in-list.ts +0 -19
  151. package/src/plugin/filter-html.ts +0 -43
  152. package/src/supported-keys.ts +0 -25
  153. package/src/types.d.ts +0 -5
@@ -0,0 +1,53 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { Plugin, PluginKey } from '@milkdown/prose/state'
3
+ import type { EditorView } from '@milkdown/prose/view'
4
+ import { $prose } from '@milkdown/utils'
5
+ import { headingIdGenerator, headingSchema } from '../node/heading'
6
+
7
+ export const syncHeadingIdPlugin = $prose((ctx) => {
8
+ const headingIdPluginKey = new PluginKey('MILKDOWN_HEADING_ID')
9
+
10
+ const updateId = (view: EditorView) => {
11
+ if (view.composing || !view.editable)
12
+ return
13
+
14
+ const getId = ctx.get(headingIdGenerator.key)
15
+ const tr = view.state.tr.setMeta('addToHistory', false)
16
+
17
+ let found = false
18
+
19
+ view.state.doc.descendants((node, pos) => {
20
+ if (node.type === headingSchema.type()) {
21
+ if (node.textContent.trim().length === 0)
22
+ return
23
+
24
+ const attrs = node.attrs
25
+ const id = getId(node)
26
+
27
+ if (attrs.id !== id) {
28
+ found = true
29
+ tr.setMeta(headingIdPluginKey, true).setNodeMarkup(pos, undefined, {
30
+ ...attrs,
31
+ id,
32
+ })
33
+ }
34
+ }
35
+ })
36
+
37
+ if (found)
38
+ view.dispatch(tr)
39
+ }
40
+
41
+ return new Plugin({
42
+ key: headingIdPluginKey,
43
+ view: (view) => {
44
+ updateId(view)
45
+
46
+ return {
47
+ update: (view) => {
48
+ updateId(view)
49
+ },
50
+ }
51
+ },
52
+ })
53
+ })
@@ -0,0 +1,57 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { EditorState, Transaction } from '@milkdown/prose/state'
3
+ import { Plugin, PluginKey } from '@milkdown/prose/state'
4
+ import { $prose } from '@milkdown/utils'
5
+ import { listItemSchema } from '../node/list-item'
6
+
7
+ import { orderedListSchema } from '../node/ordered-list'
8
+
9
+ // This plugin is used to keep the label of list item up to date in ordered list.
10
+ export const syncListOrderPlugin = $prose(() => {
11
+ const walkThrough = (state: EditorState, callback: (tr: Transaction) => void) => {
12
+ const orderedListType = orderedListSchema.type()
13
+ const listItemType = listItemSchema.type()
14
+ let tr = state.tr
15
+ state.doc.descendants((node, pos, parent, index) => {
16
+ if (node.type === listItemType && parent?.type === orderedListType) {
17
+ let changed = false
18
+ const attrs = { ...node.attrs }
19
+ if (node.attrs.listType !== 'ordered') {
20
+ attrs.listType = 'ordered'
21
+ changed = true
22
+ }
23
+
24
+ const base = parent?.maybeChild(0)
25
+ if (base === node) {
26
+ attrs.label = '1.'
27
+ changed = true
28
+ }
29
+ else if (base?.type === listItemType && base.attrs.listType === 'ordered') {
30
+ attrs.label = `${index + 1}.`
31
+ changed = true
32
+ }
33
+ else if (node.attrs.label === '•') {
34
+ attrs.label = `${index + 1}.`
35
+ changed = true
36
+ }
37
+
38
+ if (changed)
39
+ tr = tr.setNodeMarkup(pos, undefined, attrs)
40
+ }
41
+ })
42
+ callback(tr)
43
+ }
44
+ return new Plugin({
45
+ key: new PluginKey('MILKDOWN_KEEP_LIST_ORDER'),
46
+ appendTransaction: (transactions, _oldState, nextState) => {
47
+ let tr: Transaction | null = null
48
+ if (transactions.some(transaction => transaction.docChanged)) {
49
+ walkThrough(nextState, (t) => {
50
+ tr = t
51
+ })
52
+ }
53
+
54
+ return tr
55
+ },
56
+ })
57
+ })
@@ -1,3 +0,0 @@
1
- export declare const ToggleInlineCode: import("@milkdown/core").CmdKey<undefined>;
2
- export declare const codeInline: import("@milkdown/utils").MarkCreator<string, {}>;
3
- //# sourceMappingURL=code-inline.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-inline.d.ts","sourceRoot":"","sources":["../../src/mark/code-inline.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB,4CAAmC,CAAA;AAEhE,eAAO,MAAM,UAAU,mDAqDrB,CAAA"}
package/lib/mark/em.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare const ToggleItalic: import("@milkdown/core").CmdKey<undefined>;
2
- export declare const em: import("@milkdown/utils").MarkCreator<string, {}>;
3
- //# sourceMappingURL=em.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"em.d.ts","sourceRoot":"","sources":["../../src/mark/em.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,YAAY,4CAA+B,CAAA;AACxD,eAAO,MAAM,EAAE,mDA6BZ,CAAA"}
@@ -1,7 +0,0 @@
1
- export declare const backtickInputRegex: RegExp;
2
- export declare const tildeInputRegex: RegExp;
3
- export declare const TurnIntoCodeFence: import("@milkdown/core").CmdKey<undefined>;
4
- export declare const codeFence: import("@milkdown/utils").NodeCreator<"CodeFence", {
5
- languageList?: string[] | undefined;
6
- }>;
7
- //# sourceMappingURL=code-fence.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"code-fence.d.ts","sourceRoot":"","sources":["../../src/node/code-fence.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,kBAAkB,QAAoC,CAAA;AACnE,eAAO,MAAM,eAAe,QAAoC,CAAA;AAEhE,eAAO,MAAM,iBAAiB,4CAAoC,CAAA;AAGlE,eAAO,MAAM,SAAS;;EA6MpB,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { Node } from 'unist';
2
- export declare const addOrderInList: () => (ast: Node) => void;
3
- //# sourceMappingURL=add-order-in-list.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"add-order-in-list.d.ts","sourceRoot":"","sources":["../../src/plugin/add-order-in-list.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAIjC,eAAO,MAAM,cAAc,cACC,IAAI,SAY/B,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { Node } from 'unist';
2
- export declare const filterHTMLPlugin: () => (tree: Node) => void;
3
- //# sourceMappingURL=filter-html.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filter-html.d.ts","sourceRoot":"","sources":["../../src/plugin/filter-html.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,IAAI,EAAU,MAAM,OAAO,CAAA;AA+BlD,eAAO,MAAM,gBAAgB,eACA,IAAI,SAShC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"inline-nodes-cursor.d.ts","sourceRoot":"","sources":["../../src/plugin/inline-nodes-cursor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAa,MAAM,uBAAuB,CAAA;AAKzD;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAO,MAkF7C,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAIxD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE;IACrC,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,GAAG,EAAE,GAAG,CAAA;IACR,EAAE,EAAE,WAAW,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACb,KAAK,OAAO,CAAA;AAEb,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,EAAE,mBAAmB,CAAA;IACtC,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,EAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,CAAA;IACrC,eAAe,EAAE,CAAC,iBAAiB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACrE;AAED,eAAO,MAAM,aAAa,EAAE,gBAyB3B,CAAA;AAED,eAAO,MAAM,mBAAmB,sEAAuF,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAMxD,cAAc,UAAU,CAAA;AAExB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAmED,eAAO,MAAM,iBAAiB,QAAS,GAAG,SAAS,WAAW,KAAG,iBAAiB,GAAG,IAmCpF,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { Ctx } from '@milkdown/core';
2
- import { Plugin, PluginKey } from '@milkdown/prose/state';
3
- export * from './config';
4
- export declare const inlineSyncPluginKey: PluginKey<any>;
5
- export declare const getInlineSyncPlugin: (ctx: Ctx) => Plugin<null>;
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAMzD,cAAc,UAAU,CAAA;AAExB,eAAO,MAAM,mBAAmB,gBAAwC,CAAA;AACxE,eAAO,MAAM,mBAAmB,QAAS,GAAG,iBAkD3C,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAAyE,CAAA;AAEhG,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WACK,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOhF,eAAO,MAAM,WAAW,QACjB,GAAG,OACH,SAAS,SACP,WAAW,iBACH,WAAW,KAAK,IAAI,SAC5B,KAAK,SA6Bb,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAGnD,eAAO,MAAM,QAAQ,QAAS,MAAM,WAUnC,CAAA;AAED,eAAO,MAAM,IAAI,SAAU,MAAM,SAAS,MAAM,QAAQ,MAAM,WAQ7D,CAAA;AAED,eAAO,MAAM,kBAAkB,oBAAqB,MAAM,YAAY,MAAM,WACtB,CAAA;AAEtD,eAAO,MAAM,oBAAoB,gBAAiB,mBAAmB,YAAY,MAAM,WAkBtF,CAAA;AAED,eAAO,MAAM,UAAU,SAAU,IAAI,QAAQ,MAAM,eAAe,MAAM,WAkBvE,CAAA"}
@@ -1,23 +0,0 @@
1
- export declare const SupportedKeys: {
2
- readonly HardBreak: "HardBreak";
3
- readonly Blockquote: "Blockquote";
4
- readonly BulletList: "BulletList";
5
- readonly OrderedList: "OrderedList";
6
- readonly CodeFence: "CodeFence";
7
- readonly H1: "H1";
8
- readonly H2: "H2";
9
- readonly H3: "H3";
10
- readonly H4: "H4";
11
- readonly H5: "H5";
12
- readonly H6: "H6";
13
- readonly DowngradeHeading: "DowngradeHeading";
14
- readonly Text: "Text";
15
- readonly CodeInline: "CodeInline";
16
- readonly Em: "Em";
17
- readonly Bold: "Bold";
18
- readonly NextListItem: "NextListItem";
19
- readonly SinkListItem: "SinkListItem";
20
- readonly LiftListItem: "LiftListItem";
21
- };
22
- export type SupportedKeys = typeof SupportedKeys;
23
- //# sourceMappingURL=supported-keys.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"supported-keys.d.ts","sourceRoot":"","sources":["../src/supported-keys.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;CAoBhB,CAAA;AAGV,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA"}
@@ -1,66 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import { createCmd, createCmdKey } from '@milkdown/core'
3
- import type { MarkType } from '@milkdown/prose/model'
4
- import { createMark, createShortcut } from '@milkdown/utils'
5
-
6
- import { SupportedKeys } from '../supported-keys'
7
-
8
- type Keys = SupportedKeys['CodeInline']
9
- const id = 'code_inline'
10
-
11
- export const ToggleInlineCode = createCmdKey('ToggleInlineCode')
12
-
13
- export const codeInline = createMark<Keys>((utils) => {
14
- return {
15
- id,
16
- schema: () => ({
17
- priority: 100,
18
- code: true,
19
- inclusive: false,
20
- parseDOM: [{ tag: 'code' }],
21
- toDOM: mark => ['code', { class: utils.getClassName(mark.attrs, 'code-inline') }],
22
- parseMarkdown: {
23
- match: node => node.type === 'inlineCode',
24
- runner: (state, node, markType) => {
25
- state.openMark(markType)
26
- state.addText(node.value as string)
27
- state.closeMark(markType)
28
- },
29
- },
30
- toMarkdown: {
31
- match: mark => mark.type.name === id,
32
- runner: (state, mark, node) => {
33
- state.withMark(mark, 'inlineCode', node.text || '')
34
- },
35
- },
36
- }),
37
- commands: markType => [
38
- createCmd(ToggleInlineCode, () => (state, dispatch) => {
39
- const { selection, tr } = state
40
- if (selection.empty)
41
- return false
42
- const { from, to } = selection
43
-
44
- const has = state.doc.rangeHasMark(from, to, markType)
45
- if (has) {
46
- dispatch?.(tr.removeMark(from, to, markType))
47
- return true
48
- }
49
-
50
- const restMarksName = Object.keys(state.schema.marks).filter(x => x !== markType.name)
51
-
52
- restMarksName
53
- .map(name => state.schema.marks[name] as MarkType)
54
- .forEach((t) => {
55
- tr.removeMark(from, to, t)
56
- })
57
-
58
- dispatch?.(tr.addMark(from, to, markType.create()))
59
- return true
60
- }),
61
- ],
62
- shortcuts: {
63
- [SupportedKeys.CodeInline]: createShortcut(ToggleInlineCode, 'Mod-e'),
64
- },
65
- }
66
- })
package/src/mark/em.ts DELETED
@@ -1,42 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import { createCmd, createCmdKey } from '@milkdown/core'
3
- import { toggleMark } from '@milkdown/prose/commands'
4
- import { createMark, createShortcut } from '@milkdown/utils'
5
-
6
- import { SupportedKeys } from '../supported-keys'
7
-
8
- type Keys = SupportedKeys['Em']
9
-
10
- const id = 'em'
11
-
12
- export const ToggleItalic = createCmdKey('ToggleItalic')
13
- export const em = createMark<Keys>(utils => ({
14
- id,
15
- schema: () => ({
16
- inclusive: false,
17
- parseDOM: [
18
- { tag: 'i' },
19
- { tag: 'em' },
20
- { style: 'font-style', getAttrs: value => (value === 'italic') as false },
21
- ],
22
- toDOM: mark => ['em', { class: utils.getClassName(mark.attrs, id) }],
23
- parseMarkdown: {
24
- match: node => node.type === 'emphasis',
25
- runner: (state, node, markType) => {
26
- state.openMark(markType)
27
- state.next(node.children)
28
- state.closeMark(markType)
29
- },
30
- },
31
- toMarkdown: {
32
- match: mark => mark.type.name === id,
33
- runner: (state, mark) => {
34
- state.withMark(mark, 'emphasis')
35
- },
36
- },
37
- }),
38
- commands: markType => [createCmd(ToggleItalic, () => toggleMark(markType))],
39
- shortcuts: {
40
- [SupportedKeys.Em]: createShortcut(ToggleItalic, 'Mod-i'),
41
- },
42
- }))
@@ -1,245 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { ThemeCodeFenceType } from '@milkdown/core'
3
- import { createCmd, createCmdKey, editorViewCtx } from '@milkdown/core'
4
- import { expectDomTypeError } from '@milkdown/exception'
5
- import { setBlockType } from '@milkdown/prose/commands'
6
- import { textblockTypeInputRule } from '@milkdown/prose/inputrules'
7
- import { Fragment } from '@milkdown/prose/model'
8
- import type { NodeView } from '@milkdown/prose/view'
9
- import { createNode, createShortcut } from '@milkdown/utils'
10
-
11
- import { SupportedKeys } from '../supported-keys'
12
-
13
- type Keys = SupportedKeys['CodeFence']
14
-
15
- const languageOptions = [
16
- '',
17
- 'javascript',
18
- 'typescript',
19
- 'bash',
20
- 'sql',
21
- 'json',
22
- 'html',
23
- 'css',
24
- 'c',
25
- 'cpp',
26
- 'java',
27
- 'ruby',
28
- 'python',
29
- 'go',
30
- 'rust',
31
- 'markdown',
32
- ]
33
-
34
- export const backtickInputRegex = /^```(?<language>[a-z]*)?[\s\n]$/
35
- export const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/
36
-
37
- export const TurnIntoCodeFence = createCmdKey('TurnIntoCodeFence')
38
-
39
- const id = 'fence'
40
- export const codeFence = createNode<Keys, { languageList?: string[] }>((utils, options) => {
41
- const languageList = options?.languageList || languageOptions
42
-
43
- return {
44
- id,
45
- schema: ctx => ({
46
- content: 'text*',
47
- group: 'block',
48
- marks: '',
49
- defining: true,
50
- code: true,
51
- attrs: {
52
- language: {
53
- default: '',
54
- },
55
- fold: {
56
- default: true,
57
- },
58
- },
59
- parseDOM: [
60
- {
61
- tag: 'div.code-fence-container',
62
- preserveWhitespace: 'full',
63
- getAttrs: (dom) => {
64
- if (!(dom instanceof HTMLElement))
65
- throw expectDomTypeError(dom)
66
-
67
- return { language: dom.querySelector('pre')?.dataset.language }
68
- },
69
- getContent: (dom, schema) => {
70
- if (!(dom instanceof HTMLElement))
71
- throw expectDomTypeError(dom)
72
-
73
- const text = dom.querySelector('pre')?.textContent ?? ''
74
- if (!text)
75
- return Fragment.empty
76
-
77
- const textNode = schema.text(text)
78
- return Fragment.from(textNode)
79
- },
80
- },
81
- {
82
- tag: 'pre',
83
- preserveWhitespace: 'full',
84
- getAttrs: (dom) => {
85
- if (!(dom instanceof HTMLElement))
86
- throw expectDomTypeError(dom)
87
-
88
- return { language: dom.dataset.language }
89
- },
90
- },
91
- ],
92
- toDOM: (node) => {
93
- const select = document.createElement('select')
94
- languageList.forEach((lang) => {
95
- const option = document.createElement('option')
96
- option.value = lang
97
- option.innerText = !lang ? '--' : lang
98
- if (lang === node.attrs.language)
99
- option.selected = true
100
-
101
- select.appendChild(option)
102
- })
103
- select.onchange = (e) => {
104
- const target = e.target
105
- if (!(target instanceof HTMLSelectElement))
106
- return
107
-
108
- const view = ctx.get(editorViewCtx)
109
- if (!view.editable) {
110
- target.value = node.attrs.language
111
- return
112
- }
113
-
114
- const { top, left } = target.getBoundingClientRect()
115
- const result = view.posAtCoords({ top, left })
116
- if (!result)
117
- return
118
-
119
- const { tr } = view.state
120
-
121
- view.dispatch(
122
- tr.setNodeMarkup(result.inside, undefined, {
123
- ...node.attrs,
124
- language: target.value,
125
- }),
126
- )
127
- }
128
- return [
129
- 'div',
130
- {
131
- class: 'code-fence-container',
132
- },
133
- select,
134
- [
135
- 'pre',
136
- {
137
- 'data-language': node.attrs.language,
138
- 'class': utils.getClassName(node.attrs, 'code-fence'),
139
- },
140
- ['code', { spellCheck: 'false' }, 0],
141
- ],
142
- ]
143
- },
144
- parseMarkdown: {
145
- match: ({ type }) => type === 'code',
146
- runner: (state, node, type) => {
147
- const language = node.lang as string
148
- const value = node.value as string
149
- state.openNode(type, { language })
150
- if (value)
151
- state.addText(value)
152
-
153
- state.closeNode()
154
- },
155
- },
156
- toMarkdown: {
157
- match: node => node.type.name === id,
158
- runner: (state, node) => {
159
- state.addNode('code', undefined, node.content.firstChild?.text || '', {
160
- lang: node.attrs.language,
161
- })
162
- },
163
- },
164
- }),
165
- inputRules: nodeType => [
166
- textblockTypeInputRule(backtickInputRegex, nodeType, (match) => {
167
- const [ok, language] = match
168
- if (!ok)
169
- return
170
- return { language }
171
- }),
172
- textblockTypeInputRule(tildeInputRegex, nodeType, (match) => {
173
- const [ok, language] = match
174
- if (!ok)
175
- return
176
- return { language }
177
- }),
178
- ],
179
- commands: nodeType => [createCmd(TurnIntoCodeFence, () => setBlockType(nodeType))],
180
- shortcuts: {
181
- [SupportedKeys.CodeFence]: createShortcut(TurnIntoCodeFence, 'Mod-Alt-c'),
182
- },
183
- view: () => (node, view, getPos) => {
184
- let currNode = node
185
-
186
- const onSelectLanguage = (language: string) => {
187
- const { tr } = view.state
188
- view.dispatch(
189
- tr.setNodeMarkup(getPos(), undefined, {
190
- fold: true,
191
- language,
192
- }),
193
- )
194
- }
195
- const onBlur = () => {
196
- const { tr } = view.state
197
-
198
- view.dispatch(
199
- tr.setNodeMarkup(getPos(), undefined, {
200
- ...currNode.attrs,
201
- fold: true,
202
- }),
203
- )
204
- }
205
- const onFocus = () => {
206
- const { tr } = view.state
207
-
208
- view.dispatch(
209
- tr.setNodeMarkup(getPos(), undefined, {
210
- ...currNode.attrs,
211
- fold: false,
212
- }),
213
- )
214
- }
215
-
216
- const renderer = utils.themeManager.get<ThemeCodeFenceType>('code-fence', {
217
- view,
218
- onBlur,
219
- onFocus,
220
- onSelectLanguage,
221
- editable: () => view.editable,
222
- languageList,
223
- })
224
- if (!renderer)
225
- return {} as NodeView
226
-
227
- const { dom, contentDOM, onUpdate, onDestroy } = renderer
228
- onUpdate(currNode)
229
-
230
- return {
231
- dom,
232
- contentDOM,
233
- update: (updatedNode) => {
234
- if (updatedNode.type.name !== id)
235
- return false
236
- currNode = updatedNode
237
- onUpdate(currNode)
238
-
239
- return true
240
- },
241
- destroy: onDestroy,
242
- }
243
- },
244
- }
245
- })
@@ -1,19 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { Node } from 'unist'
3
- import type { Parent } from 'unist-util-visit'
4
- import { visit } from 'unist-util-visit'
5
-
6
- export const addOrderInList = () => {
7
- function transformer(ast: Node) {
8
- visit(ast, 'list', (node: Parent & { ordered?: boolean; start?: number }) => {
9
- if (node.ordered) {
10
- const start = node.start ?? 1
11
- node.children.forEach((child, index) => {
12
- (child as Node & { label: number }).label = index + start
13
- })
14
- }
15
- })
16
- }
17
-
18
- return transformer
19
- }
@@ -1,43 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { Literal, Node, Parent } from 'unist'
3
-
4
- const isParent = (node: Node): node is Parent => !!(node as Parent).children
5
- const isHTML = (node: Node): node is Literal<string> => node.type === 'html'
6
-
7
- function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {
8
- return transform(ast, 0, null)[0]
9
-
10
- function transform(node: Node, index: number, parent: Node | null) {
11
- if (isParent(node)) {
12
- const out = []
13
- for (let i = 0, n = node.children.length; i < n; i++) {
14
- const nthChild = node.children[i]
15
- if (nthChild) {
16
- const xs = transform(nthChild, i, node)
17
- if (xs) {
18
- for (let j = 0, m = xs.length; j < m; j++) {
19
- const item = xs[j]
20
- if (item)
21
- out.push(item)
22
- }
23
- }
24
- }
25
- }
26
- node.children = out
27
- }
28
-
29
- return fn(node, index, parent)
30
- }
31
- }
32
-
33
- export const filterHTMLPlugin = () => {
34
- function transformer(tree: Node) {
35
- flatMapWithDepth(tree, (node) => {
36
- if (!isHTML(node))
37
- return [node]
38
-
39
- return []
40
- })
41
- }
42
- return transformer
43
- }
@@ -1,25 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- export const SupportedKeys = {
3
- HardBreak: 'HardBreak',
4
- Blockquote: 'Blockquote',
5
- BulletList: 'BulletList',
6
- OrderedList: 'OrderedList',
7
- CodeFence: 'CodeFence',
8
- H1: 'H1',
9
- H2: 'H2',
10
- H3: 'H3',
11
- H4: 'H4',
12
- H5: 'H5',
13
- H6: 'H6',
14
- DowngradeHeading: 'DowngradeHeading',
15
- Text: 'Text',
16
- CodeInline: 'CodeInline',
17
- Em: 'Em',
18
- Bold: 'Bold',
19
- NextListItem: 'NextListItem',
20
- SinkListItem: 'SinkListItem',
21
- LiftListItem: 'LiftListItem',
22
- } as const
23
-
24
- // eslint-disable-next-line @typescript-eslint/no-redeclare
25
- export type SupportedKeys = typeof SupportedKeys
package/src/types.d.ts DELETED
@@ -1,5 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- declare module 'remark-inline-links' {
3
- let a: never;
4
- export = a;
5
- }