@milkdown/preset-commonmark 5.3.1 → 5.3.5

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 (85) hide show
  1. package/lib/index.d.ts +1 -34
  2. package/lib/index.es.js +105 -49
  3. package/lib/index.es.js.map +1 -1
  4. package/lib/src/index.d.ts +34 -0
  5. package/lib/src/index.d.ts.map +1 -0
  6. package/lib/{mark → src/mark}/code-inline.d.ts +1 -1
  7. package/lib/src/mark/code-inline.d.ts.map +1 -0
  8. package/lib/{mark → src/mark}/em.d.ts +1 -1
  9. package/lib/src/mark/em.d.ts.map +1 -0
  10. package/lib/src/mark/index.d.ts +6 -0
  11. package/lib/src/mark/index.d.ts.map +1 -0
  12. package/lib/{mark → src/mark}/link.d.ts +1 -1
  13. package/lib/src/mark/link.d.ts.map +1 -0
  14. package/lib/{mark → src/mark}/strong.d.ts +1 -1
  15. package/lib/src/mark/strong.d.ts.map +1 -0
  16. package/lib/{node → src/node}/blockquote.d.ts +1 -1
  17. package/lib/src/node/blockquote.d.ts.map +1 -0
  18. package/lib/{node → src/node}/bullet-list.d.ts +1 -1
  19. package/lib/src/node/bullet-list.d.ts.map +1 -0
  20. package/lib/{node → src/node}/code-fence.d.ts +1 -1
  21. package/lib/src/node/code-fence.d.ts.map +1 -0
  22. package/lib/{node → src/node}/doc.d.ts +1 -1
  23. package/lib/src/node/doc.d.ts.map +1 -0
  24. package/lib/{node → src/node}/hardbreak.d.ts +1 -1
  25. package/lib/src/node/hardbreak.d.ts.map +1 -0
  26. package/lib/{node → src/node}/heading.d.ts +3 -1
  27. package/lib/src/node/heading.d.ts.map +1 -0
  28. package/lib/{node → src/node}/hr.d.ts +1 -1
  29. package/lib/src/node/hr.d.ts.map +1 -0
  30. package/lib/{node → src/node}/image.d.ts +1 -1
  31. package/lib/src/node/image.d.ts.map +1 -0
  32. package/lib/{node → src/node}/index.d.ts +2 -2
  33. package/lib/src/node/index.d.ts.map +1 -0
  34. package/lib/{node → src/node}/list-item.d.ts +1 -1
  35. package/lib/src/node/list-item.d.ts.map +1 -0
  36. package/lib/{node → src/node}/ordered-list.d.ts +1 -1
  37. package/lib/src/node/ordered-list.d.ts.map +1 -0
  38. package/lib/{node → src/node}/paragraph.d.ts +1 -1
  39. package/lib/src/node/paragraph.d.ts.map +1 -0
  40. package/lib/{node → src/node}/text.d.ts +1 -1
  41. package/lib/src/node/text.d.ts.map +1 -0
  42. package/lib/{plugin → src/plugin}/filter-html.d.ts +0 -0
  43. package/lib/src/plugin/filter-html.d.ts.map +1 -0
  44. package/lib/src/plugin/index.d.ts +2 -0
  45. package/lib/src/plugin/index.d.ts.map +1 -0
  46. package/lib/{supported-keys.d.ts → src/supported-keys.d.ts} +0 -0
  47. package/lib/src/supported-keys.d.ts.map +1 -0
  48. package/lib/src/types.d.ts +5 -0
  49. package/package.json +7 -14
  50. package/src/mark/code-inline.ts +6 -7
  51. package/src/mark/link.ts +1 -2
  52. package/src/mark/strong.ts +1 -2
  53. package/src/node/blockquote.ts +1 -2
  54. package/src/node/bullet-list.ts +1 -1
  55. package/src/node/code-fence.ts +3 -4
  56. package/src/node/heading.ts +74 -25
  57. package/src/node/hr.ts +1 -2
  58. package/src/node/image.ts +12 -5
  59. package/src/node/list-item.ts +1 -2
  60. package/src/node/ordered-list.ts +1 -1
  61. package/src/node/paragraph.ts +8 -9
  62. package/lib/index.d.ts.map +0 -1
  63. package/lib/mark/code-inline.d.ts.map +0 -1
  64. package/lib/mark/em.d.ts.map +0 -1
  65. package/lib/mark/index.d.ts +0 -6
  66. package/lib/mark/index.d.ts.map +0 -1
  67. package/lib/mark/link.d.ts.map +0 -1
  68. package/lib/mark/strong.d.ts.map +0 -1
  69. package/lib/node/blockquote.d.ts.map +0 -1
  70. package/lib/node/bullet-list.d.ts.map +0 -1
  71. package/lib/node/code-fence.d.ts.map +0 -1
  72. package/lib/node/doc.d.ts.map +0 -1
  73. package/lib/node/hardbreak.d.ts.map +0 -1
  74. package/lib/node/heading.d.ts.map +0 -1
  75. package/lib/node/hr.d.ts.map +0 -1
  76. package/lib/node/image.d.ts.map +0 -1
  77. package/lib/node/index.d.ts.map +0 -1
  78. package/lib/node/list-item.d.ts.map +0 -1
  79. package/lib/node/ordered-list.d.ts.map +0 -1
  80. package/lib/node/paragraph.d.ts.map +0 -1
  81. package/lib/node/text.d.ts.map +0 -1
  82. package/lib/plugin/filter-html.d.ts.map +0 -1
  83. package/lib/plugin/index.d.ts +0 -2
  84. package/lib/plugin/index.d.ts.map +0 -1
  85. package/lib/supported-keys.d.ts.map +0 -1
