Skip to content

Commit f8cacbe

Browse files
committed
fix(sentence): fix to handle last new line of sentence
1 parent dd18d74 commit f8cacbe

File tree

4 files changed

+332
-18
lines changed

4 files changed

+332
-18
lines changed

src/parser/SeparatorParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class SeparatorParser implements AbstractParser {
2727
// It will avoid false-position like `1.23`
2828
if (firstChar === ".") {
2929
if (nextChar) {
30-
return nextChar === " ";
30+
return /[\s\t\r\n]/.test(nextChar);
3131
} else {
3232
return true;
3333
}

test/fixtures/sentence-3/output.json

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,61 +81,101 @@
8181
},
8282
{
8383
"type": "Sentence",
84-
"raw": "I found it.\nHello World.",
85-
"value": "I found it.\nHello World.",
84+
"raw": "I found it.",
85+
"value": "I found it.",
8686
"loc": {
8787
"start": {
8888
"line": 1,
8989
"column": 13
9090
},
9191
"end": {
92-
"line": 2,
93-
"column": 12
92+
"line": 1,
93+
"column": 24
9494
}
9595
},
9696
"range": [
9797
13,
98-
37
98+
24
9999
],
100100
"children": [
101101
{
102102
"type": "Str",
103-
"raw": "I found it.",
104-
"value": "I found it.",
103+
"raw": "I found it",
104+
"value": "I found it",
105105
"loc": {
106106
"start": {
107107
"line": 1,
108108
"column": 13
109109
},
110110
"end": {
111111
"line": 1,
112-
"column": 24
112+
"column": 23
113113
}
114114
},
115115
"range": [
116116
13,
117-
24
117+
23
118118
]
119119
},
120120
{
121-
"type": "WhiteSpace",
122-
"raw": "\n",
123-
"value": "\n",
121+
"type": "Punctuation",
122+
"raw": ".",
123+
"value": ".",
124124
"loc": {
125125
"start": {
126126
"line": 1,
127-
"column": 24
127+
"column": 23
128128
},
129129
"end": {
130-
"line": 2,
131-
"column": 0
130+
"line": 1,
131+
"column": 24
132132
}
133133
},
134134
"range": [
135-
24,
136-
25
135+
23,
136+
24
137137
]
138+
}
139+
]
140+
},
141+
{
142+
"type": "WhiteSpace",
143+
"raw": "\n",
144+
"value": "\n",
145+
"loc": {
146+
"start": {
147+
"line": 1,
148+
"column": 24
138149
},
150+
"end": {
151+
"line": 2,
152+
"column": 0
153+
}
154+
},
155+
"range": [
156+
24,
157+
25
158+
]
159+
},
160+
{
161+
"type": "Sentence",
162+
"raw": "Hello World.",
163+
"value": "Hello World.",
164+
"loc": {
165+
"start": {
166+
"line": 2,
167+
"column": 0
168+
},
169+
"end": {
170+
"line": 2,
171+
"column": 12
172+
}
173+
},
174+
"range": [
175+
25,
176+
37
177+
],
178+
"children": [
139179
{
140180
"type": "Str",
141181
"raw": "Hello World",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"type": "Paragraph",
3+
"children": [
4+
{
5+
"type": "Str",
6+
"value": "First, A is A.\nSecond, B is B.\nThird, C is C.",
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 3,
14+
"column": 14
15+
}
16+
},
17+
"range": [
18+
0,
19+
45
20+
],
21+
"raw": "First, A is A.\nSecond, B is B.\nThird, C is C."
22+
}
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 3,
31+
"column": 14
32+
}
33+
},
34+
"range": [
35+
0,
36+
45
37+
],
38+
"raw": "First, A is A.\nSecond, B is B.\nThird, C is C."
39+
}

0 commit comments

Comments
 (0)