@seafile/seafile-editor 1.0.18 → 1.0.20
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.
|
@@ -145,6 +145,14 @@ export const transformListItem = node => {
|
|
|
145
145
|
const {
|
|
146
146
|
children
|
|
147
147
|
} = node;
|
|
148
|
+
if (children.length === 0) {
|
|
149
|
+
return {
|
|
150
|
+
id: slugid.nice(),
|
|
151
|
+
type: LIST_ITEM,
|
|
152
|
+
// eslint-disable-next-line array-callback-return
|
|
153
|
+
children: [transformListContent({})]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
148
156
|
return {
|
|
149
157
|
id: slugid.nice(),
|
|
150
158
|
type: LIST_ITEM,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import isLastCharPunctuation from '../../utils/is-punctuation-mark';
|
|
1
2
|
const generateDefaultText = () => {
|
|
2
3
|
return {
|
|
3
4
|
type: 'text',
|
|
@@ -20,18 +21,57 @@ const transformTextNode = textNode => {
|
|
|
20
21
|
|
|
21
22
|
// blob = true, add strong parent
|
|
22
23
|
if (textNode['bold']) {
|
|
23
|
-
mdNode =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
mdNode['value'] = mdNode.value ? mdNode.value.trim() : '';
|
|
25
|
+
if (isLastCharPunctuation(mdNode.value)) {
|
|
26
|
+
const value = mdNode.value;
|
|
27
|
+
const mdNode1 = {
|
|
28
|
+
...mdNode,
|
|
29
|
+
value: value.substring(0, value.length - 1)
|
|
30
|
+
};
|
|
31
|
+
const mdNode2 = {
|
|
32
|
+
type: 'text',
|
|
33
|
+
value: value.substring(value.length - 1)
|
|
34
|
+
};
|
|
35
|
+
mdNode = [{
|
|
36
|
+
type: 'strong',
|
|
37
|
+
children: [mdNode1]
|
|
38
|
+
}, mdNode2];
|
|
39
|
+
} else {
|
|
40
|
+
mdNode = {
|
|
41
|
+
type: 'strong',
|
|
42
|
+
children: [mdNode]
|
|
43
|
+
};
|
|
44
|
+
}
|
|
27
45
|
}
|
|
28
46
|
|
|
29
47
|
// italic = true, add emphasis parent
|
|
30
|
-
if (textNode['italic']) {
|
|
48
|
+
if (textNode['italic'] && mdNode.type === 'strong') {
|
|
31
49
|
mdNode = {
|
|
32
50
|
type: 'emphasis',
|
|
33
51
|
children: [mdNode]
|
|
34
52
|
};
|
|
53
|
+
} else if (textNode['italic']) {
|
|
54
|
+
mdNode['value'] = mdNode.value ? mdNode.value.trim() : '';
|
|
55
|
+
if (isLastCharPunctuation(mdNode.value)) {
|
|
56
|
+
const value = mdNode.value;
|
|
57
|
+
const mdNode1 = {
|
|
58
|
+
...mdNode,
|
|
59
|
+
value: value.substring(0, value.length - 1)
|
|
60
|
+
};
|
|
61
|
+
const mdNode2 = {
|
|
62
|
+
type: 'text',
|
|
63
|
+
value: value.substring(value.length - 1)
|
|
64
|
+
};
|
|
65
|
+
mdNode = [{
|
|
66
|
+
type: 'emphasis',
|
|
67
|
+
children: [mdNode1]
|
|
68
|
+
}, mdNode2];
|
|
69
|
+
} else {
|
|
70
|
+
mdNode = {
|
|
71
|
+
type: 'emphasis',
|
|
72
|
+
children: [mdNode]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
35
75
|
}
|
|
36
76
|
return mdNode;
|
|
37
77
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const isChPunctuation = char => {
|
|
2
|
+
// \u2014|\u2018|\u2019|\u201c|\u201d|
|
|
3
|
+
// \u2026|
|
|
4
|
+
// \u2039|\u203a
|
|
5
|
+
// \u3001|\u3002|\u3008|\u3009|\u300a|\u300b|\u300c|\u300d|\u300e|\u300f
|
|
6
|
+
// \u3010|\u3011|\u3014|\u3015|\u301c|\u301d|\u301e
|
|
7
|
+
// \ufe43|\ufe44|\ufe4f
|
|
8
|
+
// \uffe5 (¥)
|
|
9
|
+
const reg = /[\u2014|\u2018|\u2019|\u201c|\u201d|\u2026|\u2039|\u203a|\u3001|\u3002|\u3008|\u3009|\u300a|\u300b|\u300c|\u300d|\u300e|\u300f|\u3010|\u3011|\u3014|\u3015|\u301c|\u301d|\u301e]/;
|
|
10
|
+
if (reg.test(char)) {
|
|
11
|
+
return true;
|
|
12
|
+
} else {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function isEnHalfWidthPunctuation(char) {
|
|
17
|
+
// Distribution of half-width punctuation points in unicode: 0x0021~0x007e
|
|
18
|
+
// https://en.wikibooks.org/wiki/Unicode/Character_reference/0000-0FFF
|
|
19
|
+
const reg = /[\x21-\x2f\x3a-\x40\x5b-\x60\x7B-\x7F]/;
|
|
20
|
+
if (reg.test(char)) {
|
|
21
|
+
return true;
|
|
22
|
+
} else {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function isEnFullWidthPunctuation(char) {
|
|
27
|
+
// 0xff01~0xff5e
|
|
28
|
+
// https://en.wikibooks.org/wiki/Unicode/Character_reference/F000-FFFF
|
|
29
|
+
const reg = /[\uff01-\uff0f\uff1a-\uff1f\uff20\uff3b-\uff3f\uff40\uff5b-\uff5f]/;
|
|
30
|
+
if (reg.test(char)) {
|
|
31
|
+
return true;
|
|
32
|
+
} else {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const isLastCharPunctuation = value => {
|
|
37
|
+
if (typeof value !== 'string' || !value) return false;
|
|
38
|
+
const lastChar = value.slice(-1);
|
|
39
|
+
if (isChPunctuation(lastChar)) return true;
|
|
40
|
+
if (isEnHalfWidthPunctuation(lastChar)) return true;
|
|
41
|
+
if (isEnFullWidthPunctuation(lastChar)) return true;
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
44
|
+
export default isLastCharPunctuation;
|