@doist/typist 1.0.16 → 1.0.18

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [1.0.18](https://github.com/Doist/typist/compare/v1.0.17...v1.0.18) (2023-02-23)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **deps:** Migrate ProseMirror dependencies to `@tiptap/pm` package ([#151](https://github.com/Doist/typist/issues/151)) ([d2a8eae](https://github.com/Doist/typist/commit/d2a8eaefa0dc57579aa97f170e37dae17c77590d))
6
+
7
+ ## [1.0.17](https://github.com/Doist/typist/compare/v1.0.16...v1.0.17) (2023-02-23)
8
+
9
+ ### Bug Fixes
10
+
11
+ - **markdown-serializer:** Override Turndown escaping behaviour with custom rules ([#102](https://github.com/Doist/typist/issues/102)) ([6950afb](https://github.com/Doist/typist/commit/6950afb61bd22a3b029e7f688f5e704402290e5a))
12
+
1
13
  ## [1.0.16](https://github.com/Doist/typist/compare/v1.0.15...v1.0.16) (2023-02-22)
2
14
 
3
15
  ### Bug Fixes
@@ -2,5 +2,11 @@
2
2
  * A common regex for all line termination conventions.
3
3
  */
4
4
  declare const REGEX_LINE_BREAKS: RegExp;
5
- export { REGEX_LINE_BREAKS };
5
+ /**
6
+ * A regex for standard punctuation characters for US-ASCII plus unicode punctuation.
7
+ *
8
+ * @see https://stackoverflow.com/a/25575009
9
+ */
10
+ declare const REGEX_PUNCTUATION: RegExp;
11
+ export { REGEX_LINE_BREAKS, REGEX_PUNCTUATION };
6
12
  //# sourceMappingURL=regular-expressions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regular-expressions.d.ts","sourceRoot":"","sources":["../../src/constants/regular-expressions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,QAAA,MAAM,iBAAiB,QAAoB,CAAA;AAE3C,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
1
+ {"version":3,"file":"regular-expressions.d.ts","sourceRoot":"","sources":["../../src/constants/regular-expressions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,QAAA,MAAM,iBAAiB,QAAoB,CAAA;AAE3C;;;;GAIG;AACH,QAAA,MAAM,iBAAiB,QAAoE,CAAA;AAE3F,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,CAAA"}
@@ -2,4 +2,10 @@
2
2
  * A common regex for all line termination conventions.
3
3
  */
4
4
  const REGEX_LINE_BREAKS = /(?:\r\n|\r|\n)/g;
5
- export { REGEX_LINE_BREAKS };
5
+ /**
6
+ * A regex for standard punctuation characters for US-ASCII plus unicode punctuation.
7
+ *
8
+ * @see https://stackoverflow.com/a/25575009
9
+ */
10
+ const REGEX_PUNCTUATION = /[\u2000-\u206f\u2e00-\u2e7f'!"#$%&()*+,\-./:;<=>?@\\[\]^_`{|}~]/;
11
+ export { REGEX_LINE_BREAKS, REGEX_PUNCTUATION };
package/dist/index.d.ts CHANGED
@@ -15,12 +15,12 @@ export type { AnyConfig, Editor as CoreEditor, EditorEvents, MarkRange, Range }
15
15
  export { combineTransactionSteps, defaultBlockAt, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarksBetween, getMarkType, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, mergeAttributes, posToDOMRect, } from '@tiptap/core';
16
16
  export { Extension, Mark } from '@tiptap/core';
17
17
  export * from '@tiptap/extension-character-count';
18
+ export { DOMParser, Fragment, Node as ProseMirrorNode } from '@tiptap/pm/model';
19
+ export type { Selection, Transaction } from '@tiptap/pm/state';
20
+ export { EditorState, Plugin, PluginKey } from '@tiptap/pm/state';
21
+ export type { EditorView } from '@tiptap/pm/view';
18
22
  export type { Editor, NodeViewProps, ReactRendererOptions } from '@tiptap/react';
19
23
  export { NodeViewWrapper, ReactRenderer } from '@tiptap/react';
20
24
  export type { SuggestionKeyDownProps, SuggestionOptions as TiptapSuggestionOptions, } from '@tiptap/suggestion';
21
25
  export { Suggestion } from '@tiptap/suggestion';
22
- export { DOMParser, Fragment, Node as ProseMirrorNode } from 'prosemirror-model';
23
- export type { Selection, Transaction } from 'prosemirror-state';
24
- export { EditorState, Plugin, PluginKey } from 'prosemirror-state';
25
- export type { EditorView } from 'prosemirror-view';
26
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,WAAW,GACd,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAA;AAChF,cAAc,oEAAoE,CAAA;AAClF,cAAc,0EAA0E,CAAA;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AACrE,YAAY,EACR,uBAAuB,EACvB,oBAAoB,GACvB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAA;AAClE,YAAY,EACR,yBAAyB,EACzB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,GACpB,MAAM,yCAAyC,CAAA;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA;AACnF,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAC1E,YAAY,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,EACR,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,YAAY,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC9C,cAAc,mCAAmC,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAC/E,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACjE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC9D,YAAY,EACR,sBAAsB,EACtB,iBAAiB,IAAI,uBAAuB,GAC/C,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA"}
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ export { createMarkdownSerializer } from './serializers/markdown/markdown';
11
11
  export { combineTransactionSteps, defaultBlockAt, findChildren, findChildrenInRange, findParentNode, findParentNodeClosestToPos, generateHTML, generateJSON, generateText, getAttributes, getChangedRanges, getDebugJSON, getExtensionField, getHTMLFromFragment, getMarkAttributes, getMarkRange, getMarksBetween, getMarkType, getNodeAttributes, getNodeType, getSchema, getText, getTextBetween, isActive, isList, isMarkActive, isNodeActive, isNodeEmpty, isNodeSelection, isTextSelection, mergeAttributes, posToDOMRect, } from '@tiptap/core';
12
12
  export { Extension, Mark } from '@tiptap/core';
13
13
  export * from '@tiptap/extension-character-count';
14
+ export { DOMParser, Fragment, Node as ProseMirrorNode } from '@tiptap/pm/model';
15
+ export { EditorState, Plugin, PluginKey } from '@tiptap/pm/state';
14
16
  export { NodeViewWrapper, ReactRenderer } from '@tiptap/react';
15
17
  export { Suggestion } from '@tiptap/suggestion';
16
- export { DOMParser, Fragment, Node as ProseMirrorNode } from 'prosemirror-model';
17
- export { EditorState, Plugin, PluginKey } from 'prosemirror-state';
@@ -1,13 +1,4 @@
1
1
  import type { Schema } from 'prosemirror-model';
2
- /**
3
- * The options that the `createMarkdownSerializer` function accepts.
4
- */
5
- type MarkdownSerializerOptions = {
6
- /**
7
- * Disables markdown escaping.
8
- */
9
- escape?: false;
10
- };
11
2
  /**
12
3
  * The return type for the `createMarkdownSerializer` function.
13
4
  */
@@ -38,7 +29,7 @@ declare const BULLET_LIST_MARKER = "-";
38
29
  *
39
30
  * @returns A normalized object for the Markdown serializer.
40
31
  */
41
- declare function createMarkdownSerializer(schema: Schema, options?: MarkdownSerializerOptions): MarkdownSerializerReturnType;
32
+ declare function createMarkdownSerializer(schema: Schema): MarkdownSerializerReturnType;
42
33
  export { BULLET_LIST_MARKER, createMarkdownSerializer };
43
34
  export type { MarkdownSerializerReturnType };
44
35
  //# sourceMappingURL=markdown.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/serializers/markdown/markdown.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;GAEG;AACH,KAAK,yBAAyB,GAAG;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;CACjB,CAAA;AAED;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAChC;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACtC,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,kBAAkB,MAAM,CAAA;AA8C9B;;;;;;;;;;;;GAYG;AACH,iBAAS,wBAAwB,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,yBAAyB,GACpC,4BAA4B,CA4E9B;AAED,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,CAAA;AAEvD,YAAY,EAAE,4BAA4B,EAAE,CAAA"}
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/serializers/markdown/markdown.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C;;GAEG;AACH,KAAK,4BAA4B,GAAG;IAChC;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACtC,CAAA;AAED;;GAEG;AACH,QAAA,MAAM,kBAAkB,MAAM,CAAA;AA8C9B;;;;;;;;;;;;GAYG;AACH,iBAAS,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,4BAA4B,CAiG9E;AAED,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,CAAA;AAEvD,YAAY,EAAE,4BAA4B,EAAE,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import Turndown from 'turndown';
2
+ import { REGEX_PUNCTUATION } from '../../constants/regular-expressions';
2
3
  import { isPlainTextDocument } from '../../helpers/schema';
3
4
  import { image } from './plugins/image';
4
5
  import { listItem } from './plugins/list-item';
@@ -61,19 +62,37 @@ const INITIAL_TURNDOWN_OPTIONS = {
61
62
  *
62
63
  * @returns A normalized object for the Markdown serializer.
63
64
  */
64
- function createMarkdownSerializer(schema, options) {
65
+ function createMarkdownSerializer(schema) {
65
66
  // Initialize Turndown with custom options
66
67
  const turndown = new Turndown(INITIAL_TURNDOWN_OPTIONS);
67
- // Turndown was built to convert HTML into Markdown, expecting the input to be standards
68
- // compliant HTML. As such, it collapses all whitespace by default, and there's
69
- // currently no way to opt-out of this behavior. However, for plain-text editors, we
70
- // need to preserve Markdown whitespace (otherwise we lose syntax like nested lists) by
71
- // replacing all instances of the space character (but only if it's preceded by another
72
- // space character) by the non-breaking space character, and after processing the input
73
- // with Turndown, we restore the original space character.
74
- if (isPlainTextDocument(schema) || options?.escape === false) {
68
+ // Turndown ensures Markdown characters are escaped (i.e. `\`) by default, so they are not
69
+ // interpreted as Markdown when the output is compiled back to HTML. However, for plain-text
70
+ // editors, we need to override the `escape` function to return the input as-is (effectively
71
+ // disabling the escaping behaviour), so that all characters are interpreted as Markdown.
72
+ if (isPlainTextDocument(schema)) {
75
73
  turndown.escape = (str) => str;
76
74
  }
75
+ // As for rich-text editors, we need to override the built-in escaping behaviour with a custom
76
+ // implementation to suit our requirements. Please note that the `escape` function takes the
77
+ // text content of each HTML element, with the exception of code elements, so we can be sure
78
+ // that the escaping behaviour will only touch relevant Markdown characters.
79
+ else {
80
+ turndown.escape = (str) => {
81
+ return (str
82
+ // Escape all backslash characters that precedes any punctuation characters,
83
+ // otherwise the backslash character itself will be interpreted as escaping the
84
+ // character that comes after it (which is not the intent). It's important that
85
+ // this escape rule is executed before all other escape rules, otherwise we
86
+ // could be double escaping some backslash characters.
87
+ .replace(new RegExp(`(\\\\${REGEX_PUNCTUATION.source})`, 'g'), '\\$1')
88
+ // Although the CommonMark specification allows for bulleted or ordered lists
89
+ // inside other bulleted or ordered lists (i.e. `- 1. - 1. Item`), the markup
90
+ // generated by Markdown compilers is not supported by Tiptap, and we need to
91
+ // make sure that text context that matches the ordered list syntax is
92
+ // correctly escaped in order to be interpreted as text.
93
+ .replace(/^(\d+)\.(\s.+|$)/, '$1\\.$2'));
94
+ };
95
+ }
77
96
  // Overwrite some built-in rules for handling of special behaviours
78
97
  // (see documentation for each extension for more details)
79
98
  turndown.use(paragraph(schema.nodes.paragraph, isPlainTextDocument(schema)));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@doist/typist",
3
3
  "description": "The mighty Tiptap-based rich-text editor React component that powers Doist products.",
4
- "version": "1.0.16",
4
+ "version": "1.0.18",
5
5
  "license": "MIT",
6
6
  "homepage": "https://typist.doist.dev/",
7
7
  "repository": "https://github.com/Doist/typist",
@@ -72,27 +72,10 @@
72
72
  "@tiptap/extension-task-list": "2.0.0-beta.217",
73
73
  "@tiptap/extension-text": "2.0.0-beta.217",
74
74
  "@tiptap/extension-typography": "2.0.0-beta.217",
75
+ "@tiptap/pm": "2.0.0-beta.217",
75
76
  "@tiptap/react": "2.0.0-beta.217",
76
77
  "@tiptap/suggestion": "2.0.0-beta.217",
77
- "prosemirror-codemark": "0.4.2",
78
- "prosemirror-changeset": "2.2.0",
79
- "prosemirror-collab": "1.3.0",
80
- "prosemirror-commands": "1.5.0",
81
- "prosemirror-dropcursor": "1.5.0",
82
- "prosemirror-gapcursor": "1.3.1",
83
- "prosemirror-history": "1.3.0",
84
- "prosemirror-inputrules": "1.2.0",
85
- "prosemirror-keymap": "1.2.0",
86
- "prosemirror-markdown": "1.10.1",
87
- "prosemirror-menu": "1.2.1",
88
- "prosemirror-model": "1.18.3",
89
- "prosemirror-schema-basic": "1.2.0",
90
- "prosemirror-schema-list": "1.2.2",
91
- "prosemirror-state": "1.4.2",
92
- "prosemirror-tables": "1.3.0",
93
- "prosemirror-trailing-node": "2.0.2",
94
- "prosemirror-transform": "1.7.0",
95
- "prosemirror-view": "1.29.1"
78
+ "prosemirror-codemark": "0.4.2"
96
79
  },
97
80
  "devDependencies": {
98
81
  "@doist/eslint-config": "8.1.3",