@milkdown/preset-commonmark 7.2.2 → 7.2.4

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 (45) hide show
  1. package/lib/composed/plugins.d.ts.map +1 -1
  2. package/lib/index.es.js +675 -648
  3. package/lib/index.es.js.map +1 -1
  4. package/lib/mark/emphasis.d.ts.map +1 -1
  5. package/lib/mark/link.d.ts.map +1 -1
  6. package/lib/mark/strong.d.ts.map +1 -1
  7. package/lib/node/blockquote.d.ts.map +1 -1
  8. package/lib/node/bullet-list.d.ts.map +1 -1
  9. package/lib/node/code-block.d.ts.map +1 -1
  10. package/lib/node/list-item.d.ts.map +1 -1
  11. package/lib/node/ordered-list.d.ts.map +1 -1
  12. package/lib/node/paragraph.d.ts.map +1 -1
  13. package/lib/plugin/index.d.ts +1 -0
  14. package/lib/plugin/index.d.ts.map +1 -1
  15. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +1 -1
  16. package/lib/plugin/inline-sync-plugin/regexp.d.ts +1 -0
  17. package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +1 -1
  18. package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +1 -1
  19. package/lib/plugin/remark-marker-plugin.d.ts +2 -0
  20. package/lib/plugin/remark-marker-plugin.d.ts.map +1 -0
  21. package/package.json +7 -7
  22. package/src/composed/plugins.ts +2 -1
  23. package/src/mark/emphasis.ts +14 -6
  24. package/src/mark/inline-code.ts +4 -4
  25. package/src/mark/link.ts +5 -5
  26. package/src/mark/strong.ts +14 -6
  27. package/src/node/blockquote.ts +2 -2
  28. package/src/node/bullet-list.ts +2 -2
  29. package/src/node/code-block.ts +2 -2
  30. package/src/node/hardbreak.ts +2 -2
  31. package/src/node/heading.ts +10 -10
  32. package/src/node/hr.ts +5 -5
  33. package/src/node/image.ts +6 -6
  34. package/src/node/list-item.ts +8 -7
  35. package/src/node/ordered-list.ts +3 -3
  36. package/src/node/paragraph.ts +1 -1
  37. package/src/plugin/hardbreak-clear-mark-plugin.ts +4 -4
  38. package/src/plugin/index.ts +1 -0
  39. package/src/plugin/inline-sync-plugin/inline-sync-plugin.ts +0 -2
  40. package/src/plugin/inline-sync-plugin/regexp.ts +3 -1
  41. package/src/plugin/inline-sync-plugin/replacer.ts +11 -0
  42. package/src/plugin/inline-sync-plugin/utils.ts +4 -4
  43. package/src/plugin/remark-marker-plugin.ts +20 -0
  44. package/src/plugin/sync-heading-id-plugin.ts +1 -1
  45. package/src/plugin/sync-list-order-plugin.ts +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["../../src/mark/emphasis.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,mDAsBxB,CAAA;AAaH,eAAO,MAAM,qBAAqB,6CAA4E,CAAA;AAS9G,eAAO,MAAM,cAAc,2EAQzB,CAAA"}