package/lib/index.d.ts CHANGED
@@ -1,34 +1 @@
1
- import { AtomList } from '@milkdown/utils';
2
- import { commonmarkPlugins } from './plugin';
3
- export * from './mark';
4
- export * from './node';
5
- export * from './supported-keys';
6
- export declare const commonmarkNodes: AtomList<(import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<"CodeFence", {
7
- languageList?: string[] | undefined;
8
- }>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<string, import("./node").ImageOptions>> & import("@milkdown/core").MilkdownPlugin)>;
9
- export { commonmarkPlugins };
10
- export declare const commonmark: AtomList<(import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<"CodeFence", {
11
- languageList?: string[] | undefined;
12
- }>> & import("@milkdown/core").MilkdownPlugin) | (import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<string, import("./node").ImageOptions>> & import("@milkdown/core").MilkdownPlugin)>;
13
- export declare const commands: {
14
- readonly ToggleInlineCode: import("@milkdown/core").CmdKey<undefined>;
15
- readonly ToggleItalic: import("@milkdown/core").CmdKey<undefined>;
16
- readonly ToggleLink: import("@milkdown/core").CmdKey<string>;
17
- readonly ToggleBold: import("@milkdown/core").CmdKey<undefined>;
18
- readonly ModifyLink: import("@milkdown/core").CmdKey<string>;
19
- readonly ModifyImage: import("@milkdown/core").CmdKey<string>;
20
- readonly WrapInBlockquote: import("@milkdown/core").CmdKey<undefined>;
21
- readonly WrapInBulletList: import("@milkdown/core").CmdKey<undefined>;
22
- readonly WrapInOrderedList: import("@milkdown/core").CmdKey<undefined>;
23
- readonly TurnIntoCodeFence: import("@milkdown/core").CmdKey<undefined>;
24
- readonly TurnIntoHeading: import("@milkdown/core").CmdKey<number>;
25
- readonly TurnIntoText: import("@milkdown/core").CmdKey<undefined>;
26
- readonly InsertHardbreak: import("@milkdown/core").CmdKey<undefined>;
27
- readonly InsertHr: import("@milkdown/core").CmdKey<string>;
28
- readonly InsertImage: import("@milkdown/core").CmdKey<string>;
29
- readonly SplitListItem: import("@milkdown/core").CmdKey<undefined>;
30
- readonly SinkListItem: import("@milkdown/core").CmdKey<undefined>;
31
- readonly LiftListItem: import("@milkdown/core").CmdKey<undefined>;
32
- };
33
- export declare type Commands = typeof commands;
34
- //# sourceMappingURL=index.d.ts.map
1
+ export * from './src/index'
package/lib/index.es.js CHANGED
@@ -18,7 +18,6 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { createMark, createShortcut, createNode, createPlugin, AtomList } from "@milkdown/utils";
21
- import { css } from "@emotion/css";
22
21
  import { createCmdKey, createCmd, schemaCtx, themeToolCtx } from "@milkdown/core";
