@doist/typist 1.0.15 → 1.0.17
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 +12 -0
- package/dist/components/typist-editor.d.ts.map +1 -1
- package/dist/components/typist-editor.js +3 -4
- package/dist/constants/regular-expressions.d.ts +7 -1
- package/dist/constants/regular-expressions.d.ts.map +1 -1
- package/dist/constants/regular-expressions.js +7 -1
- package/dist/serializers/markdown/markdown.d.ts +1 -10
- package/dist/serializers/markdown/markdown.d.ts.map +1 -1
- package/dist/serializers/markdown/markdown.js +28 -9
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [1.0.17](https://github.com/Doist/typist/compare/v1.0.16...v1.0.17) (2023-02-23)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- **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))
|
|
6
|
+
|
|
7
|
+
## [1.0.16](https://github.com/Doist/typist/compare/v1.0.15...v1.0.16) (2023-02-22)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
- Replace usage of useEvent with useCallback ([#98](https://github.com/Doist/typist/issues/98)) ([3b175f7](https://github.com/Doist/typist/commit/3b175f77cf0fa638a8ad267959ab720d24815fdd))
|
|
12
|
+
|
|
1
13
|
## [1.0.15](https://github.com/Doist/typist/compare/v1.0.14...v1.0.15) (2023-02-14)
|
|
2
14
|
|
|
3
15
|
### Bug Fixes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typist-editor.d.ts","sourceRoot":"","sources":["../../src/components/typist-editor.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"typist-editor.d.ts","sourceRoot":"","sources":["../../src/components/typist-editor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CAAC,SAAS,CAAC,CAAA;IAE7C;;OAEG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAC,WAAW,CAAC,CAAA;CACpD,CAAA;AAED;;;GAGG;AACH,QAAA,MAAM,YAAY,+GAiNhB,CAAA;AAEF,OAAO,EAAE,YAAY,EAAE,CAAA;AAEvB,YAAY,EACR,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,WAAW,GACd,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useImperativeHandle, useMemo } from 'react';
|
|
3
|
-
import { useEvent } from 'react-use-event-hook';
|
|
2
|
+
import { forwardRef, useCallback, useImperativeHandle, useMemo } from 'react';
|
|
4
3
|
import { getSchema } from '@tiptap/core';
|
|
5
4
|
import { Placeholder } from '@tiptap/extension-placeholder';
|
|
6
5
|
import { EditorContent } from '@tiptap/react';
|
|
@@ -57,7 +56,7 @@ const TypistEditor = forwardRef(function TypistEditor({ autoFocus, className, co
|
|
|
57
56
|
...(ariaLabelledBy ? { 'aria-labelledby': ariaLabelledBy } : {}),
|
|
58
57
|
};
|
|
59
58
|
}, [ariaDescribedBy, ariaLabel, ariaLabelledBy, editable, schema]);
|
|
60
|
-
const handleCreate =
|
|
59
|
+
const handleCreate = useCallback(function handleCreate(props) {
|
|
61
60
|
const { view } = props.editor;
|
|
62
61
|
// Apply a selection to the document if one was given and `autoFocus` is `true`
|
|
63
62
|
if (autoFocus && contentSelection) {
|
|
@@ -87,7 +86,7 @@ const TypistEditor = forwardRef(function TypistEditor({ autoFocus, className, co
|
|
|
87
86
|
}
|
|
88
87
|
// Invoke the user `onCreate` handle after all internal initializations
|
|
89
88
|
onCreate?.(props);
|
|
90
|
-
});
|
|
89
|
+
}, [autoFocus, contentSelection, onCreate]);
|
|
91
90
|
const editor = useEditor({
|
|
92
91
|
autofocus: autoFocus ? 'end' : false,
|
|
93
92
|
content: htmlContent,
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 };
|
|
@@ -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
|
|
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":"
|
|
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
|
|
65
|
+
function createMarkdownSerializer(schema) {
|
|
65
66
|
// Initialize Turndown with custom options
|
|
66
67
|
const turndown = new Turndown(INITIAL_TURNDOWN_OPTIONS);
|
|
67
|
-
// Turndown
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
|
|
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.
|
|
4
|
+
"version": "1.0.17",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://typist.doist.dev/",
|
|
7
7
|
"repository": "https://github.com/Doist/typist",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"@doist/eslint-config": "8.1.3",
|
|
99
99
|
"@doist/prettier-config": "3.0.5",
|
|
100
100
|
"@doist/reactist": "17.10.1",
|
|
101
|
-
"@mdx-js/react": "2.
|
|
101
|
+
"@mdx-js/react": "2.3.0",
|
|
102
102
|
"@semantic-release/changelog": "6.0.2",
|
|
103
103
|
"@semantic-release/exec": "6.0.3",
|
|
104
104
|
"@semantic-release/git": "10.0.1",
|
|
@@ -114,32 +114,33 @@
|
|
|
114
114
|
"@types/jest": "29.4.0",
|
|
115
115
|
"@types/lodash-es": "4.17.6",
|
|
116
116
|
"@types/marked": "4.0.8",
|
|
117
|
-
"@types/react": "18.0.
|
|
118
|
-
"@types/react-dom": "18.0.
|
|
117
|
+
"@types/react": "18.0.28",
|
|
118
|
+
"@types/react-dom": "18.0.11",
|
|
119
119
|
"@types/react-syntax-highlighter": "15.5.6",
|
|
120
120
|
"@types/turndown": "5.0.1",
|
|
121
121
|
"boring-avatars": "1.7.0",
|
|
122
122
|
"classnames": "2.3.2",
|
|
123
123
|
"conventional-changelog-conventionalcommits": "5.0.0",
|
|
124
124
|
"emoji-regex": "10.2.1",
|
|
125
|
-
"eslint": "8.
|
|
125
|
+
"eslint": "8.34.0",
|
|
126
126
|
"eslint-formatter-codeframe": "7.32.1",
|
|
127
127
|
"eslint-import-resolver-typescript": "3.5.3",
|
|
128
128
|
"eslint-plugin-jest": "27.2.1",
|
|
129
129
|
"eslint-plugin-simple-import-sort": "8.0.0",
|
|
130
130
|
"eslint-plugin-unicorn": "45.0.2",
|
|
131
|
-
"github-markdown-css": "5.
|
|
131
|
+
"github-markdown-css": "5.2.0",
|
|
132
132
|
"husky": "8.0.3",
|
|
133
133
|
"ignore-sync": "6.0.2",
|
|
134
134
|
"is-ci": "3.0.1",
|
|
135
|
-
"jest": "29.4.
|
|
136
|
-
"jest-environment-jsdom": "29.4.
|
|
137
|
-
"lint-staged": "13.1.
|
|
135
|
+
"jest": "29.4.3",
|
|
136
|
+
"jest-environment-jsdom": "29.4.3",
|
|
137
|
+
"lint-staged": "13.1.2",
|
|
138
138
|
"npm-run-all": "4.1.5",
|
|
139
139
|
"prettier": "2.8.4",
|
|
140
140
|
"react-icons": "4.7.1",
|
|
141
141
|
"react-markdown": "8.0.5",
|
|
142
142
|
"react-syntax-highlighter": "15.5.0",
|
|
143
|
+
"react-use-event-hook": "0.9.3",
|
|
143
144
|
"rehype-raw": "6.1.1",
|
|
144
145
|
"remark-gfm": "3.0.1",
|
|
145
146
|
"rimraf": "3.0.2",
|
|
@@ -147,7 +148,7 @@
|
|
|
147
148
|
"storybook-css-modules": "1.0.8",
|
|
148
149
|
"ts-jest": "29.0.5",
|
|
149
150
|
"ts-node": "10.9.1",
|
|
150
|
-
"type-fest": "3.
|
|
151
|
+
"type-fest": "3.6.0",
|
|
151
152
|
"typescript": "4.9.5",
|
|
152
153
|
"typescript-plugin-css-modules": "4.1.1"
|
|
153
154
|
},
|
|
@@ -158,7 +159,6 @@
|
|
|
158
159
|
"marked": "^4.1.1",
|
|
159
160
|
"react": "^17.0.0 || ^18.0.0",
|
|
160
161
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
161
|
-
"react-use-event-hook": "^0.9.3",
|
|
162
162
|
"turndown": "^7.1.1"
|
|
163
163
|
}
|
|
164
164
|
}
|