@milkdown/preset-commonmark 5.2.1 → 5.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 (87) hide show
  1. package/lib/index.d.ts +1 -34
  2. package/lib/index.es.js +73 -53
  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 +1 -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 +13 -25
  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 +7 -6
  56. package/src/node/heading.ts +36 -26
  57. package/src/node/hr.ts +1 -2
  58. package/src/node/image.ts +10 -7
  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.cjs.js +0 -261
  63. package/lib/index.cjs.js.map +0 -1
  64. package/lib/index.d.ts.map +0 -1
  65. package/lib/mark/code-inline.d.ts.map +0 -1
  66. package/lib/mark/em.d.ts.map +0 -1
  67. package/lib/mark/index.d.ts +0 -6
  68. package/lib/mark/index.d.ts.map +0 -1
  69. package/lib/mark/link.d.ts.map +0 -1
  70. package/lib/mark/strong.d.ts.map +0 -1
  71. package/lib/node/blockquote.d.ts.map +0 -1
  72. package/lib/node/bullet-list.d.ts.map +0 -1
  73. package/lib/node/code-fence.d.ts.map +0 -1
  74. package/lib/node/doc.d.ts.map +0 -1
  75. package/lib/node/hardbreak.d.ts.map +0 -1
  76. package/lib/node/heading.d.ts.map +0 -1
  77. package/lib/node/hr.d.ts.map +0 -1
  78. package/lib/node/image.d.ts.map +0 -1
  79. package/lib/node/index.d.ts.map +0 -1
  80. package/lib/node/list-item.d.ts.map +0 -1
  81. package/lib/node/ordered-list.d.ts.map +0 -1
  82. package/lib/node/paragraph.d.ts.map +0 -1
  83. package/lib/node/text.d.ts.map +0 -1
  84. package/lib/plugin/filter-html.d.ts.map +0 -1
  85. package/lib/plugin/index.d.ts +0 -2
  86. package/lib/plugin/index.d.ts.map +0 -1
  87. 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`
@@ -388,7 +388,7 @@ const codeFence = createNode((utils, options) => {
388
388
  height: 2.625rem;
389
389
  align-items: center;
390
390
 
391
- & > *:last-child {
391
+ & > .icon {
392
392
  width: 2.625rem;
393
393
  height: 100%;
394
394
  display: flex;
@@ -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: {
@@ -547,7 +547,9 @@ const codeFence = createNode((utils, options) => {
547
547
  valueWrapper.className = "code-fence_value";
548
548
  const value = document.createElement("span");
549
549
  valueWrapper.appendChild(value);
550
- valueWrapper.appendChild(ctx.get(themeToolCtx).slots.icon("downArrow"));
550
+ if (view.editable) {
551
+ valueWrapper.appendChild(ctx.get(themeToolCtx).slots.icon("downArrow"));
552
+ }
551
553
  select.className = "code-fence_select";
552
554
  select.addEventListener("mousedown", (e) => {
553
555
  e.preventDefault();
@@ -708,38 +710,50 @@ const hardbreak = createNode((utils) => {
708
710
  });
709
711
  const headingIndex = Array(6).fill(0).map((_, i) => i + 1);
710
712
  const TurnIntoHeading = createCmdKey();
711
- const heading = createNode((utils, options) => {
713
+ const heading = createNode((utils) => {
712
714
  const id2 = "heading";
713
- const headingMap = {
714
- 1: css`
715
- font-size: 3rem;
716
- line-height: 3.5rem;
717
- `,
718
- 2: css`
719
- font-size: 2.125rem;
720
- line-height: 2.25rem;
721
- `,
722
- 3: css`
723
- font-size: 1.5rem;
724
- line-height: 1.5rem;
725
- `
726
- };
727
- const style = (level) => (options == null ? void 0 : options.headless) ? null : css`
728
- ${headingMap[level] || ""}
729
- margin: 2.5rem 0 !important;
730
- font-weight: 400;
731
- `;
715
+ const style = (level) => utils.getStyle((_, { css }) => {
716
+ const headingMap = {
717
+ 1: css`
718
+ font-size: 3rem;
719
+ line-height: 3.5rem;
720
+ `,
721
+ 2: css`
722
+ font-size: 2.5rem;
723
+ line-height: 3rem;
724
+ `,
725
+ 3: css`
726
+ font-size: 2.125rem;
727
+ line-height: 2.25rem;
728
+ `,
729
+ 4: css`
730
+ font-size: 1.75rem;
731
+ line-height: 2rem;
732
+ `,
733
+ 5: css`
734
+ font-size: 1.5rem;
735
+ line-height: 1.5rem;
736
+ `,
737
+ 6: css`
738
+ font-size: 1.25rem;
739
+ line-height: 1.25rem;
740
+ `
741
+ };
742
+ return css`
743
+ ${headingMap[level] || ""}
744
+ margin: 2.5rem 0 !important;
745
+ font-weight: 400;
746
+ `;
747
+ });
732
748
  return {
733
749
  id: id2,
734
750
  schema: () => ({
735
751
  content: "inline*",
736
752
  group: "block",
753
+ defining: true,
737
754
  attrs: {
738
755
  level: {
739
756
  default: 1
740
- },
741
- id: {
742
- default: ""
743
757
  }
744
758
  },
745
759
  parseDOM: headingIndex.map((x) => ({ tag: `h${x}`, attrs: { level: x } })),
@@ -787,7 +801,7 @@ const heading = createNode((utils, options) => {
787
801
  const id$4 = "hr";
788
802
  const InsertHr = createCmdKey();
789
803
  const hr = createNode((utils) => {
790
- const style = utils.getStyle((themeTool) => css`
804
+ const style = utils.getStyle((themeTool, { css }) => css`
791
805
  height: ${themeTool.size.lineWidth};
792
806
  background-color: ${themeTool.palette("line")};
793
807
  border-width: 0;
@@ -852,7 +866,7 @@ const image = createNode((utils, options) => {
852
866
  failed: "Image loads failed"
853
867
  }, (_a = options == null ? void 0 : options.placeholder) != null ? _a : {});
854
868
  const isBlock = (_b = options == null ? void 0 : options.isBlock) != null ? _b : false;
855
- const containerStyle = utils.getStyle((themeTool) => css`
869
+ const containerStyle = utils.getStyle((themeTool, { css }) => css`
856
870
  display: inline-block;
857
871
  position: relative;
858
872
  text-align: center;
@@ -944,7 +958,7 @@ const image = createNode((utils, options) => {
944
958
  }
945
959
  }
946
960
  `);
947
- const style = utils.getStyle(() => css`
961
+ const style = utils.getStyle((_, { css }) => css`
948
962
  display: inline-block;
949
963
  margin: 0 auto;
950
964
  object-fit: contain;
@@ -970,7 +984,7 @@ const image = createNode((utils, options) => {
970
984
  title: { default: null },
971
985
  failed: { default: false },
972
986
  loading: { default: true },
973
- width: { default: 0 }
987
+ width: { default: null }
974
988
  },
975
989
  parseDOM: [
976
990
  {
@@ -985,7 +999,7 @@ const image = createNode((utils, options) => {
985
999
  src: dom.getAttribute("src") || "",
986
1000
  alt: dom.getAttribute("alt"),
987
1001
  title: dom.getAttribute("title") || dom.getAttribute("alt"),
988
- width: dom.getAttribute("width") || 0
1002
+ width: dom.getAttribute("width")
989
1003
  };
990
1004
  }
991
1005
  }
@@ -1099,7 +1113,9 @@ const image = createNode((utils, options) => {
1099
1113
  content.src = src;
1100
1114
  content.title = title || alt;
1101
1115
  content.alt = alt;
1102
- content.width = width;
1116
+ if (width) {
1117
+ content.width = width;
1118
+ }
1103
1119
  if (src.length === 0) {
1104
1120
  container.classList.add("system", "empty");
1105
1121
  setIcon("image");
@@ -1115,7 +1131,9 @@ const image = createNode((utils, options) => {
1115
1131
  content.src = src2;
1116
1132
  content.alt = alt2;
1117
1133
  content.title = title2 || alt2;
1118
- content.width = width2;
1134
+ if (width2) {
1135
+ content.width = width2;
1136
+ }
1119
1137
  if (loading2) {
1120
1138
  loadImage(src2);
1121
1139
  return true;
@@ -1149,7 +1167,7 @@ const SplitListItem = createCmdKey();
1149
1167
  const SinkListItem = createCmdKey();
1150
1168
  const LiftListItem = createCmdKey();
1151
1169
  const listItem = createNode((utils) => {
1152
- const style = utils.getStyle((themeTool) => css`
1170
+ const style = utils.getStyle((themeTool, { css }) => css`
1153
1171
  &,
1154
1172
  & > * {
1155
1173
  margin: 0.5rem 0;
@@ -1250,17 +1268,19 @@ const orderedList = createNode((utils) => ({
1250
1268
  ],
1251
1269
  commands: (nodeType) => [createCmd(WrapInOrderedList, () => wrapIn(nodeType))],
1252
1270
  shortcuts: {
1253
- [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Shift-7")
1271
+ [SupportedKeys.OrderedList]: createShortcut(WrapInOrderedList, "Mod-Alt-7")
1254
1272
  }
1255
1273
  }));
1256
1274
  const TurnIntoText = createCmdKey();
1257
1275
  const id = "paragraph";
1258
- const paragraph = createNode((utils, options) => {
1259
- const style = (options == null ? void 0 : options.headless) ? null : css`
1260
- font-size: 1rem;
1261
- line-height: 1.5;
1262
- letter-spacing: 0.5px;
1263
- `;
1276
+ const paragraph = createNode((utils) => {
1277
+ const style = utils.getStyle((_, { css }) => {
1278
+ return css`
1279
+ font-size: 1rem;
1280
+ line-height: 1.5;
1281
+ letter-spacing: 0.5px;
1282
+ `;
1283
+ });
1264
1284
  return {
1265
1285
  id,
1266
1286
  schema: () => ({