@milkdown/preset-commonmark 7.3.1 → 7.3.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.
Files changed (67) hide show
  1. package/lib/__internal__/serialize-text.d.ts +1 -1
  2. package/lib/__internal__/serialize-text.d.ts.map +1 -1
  3. package/lib/__internal__/with-meta.d.ts +1 -1
  4. package/lib/__internal__/with-meta.d.ts.map +1 -1
  5. package/lib/composed/inputrules.d.ts +2 -1
  6. package/lib/composed/inputrules.d.ts.map +1 -1
  7. package/lib/composed/plugins.d.ts.map +1 -1
  8. package/lib/composed/schema.d.ts.map +1 -1
  9. package/lib/index.d.ts.map +1 -1
  10. package/lib/index.es.js +615 -703
  11. package/lib/index.es.js.map +1 -1
  12. package/lib/mark/emphasis.d.ts +2 -0
  13. package/lib/mark/emphasis.d.ts.map +1 -1
  14. package/lib/mark/inline-code.d.ts +1 -0
  15. package/lib/mark/inline-code.d.ts.map +1 -1
  16. package/lib/mark/link.d.ts +2 -2
  17. package/lib/mark/link.d.ts.map +1 -1
  18. package/lib/mark/strong.d.ts +1 -0
  19. package/lib/mark/strong.d.ts.map +1 -1
  20. package/lib/node/heading.d.ts +3 -1
  21. package/lib/node/heading.d.ts.map +1 -1
  22. package/lib/node/hr.d.ts.map +1 -1
  23. package/lib/node/image.d.ts +2 -2
  24. package/lib/node/image.d.ts.map +1 -1
  25. package/lib/node/list-item.d.ts.map +1 -1
  26. package/lib/plugin/index.d.ts +0 -1
  27. package/lib/plugin/index.d.ts.map +1 -1
  28. package/package.json +9 -9
  29. package/src/__internal__/serialize-text.ts +1 -1
  30. package/src/__internal__/with-meta.ts +1 -4
  31. package/src/composed/inputrules.ts +10 -1
  32. package/src/composed/plugins.ts +2 -6
  33. package/src/composed/schema.ts +2 -1
  34. package/src/index.ts +2 -2
  35. package/src/mark/emphasis.ts +28 -1
  36. package/src/mark/inline-code.ts +12 -1
  37. package/src/mark/link.ts +1 -1
  38. package/src/mark/strong.ts +12 -1
  39. package/src/node/code-block.ts +1 -1
  40. package/src/node/heading.ts +3 -2
  41. package/src/node/hr.ts +2 -1
  42. package/src/node/image.ts +1 -1
  43. package/src/node/list-item.ts +24 -22
  44. package/src/plugin/hardbreak-clear-mark-plugin.ts +1 -1
  45. package/src/plugin/index.ts +0 -2
  46. package/src/plugin/remark-html-transformer.ts +1 -1
  47. package/lib/plugin/inline-sync-plugin/config.d.ts +0 -24
  48. package/lib/plugin/inline-sync-plugin/config.d.ts.map +0 -1
  49. package/lib/plugin/inline-sync-plugin/context.d.ts +0 -11
  50. package/lib/plugin/inline-sync-plugin/context.d.ts.map +0 -1
  51. package/lib/plugin/inline-sync-plugin/index.d.ts +0 -3
  52. package/lib/plugin/inline-sync-plugin/index.d.ts.map +0 -1
  53. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts +0 -2
  54. package/lib/plugin/inline-sync-plugin/inline-sync-plugin.d.ts.map +0 -1
  55. package/lib/plugin/inline-sync-plugin/regexp.d.ts +0 -9
  56. package/lib/plugin/inline-sync-plugin/regexp.d.ts.map +0 -1
  57. package/lib/plugin/inline-sync-plugin/replacer.d.ts +0 -5
  58. package/lib/plugin/inline-sync-plugin/replacer.d.ts.map +0 -1
  59. package/lib/plugin/inline-sync-plugin/utils.d.ts +0 -9
  60. package/lib/plugin/inline-sync-plugin/utils.d.ts.map +0 -1
  61. package/src/plugin/inline-sync-plugin/config.ts +0 -78
  62. package/src/plugin/inline-sync-plugin/context.ts +0 -121
  63. package/src/plugin/inline-sync-plugin/index.ts +0 -4
  64. package/src/plugin/inline-sync-plugin/inline-sync-plugin.ts +0 -72
  65. package/src/plugin/inline-sync-plugin/regexp.ts +0 -15
  66. package/src/plugin/inline-sync-plugin/replacer.ts +0 -56
  67. package/src/plugin/inline-sync-plugin/utils.ts +0 -92
