Skip to content

Commit 01fa5d9

Browse files
authored
Merge pull request #139 from zhlint-project/jinjiang/bugfix/126
fix: trailing quotations (close #126)
2 parents dae453a + 1006b50 commit 01fa5d9

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

src/parser/util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ export const isShorthand = (
424424
if (!status.lastToken || status.lastToken.type !== CharType.WESTERN_LETTER) {
425425
return false
426426
}
427+
if (str.length <= index + 1) {
428+
return false
429+
}
427430
const nextChar = str[index + 1]
428431
const nextType = checkCharType(nextChar)
429432
if (nextType === CharType.WESTERN_LETTER || nextType === CharType.SPACE) {

src/rules/case-pure-western.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const findNonWestern = (group: MutableGroupToken): boolean => {
2626
return findNonWestern(token)
2727
}
2828
if (isFullwidthType(token.type)) {
29+
if (token.value.match(/[]/)) {
30+
return false
31+
}
2932
return true
3033
}
3134
})
@@ -36,7 +39,11 @@ const resetValidation = (group: MutableGroupToken): void => {
3639
for (const target in ValidationTarget) {
3740
removeValidationOnTarget(token, target as ValidationTarget)
3841
}
42+
token.modifiedSpaceAfter = token.spaceAfter
43+
token.modifiedType = token.type
44+
token.modifiedValue = token.value
3945
if (token.type === GroupTokenType.GROUP) {
46+
token.modifiedInnerSpaceBefore = token.innerSpaceBefore
4047
resetValidation(token)
4148
}
4249
})

test/md.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ describe('parser with markdown', () => {
9999

100100
describe('markdown lint', () => {
101101
test('[md] single paragraph', () => {
102-
expect(getOutput('X[ xxx ](xxx)X`hello`world')).toBe(
103-
'X [xxx](xxx) X `hello` world'
102+
expect(getOutput('中文 X[ xxx ](xxx)X`hello`world')).toBe(
103+
'中文 X [xxx](xxx) X `hello` world'
104104
)
105105
})
106106
test('[md] frontmatter', () => {
@@ -129,11 +129,11 @@ describe('markdown lint', () => {
129129
test('[md] raw content', () => {
130130
// {% raw %}<div id="app" class="demo">...</div>{% raw %}
131131
expect(
132-
getOutput('{% raw %}\n<div id="app" class="demo">...</div>\n{% raw %}')
133-
).toBe('{% raw %}\n<div id="app" class="demo">...</div>\n{% raw %}')
132+
getOutput('中文 {% raw %}\n<div id="app" class="demo">...</div>\n{% raw %}')
133+
).toBe('中文 {% raw %}\n<div id="app" class="demo">...</div>\n{% raw %}')
134134
})
135135
test('[md] empty lines', () => {
136-
expect(getOutput('a\n\nb\n\nc')).toBe('a\n\nb\n\nc')
136+
expect(getOutput('中文 a\n\nb\n\nc')).toBe('中文 a\n\nb\n\nc')
137137
})
138138
test('[md] inline code', () => {
139139
expect(getOutput(`改进 \`<todo-item>\` 组件`)).toBe(

test/uncategorized.test.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('lint by issues', () => {
4040

4141
// https://github.com/zhlint-project/zhlint/issues/35
4242
test('#35 parse error', () => {
43-
expect(getOutput('x‘x’x', options)).toBe('x ‘x’ x')
43+
expect(getOutput('中文 x‘x’x', options)).toBe('中文 x ‘x’ x')
4444
})
4545

4646
// https://github.com/zhlint-project/zhlint/issues/36
@@ -57,6 +57,52 @@ describe('lint by issues', () => {
5757
expect(getOutput('中文 ;-)', options)).toBe('中文 ;-)')
5858
expect(getOutput('1) 项目符号', options)).toBe('1) 项目符号')
5959
})
60+
61+
// https://github.com/zhlint-project/zhlint/issues/126
62+
test('#126 (1)', () => {
63+
expect(getOutput(
64+
`使用 \`||\` 时,title 会先转化为布尔值判断,为 true 时返回 title,false 返回 'title'`,
65+
options
66+
)).toBe(
67+
`使用 \`||\` 时,title 会先转化为布尔值判断,为 true 时返回 title,false 返回 ‘title’`
68+
)
69+
})
70+
71+
// https://github.com/zhlint-project/zhlint/issues/126
72+
test('#126 (1) extended', () => {
73+
expect(getOutput(
74+
`中文‘中文’中文‘English’中文'中文'中文'English'中文`,
75+
options
76+
)).toBe(
77+
`中文 ‘中文’ 中文 ‘English’ 中文 ‘中文’ 中文 ‘English’ 中文`
78+
)
79+
expect(getOutput(
80+
`中文‘中文’中文‘English’中文'中文'中文'English'`,
81+
options
82+
)).toBe(
83+
`中文 ‘中文’ 中文 ‘English’ 中文 ‘中文’ 中文 ‘English’`
84+
)
85+
})
86+
87+
// https://github.com/zhlint-project/zhlint/issues/126
88+
test('#126 (2)', () => {
89+
expect(getOutput(
90+
`### 5.1 “Attention Is All You Need”`,
91+
options
92+
)).toBe(
93+
`### 5.1 “Attention Is All You Need”`
94+
)
95+
})
96+
97+
// https://github.com/zhlint-project/zhlint/issues/126
98+
test('#126 (3)', () => {
99+
expect(getOutput(
100+
`How it works: The novel HTTP/2 ‘Rapid Reset’ DDoS attack`,
101+
options
102+
)).toBe(
103+
`How it works: The novel HTTP/2 ‘Rapid Reset’ DDoS attack`
104+
)
105+
})
60106
})
61107

62108
describe('lint from v3.cn.vuejs.org', () => {

0 commit comments

Comments
 (0)