1
+ {"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["../../src/mark/emphasis.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,mDA4BxB,CAAA;AAaH,eAAO,MAAM,qBAAqB,6CAEhC,CAAA;AASF,eAAO,MAAM,cAAc,2EAQzB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,QAAQ,qCAAoB,CAAA;AAQzC,eAAO,MAAM,UAAU,+CAoCpB,CAAA;AAQH,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAGD,eAAO,MAAM,iBAAiB,8DAAmH,CAAA;AASjJ,eAAO,MAAM,iBAAiB,8DAyC5B,CAAA"}
1
+ {"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../src/mark/link.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,QAAQ,qCAAoB,CAAA;AAQzC,eAAO,MAAM,UAAU,+CAoCpB,CAAA;AAQH,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAGD,eAAO,MAAM,iBAAiB,8DAAuH,CAAA;AASrJ,eAAO,MAAM,iBAAiB,8DAyC5B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,UAAU,qCAAsB,CAAA;AAQ7C,eAAO,MAAM,YAAY,iDAsBtB,CAAA;AAaH,eAAO,MAAM,mBAAmB,6CAAwE,CAAA;AASxG,eAAO,MAAM,YAAY,qEAQvB,CAAA"}
1
+ {"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,UAAU,qCAAsB,CAAA;AAQ7C,eAAO,MAAM,YAAY,iDA4BtB,CAAA;AAaH,eAAO,MAAM,mBAAmB,6CAE9B,CAAA;AASF,eAAO,MAAM,YAAY,qEAQvB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["../../src/node/blockquote.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAKlD,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,YAAY,CAkBpD,CAAA;AAcH,eAAO,MAAM,yBAAyB,sCAA2E,CAAA;AAQjH,eAAO,MAAM,uBAAuB,6CAA4E,CAAA;AAShH,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
1
+ {"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["../../src/node/blockquote.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAKlD,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,YAAY,CAkBpD,CAAA;AAcH,eAAO,MAAM,yBAAyB,sCAA+E,CAAA;AAQrH,eAAO,MAAM,uBAAuB,6CAAgF,CAAA;AASpH,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"bullet-list.d.ts","sourceRoot":"","sources":["../../src/node/bullet-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,sDAiD3B,CAAA;AAaF,eAAO,MAAM,yBAAyB,sCAAiF,CAAA;AAQvH,eAAO,MAAM,uBAAuB,6CAA4E,CAAA;AAShH,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
1
+ {"version":3,"file":"bullet-list.d.ts","sourceRoot":"","sources":["../../src/node/bullet-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,sDAiD3B,CAAA;AAaF,eAAO,MAAM,yBAAyB,sCAAqF,CAAA;AAQ3H,eAAO,MAAM,uBAAuB,6CAAgF,CAAA;AASpH,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"code-block.d.ts","sourceRoot":"","sources":["../../src/node/code-block.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,aAAa,qCAGvB,CAAA;AAQH,eAAO,MAAM,eAAe,qDAwD1B,CAAA;AAcF,eAAO,MAAM,wBAAwB,sCAEjC,CAAA;AASJ,eAAO,MAAM,sBAAsB,6CAA2G,CAAA;AAQ9I,eAAO,MAAM,8BAA8B;SAAwE,MAAM;cAAY,MAAM;EAOzI,CAAA;AASF,eAAO,MAAM,eAAe,6EAQ1B,CAAA"}
1
+ {"version":3,"file":"code-block.d.ts","sourceRoot":"","sources":["../../src/node/code-block.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,aAAa,qCAGvB,CAAA;AAQH,eAAO,MAAM,eAAe,qDAwD1B,CAAA;AAcF,eAAO,MAAM,wBAAwB,sCAEjC,CAAA;AASJ,eAAO,MAAM,sBAAsB,6CAA+G,CAAA;AAQlJ,eAAO,MAAM,8BAA8B;SAAwE,MAAM;cAAY,MAAM;EAOzI,CAAA;AASF,eAAO,MAAM,eAAe,6EAQ1B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,oDA2DxB,CAAA;AAwBH,eAAO,MAAM,mBAAmB,6CAA4E,CAAA;AAmB5G,eAAO,MAAM,mBAAmB,6CAA6E,CAAA;AAoB7G,eAAO,MAAM,oBAAoB,6CAA8E,CAAA;AAqC/G,eAAO,MAAM,wBAAwB,6CAA+D,CAAA;AAWpG,eAAO,MAAM,cAAc,iIA6BzB,CAAA"}
1
+ {"version":3,"file":"list-item.d.ts","sourceRoot":"","sources":["../../src/node/list-item.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,oDA2DxB,CAAA;AAwBH,eAAO,MAAM,mBAAmB,6CAAgF,CAAA;AAmBhH,eAAO,MAAM,mBAAmB,6CAAiF,CAAA;AAoBjH,eAAO,MAAM,oBAAoB,6CAAkF,CAAA;AAqCnH,eAAO,MAAM,wBAAwB,6CAAqE,CAAA;AAW1G,eAAO,MAAM,cAAc,iIA6BzB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["../../src/node/ordered-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,qCAA2B,CAAA;AAQvD,eAAO,MAAM,iBAAiB,uDAiD3B,CAAA;AAaH,eAAO,MAAM,0BAA0B,sCAKrC,CAAA;AAQF,eAAO,MAAM,wBAAwB,6CAA8E,CAAA;AASnH,eAAO,MAAM,iBAAiB,iFAQ5B,CAAA"}
1
+ {"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["../../src/node/ordered-list.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,qCAA2B,CAAA;AAQvD,eAAO,MAAM,iBAAiB,uDAiD3B,CAAA;AAaH,eAAO,MAAM,0BAA0B,sCAKrC,CAAA;AAQF,eAAO,MAAM,wBAAwB,6CAAkF,CAAA;AASvH,eAAO,MAAM,iBAAiB,iFAQ5B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["../../src/node/paragraph.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,qCAAyB,CAAA;AAQnD,eAAO,MAAM,eAAe,oDA0BzB,CAAA;AAYH,eAAO,MAAM,mBAAmB,6CAA6E,CAAA;AAS7G,eAAO,MAAM,eAAe,0EAQ1B,CAAA"}
1
+ {"version":3,"file":"paragraph.d.ts","sourceRoot":"","sources":["../../src/node/paragraph.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,qCAAyB,CAAA;AAQnD,eAAO,MAAM,eAAe,oDA0BzB,CAAA;AAYH,eAAO,MAAM,mBAAmB,6CAAiF,CAAA;AASjH,eAAO,MAAM,eAAe,0EAQ1B,CAAA"}
@@ -3,6 +3,7 @@ export * from './remark-add-order-in-list-plugin';
3
3
  export * from './remark-line-break';
4
4
  export * from './remark-inline-link-plugin';
5
5
  export * from './remark-html-transformer';
6
+ export * from './remark-marker-plugin';
6
7
  export * from './inline-nodes-cursor-plugin';
7
8
  export * from './hardbreak-clear-mark-plugin';
8
9
  export * from './hardbreak-filter-plugin';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,cAAc,sBAAsB,CAAA;AAEpC,cAAc,mCAAmC,CAAA;AACjD,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AAEzC,cAAc,8BAA8B,CAAA;AAE5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AAEzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,cAAc,sBAAsB,CAAA;AAEpC,cAAc,mCAAmC,CAAA;AACjD,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AAEtC,cAAc,8BAA8B,CAAA;AAE5C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AAEzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"inline-sync-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/inline-sync-plugin.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,gBAAgB,kCAoD3B,CAAA"}
1
+ {"version":3,"file":"inline-sync-plugin.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/inline-sync-plugin.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,gBAAgB,kCAkD3B,CAAA"}
@@ -1,3 +1,4 @@
1
1
  export declare const linkRegexp: RegExp;
2
+ export declare const keepLinkRegexp: RegExp;
2
3
  export declare const punctuationRegexp: (holePlaceholder: string) => RegExp;
3
4
  //# sourceMappingURL=regexp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAAyE,CAAA;AAEhG,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WACK,CAAA"}
1
+ {"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/regexp.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,QAA4B,CAAA;AAEnD,eAAO,MAAM,cAAc,QAAyE,CAAA;AAEpG,eAAO,MAAM,iBAAiB,oBAAqB,MAAM,WACK,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,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
+ {"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAQhF,eAAO,MAAM,WAAW,QACjB,GAAG,OACH,SAAS,SACP,WAAW,iBACH,WAAW,KAAK,IAAI,SAC5B,KAAK,SAuCb,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const remarkMarker: import("@milkdown/utils").$Remark;
2
+ //# sourceMappingURL=remark-marker-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remark-marker-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/remark-marker-plugin.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,mCAOvB,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@milkdown/preset-commonmark",
3
3
  "type": "module",
4
- "version": "7.2.2",
4
+ "version": "7.2.4",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,15 +32,15 @@
32
32
  "remark-inline-links": "^6.0.0",
33
33
  "tslib": "^2.5.0",
34
34
  "unist-util-visit": "^4.0.0",
35
- "@milkdown/exception": "7.2.2",
36
- "@milkdown/utils": "7.2.2"
35
+ "@milkdown/exception": "7.2.4",
36
+ "@milkdown/utils": "7.2.4"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/unist": "^2.0.6",
40
- "@milkdown/core": "7.2.2",
41
- "@milkdown/ctx": "7.2.2",
42
- "@milkdown/prose": "7.2.2",
43
- "@milkdown/transformer": "7.2.2"
40
+ "@milkdown/core": "7.2.4",
41
+ "@milkdown/ctx": "7.2.4",
42
+ "@milkdown/prose": "7.2.4",
43
+ "@milkdown/transformer": "7.2.4"
44
44
  },
45
45
  "nx": {
46
46
  "targets": {
@@ -11,7 +11,7 @@ import {
11
11
  remarkAddOrderInListPlugin,
12
12
  remarkHtmlTransformer,
13
13
  remarkInlineLinkPlugin,
14
- remarkLineBreak,
14
+ remarkLineBreak, remarkMarker,
15
15
  syncHeadingIdPlugin,
16
16
  syncListOrderPlugin,
17
17
  } from '../plugin'
@@ -31,6 +31,7 @@ export const plugins: MilkdownPlugin[] = [
31
31
  remarkInlineLinkPlugin,
32
32
  remarkLineBreak,
33
33
  remarkHtmlTransformer,
34
+ remarkMarker,
34
35
 
35
36
  syncHeadingIdPlugin,
36
37
  syncListOrderPlugin,
@@ -1,7 +1,7 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { commandsCtx } from '@milkdown/core'
3
- import { toggleMark } from '@milkdown/prose/commands'
2
+ import { commandsCtx, remarkStringifyOptionsCtx } from '@milkdown/core'
4
3
  import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
4
+ import { toggleMark } from '@milkdown/prose/commands'
5
5
  import { withMeta } from '../__internal__'
6
6
 
7
7
  /// HTML attributes for the emphasis mark.
@@ -14,7 +14,11 @@ withMeta(emphasisAttr, {
14
14
 
15
15
  /// Emphasis mark schema.
16
16
  export const emphasisSchema = $markSchema('emphasis', ctx => ({
17
- inclusive: false,
17
+ attrs: {
18
+ marker: {
19
+ default: ctx.get(remarkStringifyOptionsCtx).emphasis || '*',
20
+ },
21
+ },
18
22
  parseDOM: [
19
23
  { tag: 'i' },
20
24
  { tag: 'em' },
@@ -24,7 +28,7 @@ export const emphasisSchema = $markSchema('emphasis', ctx => ({
24
28
  parseMarkdown: {
25
29
  match: node => node.type === 'emphasis',
26
30
  runner: (state, node, markType) => {
27
- state.openMark(markType)
31
+ state.openMark(markType, { marker: node.marker })
28
32
  state.next(node.children)
29
33
  state.closeMark(markType)
30
34
  },
@@ -32,7 +36,9 @@ export const emphasisSchema = $markSchema('emphasis', ctx => ({
32
36
  toMarkdown: {
33
37
  match: mark => mark.type.name === 'emphasis',
34
38
  runner: (state, mark) => {
35
- state.withMark(mark, 'emphasis')
39
+ state.withMark(mark, 'emphasis', undefined, {
40
+ marker: mark.attrs.marker,
41
+ })
36
42
  },
37
43
  },
38
44
  }))
@@ -48,7 +54,9 @@ withMeta(emphasisSchema.ctx, {
48
54
  })
49
55
 
50
56
  /// A command to toggle the emphasis mark.
51
- export const toggleEmphasisCommand = $command('ToggleEmphasis', () => () => toggleMark(emphasisSchema.type()))
57
+ export const toggleEmphasisCommand = $command('ToggleEmphasis', ctx => () => {
58
+ return toggleMark(emphasisSchema.type(ctx))
59
+ })
52
60
 
53
61
  withMeta(toggleEmphasisCommand, {
54
62
  displayName: 'Command<toggleEmphasisCommand>',
@@ -46,16 +46,16 @@ withMeta(inlineCodeSchema.ctx, {
46
46
  })
47
47
 
48
48
  /// A command to toggle the inlineCode mark.
49
- export const toggleInlineCodeCommand = $command('ToggleInlineCode', () => () => (state, dispatch) => {
49
+ export const toggleInlineCodeCommand = $command('ToggleInlineCode', ctx => () => (state, dispatch) => {
50
50
  const { selection, tr } = state
51
51
  if (selection.empty)
52
52
  return false
53
53
  const { from, to } = selection
54
54
 
55
- const has = state.doc.rangeHasMark(from, to, inlineCodeSchema.type())
55
+ const has = state.doc.rangeHasMark(from, to, inlineCodeSchema.type(ctx))
56
56
  // remove exists inlineCode mark if have
57
57
  if (has) {
58
- dispatch?.(tr.removeMark(from, to, inlineCodeSchema.type()))
58
+ dispatch?.(tr.removeMark(from, to, inlineCodeSchema.type(ctx)))
59
59
  return true
60
60
  }
61
61
 
@@ -69,7 +69,7 @@ export const toggleInlineCodeCommand = $command('ToggleInlineCode', () => () =>
69
69
  })
70
70
 
71
71
  // add inlineCode mark
72
- dispatch?.(tr.addMark(from, to, inlineCodeSchema.type().create()))
72
+ dispatch?.(tr.addMark(from, to, inlineCodeSchema.type(ctx).create()))
73
73
  return true
74
74
  })
75
75
 
package/src/mark/link.ts CHANGED
@@ -65,7 +65,7 @@ export type UpdateLinkCommandPayload = {
65
65
  }
66
66
  /// A command to toggle the link mark.
67
67
  /// You can pass the `href` and `title` to the link.
68
- export const toggleLinkCommand = $command('ToggleLink', () => (payload: UpdateLinkCommandPayload = {}) => toggleMark(linkSchema.type(), payload))
68
+ export const toggleLinkCommand = $command('ToggleLink', ctx => (payload: UpdateLinkCommandPayload = {}) => toggleMark(linkSchema.type(ctx), payload))
69
69
 
70
70
  withMeta(toggleLinkCommand, {
71
71
  displayName: 'Command<toggleLinkCommand>',
@@ -74,7 +74,7 @@ withMeta(toggleLinkCommand, {
74
74
 
75
75
  /// A command to update the link mark.
76
76
  /// You can pass the `href` and `title` to update the link.
77
- export const updateLinkCommand = $command('UpdateLink', () => (payload: UpdateLinkCommandPayload = {}) => (state, dispatch) => {
77
+ export const updateLinkCommand = $command('UpdateLink', ctx => (payload: UpdateLinkCommandPayload = {}) => (state, dispatch) => {
78
78
  if (!dispatch)
79
79
  return false
80
80
 
@@ -83,7 +83,7 @@ export const updateLinkCommand = $command('UpdateLink', () => (payload: UpdateLi
83
83
  const { selection } = state
84
84
  const { from, to } = selection
85
85
  state.doc.nodesBetween(from, from === to ? to + 1 : to, (n, p) => {
86
- if (linkSchema.type().isInSet(n.marks)) {
86
+ if (linkSchema.type(ctx).isInSet(n.marks)) {
87
87
  node = n
88
88
  pos = p
89
89
  return false
@@ -95,14 +95,14 @@ export const updateLinkCommand = $command('UpdateLink', () => (payload: UpdateLi
95
95
  if (!node)
96
96
  return false
97
97
 
98
- const mark = node.marks.find(({ type }) => type === linkSchema.type())
98
+ const mark = node.marks.find(({ type }) => type === linkSchema.type(ctx))
99
99
  if (!mark)
100
100
  return false
101
101
 
102
102
  const start = pos
103
103
  const end = pos + node.nodeSize
104
104
  const { tr } = state
105
- const linkMark = linkSchema.type().create({ ...mark.attrs, ...payload })
105
+ const linkMark = linkSchema.type(ctx).create({ ...mark.attrs, ...payload })
106
106
  if (!linkMark)
107
107
  return false
108
108
 
@@ -1,7 +1,7 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { commandsCtx } from '@milkdown/core'
3
- import { toggleMark } from '@milkdown/prose/commands'
2
+ import { commandsCtx, remarkStringifyOptionsCtx } from '@milkdown/core'
4
3
  import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
4
+ import { toggleMark } from '@milkdown/prose/commands'
5
5
  import { withMeta } from '../__internal__'
6
6
 
7
7
  /// HTML attributes for the strong mark.
@@ -14,7 +14,11 @@ withMeta(strongAttr, {
14
14
 
15
15
  /// Strong mark schema.
16
16
  export const strongSchema = $markSchema('strong', ctx => ({
17
- inclusive: false,
17
+ attrs: {
18
+ marker: {
19
+ default: ctx.get(remarkStringifyOptionsCtx).strong || '*',
20
+ },
21
+ },
18
22
  parseDOM: [
19
23
  { tag: 'b' },
20
24
  { tag: 'strong' },
@@ -24,7 +28,7 @@ export const strongSchema = $markSchema('strong', ctx => ({
24
28
  parseMarkdown: {
25
29
  match: node => node.type === 'strong',
26
30
  runner: (state, node, markType) => {
27
- state.openMark(markType)
31
+ state.openMark(markType, { marker: node.marker })
28
32
  state.next(node.children)
29
33
  state.closeMark(markType)
30
34
  },
@@ -32,7 +36,9 @@ export const strongSchema = $markSchema('strong', ctx => ({
32
36
  toMarkdown: {
33
37
  match: mark => mark.type.name === 'strong',
34
38
  runner: (state, mark) => {
35
- state.withMark(mark, 'strong')
39
+ state.withMark(mark, 'strong', undefined, {
40
+ marker: mark.attrs.marker,
41
+ })
36
42
  },
37
43
  },
38
44
  }))
@@ -48,7 +54,9 @@ withMeta(strongSchema.ctx, {
48
54
  })
49
55
 
50
56
  /// A command to toggle the strong mark.
51
- export const toggleStrongCommand = $command('ToggleStrong', () => () => toggleMark(strongSchema.type()))
57
+ export const toggleStrongCommand = $command('ToggleStrong', ctx => () => {
58
+ return toggleMark(strongSchema.type(ctx))
59
+ })
52
60
 
53
61
  withMeta(toggleStrongCommand, {
54
62
  displayName: 'Command<toggleStrongCommand>',
@@ -47,7 +47,7 @@ withMeta(blockquoteSchema.ctx, {
47
47
 
48
48
  /// This input rule will convert a line that starts with `> ` into a blockquote.
49
49
  /// You can type `> ` at the start of a line to create a blockquote.
50
- export const wrapInBlockquoteInputRule = $inputRule(() => wrappingInputRule(/^\s*>\s$/, blockquoteSchema.type()))
50
+ export const wrapInBlockquoteInputRule = $inputRule(ctx => wrappingInputRule(/^\s*>\s$/, blockquoteSchema.type(ctx)))
51
51
 
52
52
  withMeta(wrapInBlockquoteInputRule, {
53
53
  displayName: 'InputRule<wrapInBlockquoteInputRule>',
@@ -55,7 +55,7 @@ withMeta(wrapInBlockquoteInputRule, {
55
55
  })
56
56
 
57
57
  /// This command will wrap the current selection in a blockquote.
58
- export const wrapInBlockquoteCommand = $command('WrapInBlockquote', () => () => wrapIn(blockquoteSchema.type()))
58
+ export const wrapInBlockquoteCommand = $command('WrapInBlockquote', ctx => () => wrapIn(blockquoteSchema.type(ctx)))
59
59
 
60
60
  withMeta(wrapInBlockquoteCommand, {
61
61
  displayName: 'Command<wrapInBlockquoteCommand>',
@@ -77,7 +77,7 @@ withMeta(bulletListSchema.ctx, {
77
77
  })
78
78
 
79
79
  /// Input rule for wrapping a block in bullet list node.
80
- export const wrapInBulletListInputRule = $inputRule(() => wrappingInputRule(/^\s*([-+*])\s$/, bulletListSchema.type()))
80
+ export const wrapInBulletListInputRule = $inputRule(ctx => wrappingInputRule(/^\s*([-+*])\s$/, bulletListSchema.type(ctx)))
81
81
 
82
82
  withMeta(wrapInBulletListInputRule, {
83
83
  displayName: 'InputRule<wrapInBulletListInputRule>',
@@ -85,7 +85,7 @@ withMeta(wrapInBulletListInputRule, {
85
85
  })
86
86
 
87
87
  /// Command for creating bullet list node.
88
- export const wrapInBulletListCommand = $command('WrapInBulletList', () => () => wrapIn(bulletListSchema.type()))
88
+ export const wrapInBulletListCommand = $command('WrapInBulletList', ctx => () => wrapIn(bulletListSchema.type(ctx)))
89
89
 
90
90
  withMeta(wrapInBulletListCommand, {
91
91
  displayName: 'Command<wrapInBulletListCommand>',
@@ -88,7 +88,7 @@ withMeta(codeBlockSchema.ctx, {
88
88
 
89
89
  /// A input rule for creating code block.
90
90
  /// For example, ` ```javascript ` will create a code block with language javascript.
91
- export const createCodeBlockInputRule = $inputRule(() => textblockTypeInputRule(/^```(?<language>[a-z]*)?[\s\n]$/, codeBlockSchema.type(), match => ({
91
+ export const createCodeBlockInputRule = $inputRule(ctx => textblockTypeInputRule(/^```(?<language>[a-z]*)?[\s\n]$/, codeBlockSchema.type(ctx), match => ({
92
92
  language: match.groups?.language ?? '',
93
93
  })))
94
94
 
@@ -99,7 +99,7 @@ withMeta(createCodeBlockInputRule, {
99
99
 
100
100
  /// A command for creating code block.
101
101
  /// You can pass the language of the code block as the parameter.
102
- export const createCodeBlockCommand = $command('CreateCodeBlock', () => (language = '') => setBlockType(codeBlockSchema.type(), { language }))
102
+ export const createCodeBlockCommand = $command('CreateCodeBlock', ctx => (language = '') => setBlockType(codeBlockSchema.type(ctx), { language }))
103
103
 
104
104
  withMeta(createCodeBlockCommand, {
105
105
  displayName: 'Command<createCodeBlockCommand>',
@@ -61,7 +61,7 @@ withMeta(hardbreakSchema.ctx, {
61
61
  })
62
62
 
63
63
  /// Command to insert a hardbreak.
64
- export const insertHardbreakCommand = $command('InsertHardbreak', () => () => (state, dispatch) => {
64
+ export const insertHardbreakCommand = $command('InsertHardbreak', ctx => () => (state, dispatch) => {
65
65
  const { selection, tr } = state
66
66
  if (selection.empty) {
67
67
  // Transform two successive hardbreak into a new line
@@ -76,7 +76,7 @@ export const insertHardbreakCommand = $command('InsertHardbreak', () => () => (s
76
76
  return true
77
77
  }
78
78
  }
79
- dispatch?.(tr.setMeta('hardbreak', true).replaceSelectionWith(hardbreakSchema.type().create()).scrollIntoView())
79
+ dispatch?.(tr.setMeta('hardbreak', true).replaceSelectionWith(hardbreakSchema.type(ctx).create()).scrollIntoView())
80
80
  return true
81
81
  })
82
82
 
@@ -100,7 +100,7 @@ withMeta(headingSchema.ctx, {
100
100
  /// This input rule can turn the selected block into heading.
101
101
  /// You can input numbers of `#` and a `space` to create heading.
102
102
  export const wrapInHeadingInputRule = $inputRule((ctx) => {
103
- return textblockTypeInputRule(/^(?<hashes>#+)\s$/, headingSchema.type(), (match) => {
103
+ return textblockTypeInputRule(/^(?<hashes>#+)\s$/, headingSchema.type(ctx), (match) => {
104
104
  const x = match.groups?.hashes?.length || 0
105
105
 
106
106
  const view = ctx.get(editorViewCtx)
@@ -125,14 +125,14 @@ withMeta(wrapInHeadingInputRule, {
125
125
  /// This command can turn the selected block into heading.
126
126
  /// You can pass the level of heading to this command.
127
127
  /// By default, the level is 1, which means it will create a `h1` element.
128
- export const wrapInHeadingCommand = $command('WrapInHeading', () => {
128
+ export const wrapInHeadingCommand = $command('WrapInHeading', (ctx) => {
129
129
  return (level?: number) => {
130
130
  level ??= 1
131
131
 
132
132
  if (level < 1)
133
- return setBlockType(paragraphSchema.type())
133
+ return setBlockType(paragraphSchema.type(ctx))
134
134
 
135
- return setBlockType(headingSchema.type(), { level })
135
+ return setBlockType(headingSchema.type(ctx), { level })
136
136
  }
137
137
  })
138
138
 
@@ -144,16 +144,16 @@ withMeta(wrapInHeadingCommand, {
144
144
  /// This command can downgrade the selected heading.
145
145
  /// For example, if you have a `h2` element, and you call this command, you will get a `h1` element.
146
146
  /// If the element is already a `h1` element, it will turn it into a `p` element.
147
- export const downgradeHeadingCommand = $command('DowngradeHeading', () => () =>
147
+ export const downgradeHeadingCommand = $command('DowngradeHeading', ctx => () =>
148
148
  (state, dispatch, view) => {
149
149
  const { $from } = state.selection
150
150
  const node = $from.node()
151
- if (node.type !== headingSchema.type() || !state.selection.empty || $from.parentOffset !== 0)
151
+ if (node.type !== headingSchema.type(ctx) || !state.selection.empty || $from.parentOffset !== 0)
152
152
  return false
153
153
 
154
154
  const level = node.attrs.level - 1
155
155
  if (!level)
156
- return setBlockType(paragraphSchema.type())(state, dispatch, view)
156
+ return setBlockType(paragraphSchema.type(ctx))(state, dispatch, view)
157
157
 
158
158
  dispatch?.(
159
159
  state.tr.setNodeMarkup(state.selection.$from.before(), undefined, {
@@ -198,21 +198,21 @@ export const headingKeymap = $useKeymap('headingKeymap', {
198
198
  shortcuts: 'Mod-Alt-4',
199
199
  command: (ctx) => {
200
200
  const commands = ctx.get(commandsCtx)
201
- return () => commands.call(wrapInHeadingCommand.key, 3)
201
+ return () => commands.call(wrapInHeadingCommand.key, 4)
202
202
  },
203
203
  },
204
204
  TurnIntoH5: {
205
205
  shortcuts: 'Mod-Alt-5',
206
206
  command: (ctx) => {
207
207
  const commands = ctx.get(commandsCtx)
208
- return () => commands.call(wrapInHeadingCommand.key, 3)
208
+ return () => commands.call(wrapInHeadingCommand.key, 5)
209
209
  },
210
210
  },
211
211
  TurnIntoH6: {
212
212
  shortcuts: 'Mod-Alt-6',
213
213
  command: (ctx) => {
214
214
  const commands = ctx.get(commandsCtx)
215
- return () => commands.call(wrapInHeadingCommand.key, 3)
215
+ return () => commands.call(wrapInHeadingCommand.key, 6)
216
216
  },
217
217
  },
218
218
  DowngradeHeading: {
package/src/node/hr.ts CHANGED
@@ -44,12 +44,12 @@ withMeta(hrSchema.ctx, {
44
44
 
45
45
  /// Input rule to insert a hr.
46
46
  /// For example, `---` will be converted to a hr.
47
- export const insertHrInputRule = $inputRule(() => new InputRule(
47
+ export const insertHrInputRule = $inputRule(ctx => new InputRule(
48
48
  /^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
49
49
  const { tr } = state
50
50
 
51
51
  if (match[0])
52
- tr.replaceWith(start - 1, end, hrSchema.type().create())
52
+ tr.replaceWith(start - 1, end, hrSchema.type(ctx).create())
53
53
 
54
54
  return tr
55
55
  },
@@ -61,14 +61,14 @@ withMeta(insertHrInputRule, {
61
61
  })
62
62
 
63
63
  /// Command to insert a hr.
64
- export const insertHrCommand = $command('InsertHr', () => () => (state, dispatch) => {
64
+ export const insertHrCommand = $command('InsertHr', ctx => () => (state, dispatch) => {
65
65
  if (!dispatch)
66
66
  return true
67
67
 
68
- const paragraph = paragraphSchema.node.type().create()
68
+ const paragraph = paragraphSchema.node.type(ctx).create()
69
69
  const { tr, selection } = state
70
70
  const { from } = selection
71
- const node = hrSchema.type().create()
71
+ const node = hrSchema.type(ctx).create()
72
72
  if (!node)
73
73
  return true
74
74
 
package/src/node/image.ts CHANGED
@@ -92,14 +92,14 @@ export type UpdateImageCommandPayload = {
92
92
 
93
93
  /// This command will insert a image node.
94
94
  /// You can pass a payload to set `src`, `alt` and `title` for the image node.
95
- export const insertImageCommand = $command('InsertImage', () => (payload: UpdateImageCommandPayload = {}) =>
95
+ export const insertImageCommand = $command('InsertImage', ctx => (payload: UpdateImageCommandPayload = {}) =>
96
96
  (state, dispatch) => {
97
97
  if (!dispatch)
98
98
  return true
99
99
 
100
100
  const { src = '', alt = '', title = '' } = payload
101
101
 
102
- const node = imageSchema.type().create({ src, alt, title })
102
+ const node = imageSchema.type(ctx).create({ src, alt, title })
103
103
  if (!node)
104
104
  return true
105
105
 
@@ -114,8 +114,8 @@ withMeta(insertImageCommand, {
114
114
 
115
115
  /// This command will update the selected image node.
116
116
  /// You can pass a payload to update `src`, `alt` and `title` for the image node.
117
- export const updateImageCommand = $command('UpdateImage', () => (payload: UpdateImageCommandPayload = {}) => (state, dispatch) => {
118
- const nodeWithPos = findSelectedNodeOfType(state.selection, imageSchema.type())
117
+ export const updateImageCommand = $command('UpdateImage', ctx => (payload: UpdateImageCommandPayload = {}) => (state, dispatch) => {
118
+ const nodeWithPos = findSelectedNodeOfType(state.selection, imageSchema.type(ctx))
119
119
  if (!nodeWithPos)
120
120
  return false
121
121
 
@@ -142,12 +142,12 @@ withMeta(updateImageCommand, {
142
142
  /// This input rule will insert a image node.
143
143
  /// You can input `![alt](src "title")` to insert a image node.
144
144
  /// The `title` is optional.
145
- export const insertImageInputRule = $inputRule(() => new InputRule(
145
+ export const insertImageInputRule = $inputRule(ctx => new InputRule(
146
146
  /!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,
147
147
  (state, match, start, end) => {
148
148
  const [matched, alt, src = '', title] = match
149
149
  if (matched)
150
- return state.tr.replaceWith(start, end, imageSchema.type().create({ src, alt, title }))
150
+ return state.tr.replaceWith(start, end, imageSchema.type(ctx).create({ src, alt, title }))
151
151
 
152
152
  return null
153
153
  },
@@ -4,6 +4,7 @@ import { expectDomTypeError } from '@milkdown/exception'
4
4
  import { liftListItem, sinkListItem, splitListItem } from '@milkdown/prose/schema-list'
5
5
  import { $command, $nodeAttr, $nodeSchema, $useKeymap } from '@milkdown/utils'
6
6
  import { type Command, TextSelection } from '@milkdown/prose/state'
7
+ import type { Ctx } from '@milkdown/ctx'
7
8
  import { withMeta } from '../__internal__'
8
9
 
9
10
  /// HTML attributes for list item node.
@@ -98,7 +99,7 @@ withMeta(listItemSchema.ctx, {
98
99
  /// * List item 1
99
100
  /// * List item 2
100
101
  /// ```
101
- export const sinkListItemCommand = $command('SinkListItem', () => () => sinkListItem(listItemSchema.type()))
102
+ export const sinkListItemCommand = $command('SinkListItem', ctx => () => sinkListItem(listItemSchema.type(ctx)))
102
103
 
103
104
  withMeta(sinkListItemCommand, {
104
105
  displayName: 'Command<sinkListItemCommand>',
@@ -117,7 +118,7 @@ withMeta(sinkListItemCommand, {
117
118
  /// * List item 1
118
119
  /// * List item 2
119
120
  /// ```
120
- export const liftListItemCommand = $command('SplitListItem', () => () => liftListItem(listItemSchema.type()))
121
+ export const liftListItemCommand = $command('SplitListItem', ctx => () => liftListItem(listItemSchema.type(ctx)))
121
122
 
122
123
  withMeta(liftListItemCommand, {
123
124
  displayName: 'Command<liftListItemCommand>',
@@ -137,14 +138,14 @@ withMeta(liftListItemCommand, {
137
138
  /// * List item 2
138
139
  /// * <- cursor here
139
140
  /// ```
140
- export const splitListItemCommand = $command('SplitListItem', () => () => splitListItem(listItemSchema.type()))
141
+ export const splitListItemCommand = $command('SplitListItem', ctx => () => splitListItem(listItemSchema.type(ctx)))
141
142
 
142
143
  withMeta(splitListItemCommand, {
143
144
  displayName: 'Command<splitListItemCommand>',
144
145
  group: 'ListItem',
145
146
  })
146
147
 
147
- const liftFirstListItem: Command = (state, dispatch, view) => {
148
+ const liftFirstListItem = (ctx: Ctx): Command => (state, dispatch, view) => {
148
149
  const { selection } = state
149
150
  if (!(selection instanceof TextSelection))
150
151
  return false
@@ -157,7 +158,7 @@ const liftFirstListItem: Command = (state, dispatch, view) => {
157
158
 
158
159
  const parentItem = $from.node(-1)
159
160
  // selection should be in list item and list item should be the first child of the list
160
- if (parentItem.type !== listItemSchema.type() || parentItem.firstChild !== $from.node())
161
+ if (parentItem.type !== listItemSchema.type(ctx) || parentItem.firstChild !== $from.node())
161
162
  return false
162
163
 
163
164
  const list = $from.node(-2)
@@ -165,7 +166,7 @@ const liftFirstListItem: Command = (state, dispatch, view) => {
165
166
  if (list.childCount > 1)
166
167
  return false
167
168
 
168
- return liftListItem(listItemSchema.type())(state, dispatch, view)
169
+ return liftListItem(listItemSchema.type(ctx))(state, dispatch, view)
169
170
  }
170
171
 
171
172
  /// The command to remove list item **only if**:
@@ -174,7 +175,7 @@ const liftFirstListItem: Command = (state, dispatch, view) => {
174
175
  /// - List item is the only child of the list.
175
176
  ///
176
177
  /// Most of the time, you shouldn't use this command directly.
177
- export const liftFirstListItemCommand = $command('LiftFirstListItem', () => () => liftFirstListItem)
178
+ export const liftFirstListItemCommand = $command('LiftFirstListItem', ctx => () => liftFirstListItem(ctx))
178
179
 
179
180
  withMeta(liftFirstListItemCommand, {
180
181
  displayName: 'Command<liftFirstListItemCommand>',
@@ -77,9 +77,9 @@ withMeta(orderedListSchema.ctx, {
77
77
  })
78
78
 
79
79
  /// Input rule for wrapping a block in ordered list node.
80
- export const wrapInOrderedListInputRule = $inputRule(() => wrappingInputRule(
80
+ export const wrapInOrderedListInputRule = $inputRule(ctx => wrappingInputRule(
81
81
  /^\s*(\d+)\.\s$/,
82
- orderedListSchema.type(),
82
+ orderedListSchema.type(ctx),
83
83
  match => ({ order: Number(match[1]) }),
84
84
  (match, node) => node.childCount + node.attrs.order === Number(match[1]),
85
85
  ))
@@ -90,7 +90,7 @@ withMeta(wrapInOrderedListInputRule, {
90
90
  })
91
91
 
92
92
  /// Command for wrapping a block in ordered list node.
93
- export const wrapInOrderedListCommand = $command('WrapInOrderedList', () => () => wrapIn(orderedListSchema.type()))
93
+ export const wrapInOrderedListCommand = $command('WrapInOrderedList', ctx => () => wrapIn(orderedListSchema.type(ctx)))
94
94
 
95
95
  withMeta(wrapInOrderedListCommand, {
96
96
  displayName: 'Command<wrapInOrderedListCommand>',