@@ -1,5 +1,7 @@
1
1
  export declare const emphasisAttr: import("@milkdown/utils").$MarkAttr;
2
2
  export declare const emphasisSchema: import("@milkdown/utils").$MarkSchema<"emphasis">;
3
3
  export declare const toggleEmphasisCommand: import("@milkdown/utils").$Command<unknown>;
4
+ export declare const emphasisStarInputRule: import("@milkdown/utils").$InputRule;
5
+ export declare const emphasisUnderscoreInputRule: import("@milkdown/utils").$InputRule;
4
6
  export declare const emphasisKeymap: import("@milkdown/utils").$UserKeymap<"emphasisKeymap", "ToggleEmphasis">;
5
7
  //# sourceMappingURL=emphasis.d.ts.map
@@ -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,mDA4BxB,CAAA;AAaH,eAAO,MAAM,qBAAqB,6CAEhC,CAAA;AASF,eAAO,MAAM,cAAc,2EAQzB,CAAA"}
1
+ {"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["../../src/mark/emphasis.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,qCAAwB,CAAA;AAQjD,eAAO,MAAM,cAAc,mDA4BxB,CAAA;AAaH,eAAO,MAAM,qBAAqB,6CAEhC,CAAA;AAQF,eAAO,MAAM,qBAAqB,sCAKhC,CAAA;AAQF,eAAO,MAAM,2BAA2B,sCAKtC,CAAA;AASF,eAAO,MAAM,cAAc,2EAQzB,CAAA"}
@@ -1,5 +1,6 @@
1
1
  export declare const inlineCodeAttr: import("@milkdown/utils").$MarkAttr;
2
2
  export declare const inlineCodeSchema: import("@milkdown/utils").$MarkSchema<"inlineCode">;
3
3
  export declare const toggleInlineCodeCommand: import("@milkdown/utils").$Command<unknown>;
4
+ export declare const inlineCodeInputRule: import("@milkdown/utils").$InputRule;
4
5
  export declare const inlineCodeKeymap: import("@milkdown/utils").$UserKeymap<"inlineCodeKeymap", "ToggleInlineCode">;
5
6
  //# sourceMappingURL=inline-code.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inline-code.d.ts","sourceRoot":"","sources":["../../src/mark/inline-code.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,qDAoB1B,CAAA;AAaH,eAAO,MAAM,uBAAuB,6CAyBlC,CAAA;AASF,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
1
+ {"version":3,"file":"inline-code.d.ts","sourceRoot":"","sources":["../../src/mark/inline-code.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,qCAA0B,CAAA;AAQrD,eAAO,MAAM,gBAAgB,qDAoB1B,CAAA;AAaH,eAAO,MAAM,uBAAuB,6CAyBlC,CAAA;AAQF,eAAO,MAAM,mBAAmB,sCAE9B,CAAA;AASF,eAAO,MAAM,gBAAgB,+EAQ3B,CAAA"}
@@ -1,9 +1,9 @@
1
1
  export declare const linkAttr: import("@milkdown/utils").$MarkAttr;
2
2
  export declare const linkSchema: import("@milkdown/utils").$MarkSchema<"link">;
3
- export type UpdateLinkCommandPayload = {
3
+ export interface UpdateLinkCommandPayload {
4
4
  href?: string;
5
5
  title?: string;
6
- };
6
+ }
7
7
  export declare const toggleLinkCommand: import("@milkdown/utils").$Command<UpdateLinkCommandPayload>;
8
8
  export declare const updateLinkCommand: import("@milkdown/utils").$Command<UpdateLinkCommandPayload>;
9
9
  //# sourceMappingURL=link.d.ts.map
@@ -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,8DAAuH,CAAA;AASrJ,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,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAGD,eAAO,MAAM,iBAAiB,8DAAuH,CAAA;AASrJ,eAAO,MAAM,iBAAiB,8DAyC5B,CAAA"}
@@ -1,5 +1,6 @@
1
1
  export declare const strongAttr: import("@milkdown/utils").$MarkAttr;
2
2
  export declare const strongSchema: import("@milkdown/utils").$MarkSchema<"strong">;
3
3
  export declare const toggleStrongCommand: import("@milkdown/utils").$Command<unknown>;
4
+ export declare const strongInputRule: import("@milkdown/utils").$InputRule;
4
5
  export declare const strongKeymap: import("@milkdown/utils").$UserKeymap<"strongKeymap", "ToggleBold">;
5
6
  //# sourceMappingURL=strong.d.ts.map
@@ -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,iDA4BtB,CAAA;AAaH,eAAO,MAAM,mBAAmB,6CAE9B,CAAA;AASF,eAAO,MAAM,YAAY,qEAQvB,CAAA"}
1
+ {"version":3,"file":"strong.d.ts","sourceRoot":"","sources":["../../src/mark/strong.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,UAAU,qCAAsB,CAAA;AAQ7C,eAAO,MAAM,YAAY,iDA4BtB,CAAA;AAaH,eAAO,MAAM,mBAAmB,6CAE9B,CAAA;AAQF,eAAO,MAAM,eAAe,sCAE1B,CAAA;AASF,eAAO,MAAM,YAAY,qEAQvB,CAAA"}
@@ -1,9 +1,11 @@
1
1
  import type { Node } from '@milkdown/prose/model';
2
- export declare const headingIdGenerator: import("@milkdown/utils").$Ctx<(node: Node) => string, "headingIdGenerator">;
2
+ declare function defaultHeadingIdGenerator(node: Node): string;
3
+ export declare const headingIdGenerator: import("@milkdown/utils").$Ctx<typeof defaultHeadingIdGenerator, "headingIdGenerator">;
3
4
  export declare const headingAttr: import("@milkdown/utils").$NodeAttr;
4
5
  export declare const headingSchema: import("@milkdown/utils").$NodeSchema<"heading">;
5
6
  export declare const wrapInHeadingInputRule: import("@milkdown/utils").$InputRule;
6
7
  export declare const wrapInHeadingCommand: import("@milkdown/utils").$Command<number>;
7
8
  export declare const downgradeHeadingCommand: import("@milkdown/utils").$Command<unknown>;
8
9
  export declare const headingKeymap: import("@milkdown/utils").$UserKeymap<"headingKeymap", "DowngradeHeading" | "TurnIntoH1" | "TurnIntoH2" | "TurnIntoH3" | "TurnIntoH4" | "TurnIntoH5" | "TurnIntoH6">;
10
+ export {};
9
11
  //# sourceMappingURL=heading.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAejD,eAAO,MAAM,kBAAkB,wCALU,IAAI,kCAK0C,CAAA;AAQvF,eAAO,MAAM,WAAW,qCAAuB,CAAA;AAQ/C,eAAO,MAAM,aAAa,kDAmDxB,CAAA;AAcF,eAAO,MAAM,sBAAsB,sCAgBjC,CAAA;AAUF,eAAO,MAAM,oBAAoB,4CAS/B,CAAA;AAUF,eAAO,MAAM,uBAAuB,6CAkBhC,CAAA;AAUJ,eAAO,MAAM,aAAa,sKAkDxB,CAAA"}
1
+ {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/node/heading.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAUjD,iBAAS,yBAAyB,CAAC,IAAI,EAAE,IAAI,UAE5C;AAID,eAAO,MAAM,kBAAkB,wFAAwD,CAAA;AAQvF,eAAO,MAAM,WAAW,qCAAuB,CAAA;AAQ/C,eAAO,MAAM,aAAa,kDAmDxB,CAAA;AAcF,eAAO,MAAM,sBAAsB,sCAgBjC,CAAA;AAUF,eAAO,MAAM,oBAAoB,4CAS/B,CAAA;AAUF,eAAO,MAAM,uBAAuB,6CAkBhC,CAAA;AAUJ,eAAO,MAAM,aAAa,sKAkDxB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../src/node/hr.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM,qCAAkB,CAAA;AAQrC,eAAO,MAAM,QAAQ,6CAgBlB,CAAA;AAcH,eAAO,MAAM,iBAAiB,sCAS5B,CAAA;AAQF,eAAO,MAAM,eAAe,6CAkB1B,CAAA"}
1
+ {"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../src/node/hr.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,MAAM,qCAAkB,CAAA;AAQrC,eAAO,MAAM,QAAQ,6CAgBlB,CAAA;AAcH,eAAO,MAAM,iBAAiB,sCAU5B,CAAA;AAQF,eAAO,MAAM,eAAe,6CAkB1B,CAAA"}
@@ -1,10 +1,10 @@
1
1
  export declare const imageAttr: import("@milkdown/utils").$NodeAttr;
2
2
  export declare const imageSchema: import("@milkdown/utils").$NodeSchema<"image">;
3
- export type UpdateImageCommandPayload = {
3
+ export interface UpdateImageCommandPayload {
4
4
  src?: string;
5
5
  title?: string;
6
6
  alt?: string;
7
- };
7
+ }
8
8
  export declare const insertImageCommand: import("@milkdown/utils").$Command<UpdateImageCommandPayload>;
9
9
  export declare const updateImageCommand: import("@milkdown/utils").$Command<UpdateImageCommandPayload>;
10
10
  export declare const insertImageInputRule: import("@milkdown/utils").$InputRule;
@@ -1 +1 @@
1
- {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,qCAAqB,CAAA;AAQ3C,eAAO,MAAM,WAAW,gDAyDtB,CAAA;AAaF,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAID,eAAO,MAAM,kBAAkB,+DAa3B,CAAA;AASJ,eAAO,MAAM,kBAAkB,+DAkB7B,CAAA;AAUF,eAAO,MAAM,oBAAoB,sCAS/B,CAAA"}
1
+ {"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/node/image.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,qCAAqB,CAAA;AAQ3C,eAAO,MAAM,WAAW,gDAyDtB,CAAA;AAaF,MAAM,WAAW,yBAAyB;IACxC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAID,eAAO,MAAM,kBAAkB,+DAa3B,CAAA;AASJ,eAAO,MAAM,kBAAkB,+DAkB7B,CAAA;AAUF,eAAO,MAAM,oBAAoB,sCAS/B,CAAA"}
@@ -1 +1 @@
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
+ {"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;AAuCnH,eAAO,MAAM,wBAAwB,6CAAqE,CAAA;AAW1G,eAAO,MAAM,cAAc,iIA6BzB,CAAA"}
@@ -1,4 +1,3 @@
1
- export * from './inline-sync-plugin';
2
1
  export * from './remark-add-order-in-list-plugin';
3
2
  export * from './remark-line-break';
4
3
  export * from './remark-inline-link-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;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
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAEA,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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@milkdown/preset-commonmark",
3
3
  "type": "module",
4
- "version": "7.3.1",
4
+ "version": "7.3.3",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,7 +16,6 @@
16
16
  ],
17
17
  "sideEffects": false,
18
18
  "main": "./lib/index.es.js",
19
- "types": "./lib/index.d.ts",
20
19
  "files": [
21
20
  "lib",
22
21
  "src"
@@ -32,14 +31,14 @@
32
31
  "remark-inline-links": "^7.0.0",
33
32
  "tslib": "^2.5.0",
34
33
  "unist-util-visit": "^5.0.0",
35
- "@milkdown/exception": "7.3.1",
36
- "@milkdown/utils": "7.3.1"
34
+ "@milkdown/exception": "7.3.3",
35
+ "@milkdown/utils": "7.3.3"
37
36
  },
38
37
  "devDependencies": {
39
- "@milkdown/core": "7.3.1",
40
- "@milkdown/ctx": "7.3.1",
41
- "@milkdown/prose": "7.3.1",
42
- "@milkdown/transformer": "7.3.1"
38
+ "@milkdown/ctx": "7.3.3",
39
+ "@milkdown/prose": "7.3.3",
40
+ "@milkdown/core": "7.3.3",
41
+ "@milkdown/transformer": "7.3.3"
43
42
  },
44
43
  "nx": {
45
44
  "targets": {
@@ -70,5 +69,6 @@
70
69
  "test": "vitest",
71
70
  "tsc": "tsc --noEmit && echo",
72
71
  "build": "tsc --emitDeclarationOnly && vite build"
73
- }
72
+ },
73
+ "types": "./lib/index.d.ts"
74
74
  }
@@ -3,7 +3,7 @@ import type { SerializerState } from '@milkdown/transformer'
3
3
  import type { Node } from '@milkdown/prose/model'
4
4
  import { Fragment } from '@milkdown/prose/model'
5
5
 
6
- export const serializeText = (state: SerializerState, node: Node) => {
6
+ export function serializeText(state: SerializerState, node: Node) {
7
7
  const lastIsHardBreak
8
8
  = node.childCount >= 1 && node.lastChild?.type.name === 'hardbreak'
9
9
  if (!lastIsHardBreak) {
@@ -1,10 +1,7 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import type { Meta, MilkdownPlugin } from '@milkdown/ctx'
3
3
 
4
- export const withMeta = <T extends MilkdownPlugin>(
5
- plugin: T,
6
- meta: Partial<Meta> & Pick<Meta, 'displayName'>,
7
- ): T => {
4
+ export function withMeta<T extends MilkdownPlugin>(plugin: T, meta: Partial<Meta> & Pick<Meta, 'displayName'>): T {
8
5
  Object.assign(plugin, {
9
6
  meta: {
10
7
  package: '@milkdown/preset-commonmark',
@@ -1,9 +1,10 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import type { MilkdownPlugin } from '@milkdown/ctx'
3
3
  import { createCodeBlockInputRule, insertHrInputRule, wrapInBlockquoteInputRule, wrapInBulletListInputRule, wrapInHeadingInputRule, wrapInOrderedListInputRule } from '../node'
4
+ import { emphasisStarInputRule, emphasisUnderscoreInputRule, inlineCodeInputRule, strongInputRule } from '../mark'
4
5
 
5
6
  /// @internal
6
- export const inputrules: MilkdownPlugin[] = [
7
+ export const inputRules: MilkdownPlugin[] = [
7
8
  wrapInBlockquoteInputRule,
8
9
  wrapInBulletListInputRule,
9
10
  wrapInOrderedListInputRule,
@@ -11,3 +12,11 @@ export const inputrules: MilkdownPlugin[] = [
11
12
  insertHrInputRule,
12
13
  wrapInHeadingInputRule,
13
14
  ].flat()
15
+
16
+ /// @internal
17
+ export const markInputRules: MilkdownPlugin[] = [
18
+ emphasisStarInputRule,
19
+ emphasisUnderscoreInputRule,
20
+ inlineCodeInputRule,
21
+ strongInputRule,
22
+ ]
@@ -6,21 +6,17 @@ import {
6
6
  hardbreakFilterNodes,
7
7
  hardbreakFilterPlugin,
8
8
  inlineNodesCursorPlugin,
9
- inlineSyncConfig,
10
- inlineSyncPlugin,
11
9
  remarkAddOrderInListPlugin,
12
10
  remarkHtmlTransformer,
13
11
  remarkInlineLinkPlugin,
14
- remarkLineBreak, remarkMarker,
12
+ remarkLineBreak,
13
+ remarkMarker,
15
14
  syncHeadingIdPlugin,
16
15
  syncListOrderPlugin,
17
16
  } from '../plugin'
18
17
 
19
18
  /// @internal
20
19
  export const plugins: MilkdownPlugin[] = [
21
- inlineSyncConfig,
22
- inlineSyncPlugin,
23
-
24
20
  hardbreakClearMarkPlugin,
25
21
  hardbreakFilterNodes,
26
22
  hardbreakFilterPlugin,
@@ -16,7 +16,8 @@ import {
16
16
  headingIdGenerator,
17
17
  headingSchema,
18
18
  hrAttr,
19
- hrSchema, htmlAttr,
19
+ hrSchema,
20
+ htmlAttr,
20
21
  htmlSchema,
21
22
  imageAttr,
22
23
  imageSchema,
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- import { commands, inputrules, keymap, plugins, schema } from './composed'
3
+ import { commands, inputRules, keymap, markInputRules, plugins, schema } from './composed'
4
4
 
5
5
  export * from './node'
6
6
  export * from './mark'
@@ -8,4 +8,4 @@ export * from './plugin'
8
8
  export * from './composed'
9
9
 
10
10
  /// The commonmark preset, includes all the plugins.
11
- export const commonmark = [schema, inputrules, commands, keymap, plugins].flat()
11
+ export const commonmark = [schema, inputRules, markInputRules, commands, keymap, plugins].flat()
@@ -1,7 +1,8 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { commandsCtx, remarkStringifyOptionsCtx } from '@milkdown/core'
3
- import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
3
+ import { $command, $inputRule, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
4
4
  import { toggleMark } from '@milkdown/prose/commands'
5
+ import { markRule } from '@milkdown/prose'
5
6
  import { withMeta } from '../__internal__'
6
7
 
7
8
  /// HTML attributes for the emphasis mark.
@@ -63,6 +64,32 @@ withMeta(toggleEmphasisCommand, {
63
64
  group: 'Emphasis',
64
65
  })
65
66
 
67
+ /// Input rule for use `*` to create emphasis mark.
68
+ export const emphasisStarInputRule = $inputRule((ctx) => {
69
+ return markRule(/(?:^|[^*])\*([^*]+)\*$/, emphasisSchema.type(ctx), {
70
+ updateCaptured: ({ fullMatch, start }) =>
71
+ !fullMatch.startsWith('*') ? { fullMatch: fullMatch.slice(1), start: start + 1 } : {},
72
+ })
73
+ })
74
+
75
+ withMeta(emphasisStarInputRule, {
76
+ displayName: 'InputRule<emphasis>|Star',
77
+ group: 'Emphasis',
78
+ })
79
+
80
+ /// Input rule for use `_` to create emphasis mark.
81
+ export const emphasisUnderscoreInputRule = $inputRule((ctx) => {
82
+ return markRule(/(?:^|[^_])_([^_]+)_$/, emphasisSchema.type(ctx), {
83
+ updateCaptured: ({ fullMatch, start }) =>
84
+ !fullMatch.startsWith('_') ? { fullMatch: fullMatch.slice(1), start: start + 1 } : {},
85
+ })
86
+ })
87
+
88
+ withMeta(emphasisUnderscoreInputRule, {
89
+ displayName: 'InputRule<emphasis>|Underscore',
90
+ group: 'Emphasis',
91
+ })
92
+
66
93
  /// Keymap for the emphasis mark.
67
94
  /// - `Mod-i` - Toggle the emphasis mark.
68
95
  export const emphasisKeymap = $useKeymap('emphasisKeymap', {
@@ -1,7 +1,8 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { commandsCtx } from '@milkdown/core'
3
3
  import type { MarkType } from '@milkdown/prose/model'
4
- import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
4
+ import { $command, $inputRule, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
5
+ import { markRule } from '@milkdown/prose'
5
6
  import { withMeta } from '../__internal__'
6
7
 
7
8
  /// HTML attributes for the inlineCode mark.
@@ -78,6 +79,16 @@ withMeta(toggleInlineCodeCommand, {
78
79
  group: 'InlineCode',
79
80
  })
80
81
 
82
+ /// Input rule for create inlineCode mark.
83
+ export const inlineCodeInputRule = $inputRule((ctx) => {
84
+ return markRule(/(?:\`)([^\`]+)(?:\`)$/, inlineCodeSchema.type(ctx))
85
+ })
86
+
87
+ withMeta(inlineCodeInputRule, {
88
+ displayName: 'InputRule<inlineCodeInputRule>',
89
+ group: 'InlineCode',
90
+ })
91
+
81
92
  /// Keymap for the inlineCode mark.
82
93
  /// - `Mod-e` - Toggle the inlineCode mark.
83
94
  export const inlineCodeKeymap = $useKeymap('inlineCodeKeymap', {
package/src/mark/link.ts CHANGED
@@ -59,7 +59,7 @@ withMeta(linkSchema.mark, {
59
59
  })
60
60
 
61
61
  /// @internal
62
- export type UpdateLinkCommandPayload = {
62
+ export interface UpdateLinkCommandPayload {
63
63
  href?: string
64
64
  title?: string
65
65
  }
@@ -1,7 +1,8 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { commandsCtx, remarkStringifyOptionsCtx } from '@milkdown/core'
3
- import { $command, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
3
+ import { $command, $inputRule, $markAttr, $markSchema, $useKeymap } from '@milkdown/utils'
4
4
  import { toggleMark } from '@milkdown/prose/commands'
5
+ import { markRule } from '@milkdown/prose'
5
6
  import { withMeta } from '../__internal__'
6
7
 
7
8
  /// HTML attributes for the strong mark.
@@ -63,6 +64,16 @@ withMeta(toggleStrongCommand, {
63
64
  group: 'Strong',
64
65
  })
65
66
 
67
+ /// A input rule that will capture the strong mark.
68
+ export const strongInputRule = $inputRule((ctx) => {
69
+ return markRule(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/, strongSchema.type(ctx))
70
+ })
71
+
72
+ withMeta(strongInputRule, {
73
+ displayName: 'InputRule<strong>',
74
+ group: 'Strong',
75
+ })
76
+
66
77
  /// Keymap for the strong mark.
67
78
  /// - `Mod-b` - Toggle the strong mark.
68
79
  export const strongKeymap = $useKeymap('strongKeymap', {
@@ -107,7 +107,7 @@ withMeta(createCodeBlockCommand, {
107
107
  })
108
108
 
109
109
  /// A command for updating the code block language of the target position.
110
- export const updateCodeBlockLanguageCommand = $command('UpdateCodeBlockLanguage', () => ({ pos, language }: { pos: number; language: string } = { pos: -1, language: '' }) => (state, dispatch) => {
110
+ export const updateCodeBlockLanguageCommand = $command('UpdateCodeBlockLanguage', () => ({ pos, language }: { pos: number, language: string } = { pos: -1, language: '' }) => (state, dispatch) => {
111
111
  if (pos >= 0) {
112
112
  dispatch?.(state.tr.setNodeAttribute(pos, 'language', language))
113
113
  return true
@@ -13,8 +13,9 @@ const headingIndex = Array(6)
13
13
  .fill(0)
14
14
  .map((_, i) => i + 1)
15
15
 
16
- const defaultHeadingIdGenerator = (node: Node) =>
17
- slugify(node.textContent)
16
+ function defaultHeadingIdGenerator(node: Node) {
17
+ return slugify(node.textContent)
18
+ }
18
19
 
19
20
  /// This is a slice contains a function to generate heading id.
20
21
  /// You can configure it to generate id in your own way.
package/src/node/hr.ts CHANGED
@@ -45,7 +45,8 @@ withMeta(hrSchema.ctx, {
45
45
  /// Input rule to insert a hr.
46
46
  /// For example, `---` will be converted to a hr.
47
47
  export const insertHrInputRule = $inputRule(ctx => new InputRule(
48
- /^(?:---|___\s|\*\*\*\s)$/, (state, match, start, end) => {
48
+ /^(?:---|___\s|\*\*\*\s)$/,
49
+ (state, match, start, end) => {
49
50
  const { tr } = state
50
51
 
51
52
  if (match[0])
package/src/node/image.ts CHANGED
@@ -84,7 +84,7 @@ withMeta(imageSchema.ctx, {
84
84
  })
85
85
 
86
86
  /// @internal
87
- export type UpdateImageCommandPayload = {
87
+ export interface UpdateImageCommandPayload {
88
88
  src?: string
89
89
  title?: string
90
90
  alt?: string
@@ -145,28 +145,30 @@ withMeta(splitListItemCommand, {
145
145
  group: 'ListItem',
146
146
  })
147
147
 
148
- const liftFirstListItem = (ctx: Ctx): Command => (state, dispatch, view) => {
149
- const { selection } = state
150
- if (!(selection instanceof TextSelection))
151
- return false
152
-
153
- const { empty, $from } = selection
154
-
155
- // selection should be empty and at the start of the node
156
- if (!empty || $from.parentOffset !== 0)
157
- return false
158
-
159
- const parentItem = $from.node(-1)
160
- // selection should be in list item and list item should be the first child of the list
161
- if (parentItem.type !== listItemSchema.type(ctx) || parentItem.firstChild !== $from.node())
162
- return false
163
-
164
- const list = $from.node(-2)
165
- // list should have only one list item
166
- if (list.childCount > 1)
167
- return false
168
-
169
- return liftListItem(listItemSchema.type(ctx))(state, dispatch, view)
148
+ function liftFirstListItem(ctx: Ctx): Command {
149
+ return (state, dispatch, view) => {
150
+ const { selection } = state
151
+ if (!(selection instanceof TextSelection))
152
+ return false
153
+
154
+ const { empty, $from } = selection
155
+
156
+ // selection should be empty and at the start of the node
157
+ if (!empty || $from.parentOffset !== 0)
158
+ return false
159
+
160
+ const parentItem = $from.node(-1)
161
+ // selection should be in list item and list item should be the first child of the list
162
+ if (parentItem.type !== listItemSchema.type(ctx) || parentItem.firstChild !== $from.node())
163
+ return false
164
+
165
+ const list = $from.node(-2)
166
+ // list should have only one list item
167
+ if (list.childCount > 1)
168
+ return false
169
+
170
+ return liftListItem(listItemSchema.type(ctx))(state, dispatch, view)
171
+ }
170
172
  }
171
173
 
172
174
  /// The command to remove list item **only if**:
@@ -31,7 +31,7 @@ export const hardbreakClearMarkPlugin = $prose((ctx) => {
31
31
  const isAddMarkStep = step instanceof AddMarkStep
32
32
  if (isAddMarkStep) {
33
33
  let _tr = newState.tr
34
- const { from, to } = step as unknown as { from: number; to: number }
34
+ const { from, to } = step as unknown as { from: number, to: number }
35
35
  newState.doc.nodesBetween(from, to, (node, pos) => {
36
36
  if (node.type === hardbreakSchema.type(ctx))
37
37
  _tr = _tr.setNodeMarkup(pos, hardbreakSchema.type(ctx), undefined, [])
@@ -1,7 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- export * from './inline-sync-plugin'
4
-
5
3
  export * from './remark-add-order-in-list-plugin'
6
4
  export * from './remark-line-break'
7
5
  export * from './remark-inline-link-plugin'
@@ -4,7 +4,7 @@ import type { Node } from '@milkdown/transformer'
4
4
  import { withMeta } from '../__internal__'
5
5
 
6
6
  const isParent = (node: Node): node is Node & { children: Node[] } => !!(node as Node & { children: Node[] }).children
7
- const isHTML = (node: Node): node is Node & { children: Node[]; value: unknown } => node.type === 'html'
7
+ const isHTML = (node: Node): node is Node & { children: Node[], value: unknown } => node.type === 'html'
8
8
 
9
9
  function flatMapWithDepth(ast: Node, fn: (node: Node, index: number, parent: Node | null) => Node[]) {
10
10
  return transform(ast, 0, null)[0]
@@ -1,24 +0,0 @@
1
- import type { Ctx } from '@milkdown/ctx';
2
- import type { Node, NodeType } from '@milkdown/prose/model';
3
- import type { Transaction } from '@milkdown/prose/state';
4
- export type ShouldSyncNode = (context: {
5
- prevNode: Node;
6
- nextNode: Node;
7
- ctx: Ctx;
8
- tr: Transaction;
9
- text: string;
10
- }) => boolean;
11
- export interface SyncNodePlaceholder {
12
- hole: string;
13
- punctuation: string;
14
- char: string;
15
- }
16
- export interface InlineSyncConfig {
17
- placeholderConfig: SyncNodePlaceholder;
18
- shouldSyncNode: ShouldSyncNode;
19
- globalNodes: Array<NodeType | string>;
20
- movePlaceholder: (placeholderToMove: string, text: string) => string;
21
- }
22
- export declare const defaultConfig: InlineSyncConfig;
23
- export declare const inlineSyncConfig: import("@milkdown/utils").$Ctx<InlineSyncConfig, "inlineSyncConfig">;
24
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOxD,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;AAGb,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;CACb;AAGD,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;AAGD,eAAO,MAAM,aAAa,EAAE,gBAyB3B,CAAA;AAaD,eAAO,MAAM,gBAAgB,sEAAgF,CAAA"}
@@ -1,11 +0,0 @@
1
- import type { Ctx } from '@milkdown/ctx';
2
- import type { Node } from '@milkdown/prose/model';
3
- import type { EditorState } from '@milkdown/prose/state';
4
- export interface InlineSyncContext {
5
- text: string;
6
- prevNode: Node;
7
- nextNode: Node;
8
- placeholder: string;
9
- }
10
- export declare const getContextByState: (ctx: Ctx, state: EditorState) => InlineSyncContext | null;
11
- //# sourceMappingURL=context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAOxD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,IAAI,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACpB;AAiED,eAAO,MAAM,iBAAiB,QAAS,GAAG,SAAS,WAAW,KAAG,iBAAiB,GAAG,IAuCpF,CAAA"}
@@ -1,3 +0,0 @@
1
- export * from './config';
2
- export * from './inline-sync-plugin';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAA;AACxB,cAAc,sBAAsB,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare const inlineSyncPlugin: import("@milkdown/utils").$Prose;
2
- //# sourceMappingURL=inline-sync-plugin.d.ts.map
@@ -1 +0,0 @@
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,9 +0,0 @@
1
- export declare const linkRegexp: RegExp;
2
- export declare const keepLinkRegexp: RegExp;
3
- export declare const punctuationRegexp: (holePlaceholder: string) => RegExp;
4
- export declare const ZERO_WIDTH_SPACE = "\u200B";
5
- export declare const asterisk: string;
6
- export declare const asteriskHolder: string;
7
- export declare const underline: string;
8
- export declare const underlineHolder: string;
9
- //# sourceMappingURL=regexp.d.ts.map
@@ -1 +0,0 @@
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;AAE9D,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,eAAO,MAAM,QAAQ,QAAyB,CAAA;AAC9C,eAAO,MAAM,cAAc,QAAyB,CAAA;AACpD,eAAO,MAAM,SAAS,QAAyB,CAAA;AAC/C,eAAO,MAAM,eAAe,QAAyB,CAAA"}
@@ -1,5 +0,0 @@
1
- import type { Ctx } from '@milkdown/ctx';
2
- import type { Attrs } from '@milkdown/prose/model';
3
- import type { EditorState, PluginKey, Transaction } from '@milkdown/prose/state';
4
- export declare const runReplacer: (ctx: Ctx, key: PluginKey, state: EditorState, dispatch: (tr: Transaction) => void, attrs: Attrs) => void;
5
- //# sourceMappingURL=replacer.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,9 +0,0 @@
1
- import type { Node } from '@milkdown/prose/model';
2
- import type { SyncNodePlaceholder } from './config';
3
- export declare const keepLink: (str: string) => string;
4
- export declare const mergeSlash: (str: string) => string;
5
- export declare const swap: (text: string, first: number, last: number) => string;
6
- export declare const replacePunctuation: (holePlaceholder: string) => (text: string) => string;
7
- export declare const calculatePlaceholder: (placeholder: SyncNodePlaceholder) => (text: string) => string;
8
- export declare const calcOffset: (node: Node, from: number, placeholder: string) => number;
9
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/plugin/inline-sync-plugin/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAUnD,eAAO,MAAM,QAAQ,QAAS,MAAM,WAUnC,CAAA;AAED,eAAO,MAAM,UAAU,QAAS,MAAM,WAMrC,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,WAwBvE,CAAA"}