@milkdown/preset-commonmark 7.2.2 → 7.2.3

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.
@@ -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,6CAIhC,CAAA;AASF,eAAO,MAAM,cAAc,2EAQzB,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,6CAK9B,CAAA;AASF,eAAO,MAAM,YAAY,qEAQvB,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.3",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,15 +32,16 @@
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
+ "vfile": "^5.3.7",
36
+ "@milkdown/exception": "7.2.3",
37
+ "@milkdown/utils": "7.2.3"
37
38
  },
38
39
  "devDependencies": {
39
40
  "@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"
41
+ "@milkdown/core": "7.2.3",
42
+ "@milkdown/ctx": "7.2.3",
43
+ "@milkdown/prose": "7.2.3",
44
+ "@milkdown/transformer": "7.2.3"
44
45
  },
45
46
  "nx": {
46
47
  "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 { toggleMarkdownMark } from '@milkdown/prose'
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,11 @@ 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
+ const markType = emphasisSchema.type()
59
+ const mark = ctx.get(remarkStringifyOptionsCtx).emphasis || '*'
60
+ return toggleMarkdownMark(markType, mark)
61
+ })
52
62
 
53
63
  withMeta(toggleEmphasisCommand, {
54
64
  displayName: 'Command<toggleEmphasisCommand>',
@@ -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 { toggleMarkdownMark } from '@milkdown/prose'
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,12 @@ 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
+ const markType = strongSchema.type()
59
+ const markSymbol = ctx.get(remarkStringifyOptionsCtx).strong || '*'
60
+ const mark = markSymbol + markSymbol
61
+ return toggleMarkdownMark(markType, mark)
62
+ })
52
63
 
53
64
  withMeta(toggleStrongCommand, {
54
65
  displayName: 'Command<toggleStrongCommand>',
@@ -6,6 +6,7 @@ export * from './remark-add-order-in-list-plugin'
6
6
  export * from './remark-line-break'
7
7
  export * from './remark-inline-link-plugin'
8
8
  export * from './remark-html-transformer'
9
+ export * from './remark-marker-plugin'
9
10
 
10
11
  export * from './inline-nodes-cursor-plugin'
11
12
 
@@ -60,8 +60,6 @@ export const inlineSyncPlugin = $prose((ctx: Ctx) => {
60
60
  runReplacer(ctx, inlineSyncPluginKey, state, dispatch, prevNode.attrs)
61
61
  })
62
62
 
63
- tr.setMeta('addToHistory', false)
64
-
65
63
  return null
66
64
  },
67
65
  },
@@ -1,6 +1,8 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- export const linkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/
3
+ export const linkRegexp = /\[([^\]]+)]\([^\s\]]+\)/
4
+
5
+ export const keepLinkRegexp = /\[(?<span>((www|https:\/\/|http:\/\/)[^\s\]]+))]\((?<url>[^\s\]]+)\)/
4
6
 
5
7
  export const punctuationRegexp = (holePlaceholder: string) =>
6
8
  new RegExp(`\\\\(?=[^\\w\\s${holePlaceholder}\\\\]|_)`, 'g')
@@ -7,6 +7,7 @@ import { TextSelection } from '@milkdown/prose/state'
7
7
  import { inlineSyncConfig } from './config'
8
8
  import { getContextByState } from './context'
9
9
  import { calcOffset } from './utils'
10
+ import { linkRegexp } from './regexp'
10
11
 
11
12
  export const runReplacer = (
12
13
  ctx: Ctx,
@@ -26,6 +27,8 @@ export const runReplacer = (
26
27
  if (!context)
27
28
  return
28
29
 
30
+ const lastUserInput = context.text.slice(0, context.text.indexOf(context.placeholder))
31
+
29
32
  const { $from } = nextState.selection
30
33
  const from = $from.before()
31
34
  const to = $from.after()
@@ -41,5 +44,13 @@ export const runReplacer = (
41
44
  // restore the selection
42
45
  tr = tr.setSelection(TextSelection.near(tr.doc.resolve(offset + 1)))
43
46
 
47
+ const needsRestoreMark = linkRegexp.test(lastUserInput) || ['*', '_', '~'].includes(lastUserInput.at(-1) || '')
48
+ if (needsRestoreMark && tr.selection instanceof TextSelection) {
49
+ const marks = tr.selection.$cursor?.marks() ?? []
50
+ marks.forEach((mark) => {
51
+ tr = tr.removeStoredMark(mark.type)
52
+ })
53
+ }
54
+
44
55
  dispatch(tr)
45
56
  }
@@ -3,16 +3,16 @@
3
3
  import type { Node } from '@milkdown/prose/model'
4
4
 
5
5
  import type { SyncNodePlaceholder } from './config'
6
- import { linkRegexp, punctuationRegexp } from './regexp'
6
+ import { keepLinkRegexp, punctuationRegexp } from './regexp'
7
7
 
8
8
  export const keepLink = (str: string) => {
9
9
  let text = str
10
- let match = text.match(linkRegexp)
10
+ let match = text.match(keepLinkRegexp)
11
11
  while (match && match.groups) {
12
12
  const { span } = match.groups
13
- text = text.replace(linkRegexp, span as string)
13
+ text = text.replace(keepLinkRegexp, span as string)
14
14
 
15
- match = text.match(linkRegexp)
15
+ match = text.match(keepLinkRegexp)
16
16
  }
17
17
  return text
18
18
  }
@@ -0,0 +1,20 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { $remark } from '@milkdown/utils'
3
+ import type { Node } from 'unist'
4
+ import type { VFile } from 'vfile'
5
+ import { visit } from 'unist-util-visit'
6
+ import { withMeta } from '../__internal__'
7
+
8
+ export const remarkMarker = $remark(() => () => (tree: Node, file: VFile) => {
9
+ const getMarker = (node: Node) => {
10
+ return (file.value as string).charAt(node.position!.start.offset!)
11
+ }
12
+ visit(tree, node => ['strong', 'emphasis'].includes(node.type), (node: Node) => {
13
+ (node as Node & { marker: string }).marker = getMarker(node)
14
+ })
15
+ })
16
+
17
+ withMeta(remarkMarker, {
18
+ displayName: 'Remark<remarkMarker>',
19
+ group: 'Remark',
20
+ })