23
22
  import { markRule, toggleMark, TextSelection, InputRule, wrappingInputRule, wrapIn, textblockTypeInputRule, setBlockType, Plugin, PluginKey, ReplaceStep, AddMarkStep, Selection, findSelectedNodeOfType, splitListItem, sinkListItem, liftListItem } from "@milkdown/prose";
24
23
  import links from "remark-inline-links";
@@ -45,7 +44,7 @@ const SupportedKeys = {
45
44
  const id$a = "code_inline";
46
45
  const ToggleInlineCode = createCmdKey();
47
46
  const codeInline = createMark((utils) => {
48
- const style = utils.getStyle(({ palette, size, font }) => css`
47
+ const style = utils.getStyle(({ palette, size, font }, { css }) => css`
49
48
  background-color: ${palette("neutral")};
50
49
  color: ${palette("background")};
51
50
  border-radius: ${size.radius};
@@ -56,7 +55,9 @@ const codeInline = createMark((utils) => {
56
55
  return {
57
56
  id: id$a,
58
57
  schema: () => ({
59
- excludes: "_",
58
+ priority: 100,
59
+ code: true,
60
+ inclusive: false,
60
61
  parseDOM: [{ tag: "code" }],
61
62
  toDOM: (mark) => ["code", { class: utils.getClassName(mark.attrs, "code-inline", style) }],
62
63
  parseMarkdown: {
@@ -69,9 +70,8 @@ const codeInline = createMark((utils) => {
69
70
  },
70
71
  toMarkdown: {
71
72
  match: (mark) => mark.type.name === id$a,
72
- runner: (state, _, node) => {
73
- state.addNode("inlineCode", void 0, node.text || "");
74
- return true;
73
+ runner: (state, mark, node) => {
74
+ state.withMark(mark, "inlineCode", node.text || "");
75
75
  }
76
76
  }
77
77
  }),
@@ -121,7 +121,7 @@ const ToggleLink = createCmdKey();
121
121
  const ModifyLink = createCmdKey();
122
122
  const id$8 = "link";
123
123
  const link = createMark((utils) => {
124
- const style = utils.getStyle((themeTool) => {
124
+ const style = utils.getStyle((themeTool, { css }) => {
125
125
  const lineColor = themeTool.palette("line");
126
126
  return css`
127
127
  color: ${themeTool.palette("secondary")};
@@ -220,7 +220,7 @@ const link = createMark((utils) => {
220
220
  const id$7 = "strong";
221
221
  const ToggleBold = createCmdKey();
222
222
  const strong = createMark((utils) => {
223
- const style = utils.getStyle(() => css`
223
+ const style = utils.getStyle((_, { css }) => css`
224
224
  font-weight: 600;
225
225
  `);
226
226
  return {
@@ -261,7 +261,7 @@ const marks = [codeInline(), em(), strong(), link()];
261
261
  const id$6 = "blockquote";
262
262
  const WrapInBlockquote = createCmdKey();
263
263
  const blockquote = createNode((utils) => {
264
- const style = utils.getStyle((themeTool) => css`
264
+ const style = utils.getStyle((themeTool, { css }) => css`
265
265
  padding-left: 1.875rem;
266
266
  line-height: 1.75rem;
267
267
  border-left: 4px solid ${themeTool.palette("primary")};
@@ -326,7 +326,7 @@ const bulletList = createNode((utils) => {
326
326
  inputRules: (nodeType) => [wrappingInputRule(/^\s*([-+*])\s$/, nodeType)],
327
327
  commands: (nodeType) => [createCmd(WrapInBulletList, () => wrapIn(nodeType))],
328
328
  shortcuts: {
329
- [SupportedKeys.BulletList]: createShortcut(WrapInBulletList, "Mod-Shift-8")
329
+ [SupportedKeys.BulletList]: createShortcut(WrapInBulletList, "Mod-Alt-8")
330
330
  }
331
331
  };
332
332
  });
@@ -353,7 +353,7 @@ const tildeInputRegex = /^~~~(?<language>[a-z]*)?[\s\n]$/;
353
353
  const TurnIntoCodeFence = createCmdKey();
354
354
  const id$5 = "fence";
355
355
  const codeFence = createNode((utils, options) => {
356
- const style = utils.getStyle(({ palette, mixin, size, font }) => {
356
+ const style = utils.getStyle(({ palette, mixin, size, font }, { css }) => {
357
357
  const { shadow, scrollbar, border } = mixin;
358
358
  const { lineWidth, radius } = size;
359
359
  return css`
@@ -489,12 +489,12 @@ const codeFence = createNode((utils, options) => {
489
489
  ],
490
490
  toDOM: (node) => {
491
491
  return [
492
- "div",
492
+ "pre",
493
493
  {
494
494
  "data-language": node.attrs.language,
495
495
  class: utils.getClassName(node.attrs, "code-fence", style)
496
496
  },
497
- ["pre", ["code", { spellCheck: "false" }, 0]]
497
+ ["code", { spellCheck: "false" }, 0]
498
498
  ];
499
499
  },
500
500
  parseMarkdown: {
@@ -710,27 +710,42 @@ const hardbreak = createNode((utils) => {
710
710
  });
711
711
  const headingIndex = Array(6).fill(0).map((_, i) => i + 1);
712
712
  const TurnIntoHeading = createCmdKey();
713
- const heading = createNode((utils, options) => {
713
+ const headingPluginKey = new PluginKey("MILKDOWN_PLUGIN_ID");
714
+ const heading = createNode((utils) => {
714
715
  const id2 = "heading";
715
- const headingMap = {
716
- 1: css`
717
- font-size: 3rem;
718
- line-height: 3.5rem;
719
- `,
720
- 2: css`
721
- font-size: 2.125rem;
722
- line-height: 2.25rem;
723
- `,
724
- 3: css`
725
- font-size: 1.5rem;
726
- line-height: 1.5rem;
727
- `
728
- };
729
- const style = (level) => (options == null ? void 0 : options.headless) ? null : css`
730
- ${headingMap[level] || ""}
731
- margin: 2.5rem 0 !important;
732
- font-weight: 400;
733
- `;
716
+ const style = (level) => utils.getStyle((_, { css }) => {
717
+ const headingMap = {
718
+ 1: css`
719
+ font-size: 3rem;
720
+ line-height: 3.5rem;
721
+ `,
722
+ 2: css`
723
+ font-size: 2.5rem;
724
+ line-height: 3rem;
725
+ `,
726
+ 3: css`
727
+ font-size: 2.125rem;
728
+ line-height: 2.25rem;
729
+ `,
730
+ 4: css`
731
+ font-size: 1.75rem;
732
+ line-height: 2rem;
733
+ `,
734
+ 5: css`
735
+ font-size: 1.5rem;
736
+ line-height: 1.5rem;
737
+ `,
738
+ 6: css`
739
+ font-size: 1.25rem;
740
+ line-height: 1.25rem;
741
+ `
742
+ };
743
+ return css`
744
+ ${headingMap[level] || ""}
745
+ margin: 2.5rem 0 !important;
746
+ font-weight: 400;
747
+ `;
748
+ });
734
749
  return {
735
750
  id: id2,
736
751
  schema: () => ({
@@ -738,15 +753,27 @@ const heading = createNode((utils, options) => {
738
753
  group: "block",
739
754
  defining: true,
740
755
  attrs: {
756
+ id: {
757
+ default: ""
758
+ },
741
759
  level: {
742
760
  default: 1
743
761
  }
744
762
  },
745
- parseDOM: headingIndex.map((x) => ({ tag: `h${x}`, attrs: { level: x } })),
763
+ parseDOM: headingIndex.map((x) => ({
764
+ tag: `h${x}`,
765
+ getAttrs: (node) => {
766
+ if (!(node instanceof HTMLElement)) {
767
+ throw new Error();
768
+ }
769
+ return { level: x, id: node.id };
770
+ }
771
+ })),
746
772
  toDOM: (node) => {
747
773
  return [
748
774
  `h${node.attrs.level}`,
749
775
  {
776
+ id: node.attrs.id || node.textContent.split(" ").join("-").toLocaleLowerCase(),
750
777
  class: utils.getClassName(node.attrs, `heading h${node.attrs.level}`, style(node.attrs.level))
751
778
  },
752
779
  0
@@ -781,13 +808,34 @@ const heading = createNode((utils, options) => {
781
808
  [SupportedKeys.H4]: createShortcut(TurnIntoHeading, "Mod-Alt-4", 4),
782
809
  [SupportedKeys.H5]: createShortcut(TurnIntoHeading, "Mod-Alt-5", 5),
783
810
  [SupportedKeys.H6]: createShortcut(TurnIntoHeading, "Mod-Alt-6", 6)
784
- }
811
+ },
812
+ prosePlugins: (type) => [
813
+ new Plugin({
814
+ key: headingPluginKey,
815
+ appendTransaction: (transactions, _, nextState) => {
816
+ const tr = nextState.tr;
817
+ let modified = false;
818
+ if (transactions.some((transaction) => transaction.docChanged)) {
819
+ nextState.doc.descendants((node, pos) => {
820
+ if (node.type === type) {
821
+ const attrs = node.attrs;
822
+ tr.setNodeMarkup(pos, void 0, __spreadProps(__spreadValues({}, attrs), {
823
+ id: node.textContent.split(" ").join("-").toLocaleLowerCase()
824
+ }));
825
+ modified = true;
826
+ }
827
+ });
828
+ }
829
+ return modified ? tr : null;
830
+ }
831
+ })
832
+ ]
785
833
  };
786
834
  });
787
835
  const id$4 = "hr";
788
836
  const InsertHr = createCmdKey();
789
837
  const hr = createNode((utils) => {
790
- const style = utils.getStyle((themeTool) => css`
838
+ const style = utils.getStyle((themeTool, { css }) => css`
791
839
  height: ${themeTool.size.lineWidth};
792
840
  background-color: ${themeTool.palette("line")};
793
841
  border-width: 0;
@@ -852,7 +900,7 @@ const image = createNode((utils, options) => {
852
900
  failed: "Image loads failed"
853
901
  }, (_a = options == null ? void 0 : options.placeholder) != null ? _a : {});
854
902
  const isBlock = (_b = options == null ? void 0 : options.isBlock) != null ? _b : false;
855
- const containerStyle = utils.getStyle((themeTool) => css`
903
+ const containerStyle = utils.getStyle((themeTool, { css }) => css`
856
904
  display: inline-block;
857
905
  position: relative;
858
906
  text-align: center;
@@ -944,7 +992,7 @@ const image = createNode((utils, options) => {
944
992
  }
945
993
  }
946
994
  `);
947
- const style = utils.getStyle(() => css`
995
+ const style = utils.getStyle((_, { css }) => css`
948
996
  display: inline-block;
949
997
  margin: 0 auto;
950
998
  object-fit: contain;
@@ -1076,8 +1124,11 @@ const image = createNode((utils, options) => {
1076
1124
  const img = document.createElement("img");
1077
1125
  img.src = src2;
1078
1126
  img.onerror = () => {
1127
+ const pos = getPos();
1128
+ if (!pos)
1129
+ return;
1079
1130
  const { tr } = view.state;
1080
- const _tr = tr.setNodeMarkup(getPos(), nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1131
+ const _tr = tr.setNodeMarkup(pos, nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1081
1132
  src: src2,
1082
1133
  loading: false,
1083
1134
  failed: true
@@ -1086,7 +1137,10 @@ const image = createNode((utils, options) => {
1086
1137
  };
1087
1138
  img.onload = () => {
1088
1139
  const { tr } = view.state;
1089
- const _tr = tr.setNodeMarkup(getPos(), nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1140
+ const pos = getPos();
1141
+ if (!pos)
1142
+ return;
1143
+ const _tr = tr.setNodeMarkup(pos, nodeType, __spreadProps(__spreadValues({}, node.attrs), {
1090
1144
  width: img.width,
1091
1145
  src: src2,
1092
1146
  loading: false,
@@ -1153,7 +1207,7 @@ const SplitListItem = createCmdKey();
1153
1207
  const SinkListItem = createCmdKey();
1154
1208
  const LiftListItem = createCmdKey();
1155
1209
  const listItem = createNode((utils) => {
1156
- const style = utils.getStyle((themeTool) => css`
1210
+ const style = utils.getStyle((themeTool, { css }) => css`
1157
1211
  &,
1158
1212
  & > * {
1159
1213
  margin: 0.5rem 0;
@@ -1254,17 +1308,19 @@ const orderedList = createNode((utils) => ({
1254
1308
  ],
1255
1309
  commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
1256
1310
  shortcuts: {
1257
- [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Shift-7")
1311
+ [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Alt-7")
1258
1312
  }
1259
1313
  }));
1260
1314
  const TurnIntoText = createCmdKey();
1261
1315
  const id = "paragraph";
1262
- const paragraph = createNode((utils, options) => {
1263
- const style = (options == null ? void 0 : options.headless) ? null : css`
1264
- font-size: 1rem;
1265
- line-height: 1.5;
1266
- letter-spacing: 0.5px;
1267
- `;
1316
+ const paragraph = createNode((utils) => {
1317
+ const style = utils.getStyle((_, { css }) => {
1318
+ return css`
1319
+ font-size: 1rem;
1320
+ line-height: 1.5;
1321
+ letter-spacing: 0.5px;
1322
+ `;
1323
+ });
1268
1324
  return {
1269
1325
  id,
1270
1326
  schema: () => ({
@@ -1389,5 +1445,5 @@ const commands = {
1389
1445
  SinkListItem,
1390
1446
  LiftListItem
1391
1447
  };
1392
- export { InsertHardbreak, InsertHr, InsertImage, LiftListItem, ModifyImage, ModifyLink, SinkListItem, SplitListItem, SupportedKeys, ToggleBold, ToggleInlineCode, ToggleItalic, ToggleLink, TurnIntoCodeFence, TurnIntoHeading, TurnIntoText, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, backtickInputRegex, blockquote, bulletList, codeFence, codeInline, commands, commonmark, commonmarkNodes, commonmarkPlugins, doc, em, hardbreak, heading, hr, image, link, listItem, marks, nodes, orderedList, paragraph, strong, text, tildeInputRegex };
1448
+ export { InsertHardbreak, InsertHr, InsertImage, LiftListItem, ModifyImage, ModifyLink, SinkListItem, SplitListItem, SupportedKeys, ToggleBold, ToggleInlineCode, ToggleItalic, ToggleLink, TurnIntoCodeFence, TurnIntoHeading, TurnIntoText, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, backtickInputRegex, blockquote, bulletList, codeFence, codeInline, commands, commonmark, commonmarkNodes, commonmarkPlugins, doc, em, hardbreak, heading, headingPluginKey, hr, image, link, listItem, marks, nodes, orderedList, paragraph, strong, text, tildeInputRegex };
1393
1449
  //# sourceMappingURL=index.es.js.map