Skip to content

Commit ca9ae8f

Browse files
committed
fix: trailing whitespace concise blocks
1 parent c9b1008 commit ca9ae8f

7 files changed

Lines changed: 33 additions & 3 deletions

File tree

.changeset/tricky-aliens-cut.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"htmljs-parser": patch
3+
---
4+
5+
Fix incorrectly skipped trailing literal whitespace in concise blocks.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
1╭─ ---
2+
2╭─ A ${'B'} C
3+
│ │ │ │ ╰─ text " C "
4+
│ │ │ ╰─ placeholder:escape.value "'B'"
5+
│ │ ╰─ placeholder:escape "${'B'}"
6+
╰─ ╰─ text " A "
7+
3╰─ ---
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
A ${'B'} C
3+
---
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1╭─ -- ${value}
2+
│ │ │ ╰─ text " "
3+
│ │ ╰─ placeholder:escape.value "value"
4+
╰─ ╰─ placeholder:escape "${value}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- ${value}

src/states/BEGIN_DELIMITED_HTML_BLOCK.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
htmlEOF,
77
type Meta,
88
ErrorCode,
9-
isWhitespaceCode,
9+
isLineCode,
1010
} from "../internal";
1111

1212
export interface DelimitedHTMLBlockMeta extends Meta {
@@ -128,7 +128,7 @@ function handleDelimitedBlockEOL(
128128
// we will end the block
129129
const pos = parser.pos;
130130
let cur = parser.pos;
131-
while (cur && isWhitespaceCode(parser.data.charCodeAt(cur - 1))) {
131+
while (cur && isLineCode(parser.data.charCodeAt(cur - 1))) {
132132
cur--;
133133
}
134134

src/util/util.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ export function isWhitespaceCode(code: number) {
99
return code <= CODE.SPACE;
1010
}
1111

12+
export function isLineCode(code: number) {
13+
switch (code) {
14+
case CODE.NEWLINE:
15+
case CODE.CARRIAGE_RETURN:
16+
return true;
17+
default:
18+
return false;
19+
}
20+
}
21+
1222
export function isIndentCode(code: number) {
1323
return code === CODE.TAB || code === CODE.SPACE;
1424
}
@@ -55,7 +65,7 @@ export function htmlEOF(this: Parser) {
5565
if (!this.activeTag || this.activeTag.concise) {
5666
const pos = this.pos;
5767
let cur = this.pos;
58-
while (cur && isWhitespaceCode(this.data.charCodeAt(cur - 1))) {
68+
while (cur && isLineCode(this.data.charCodeAt(cur - 1))) {
5969
cur--;
6070
}
6171

0 commit comments

Comments
 (0)