Skip to content

Commit ec4faba

Browse files
Timothy Johnsonjamesbirtles
authored andcommitted
Fix printing of html entities in svelte > 3.4.3 (#39)
Fixes #29
1 parent d44b501 commit ec4faba

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/print/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
9898
* allow for flexible grouping of HTML tags in a particular indentation level,
9999
* and is similar to how vanilla HTML is handled in Prettier core.
100100
*/
101-
keepIfLonely: /\n\r?\s*\n\r?/.test(node.data),
101+
keepIfLonely: /\n\r?\s*\n\r?/.test((node.raw || node.data)),
102102
};
103103
}
104104

@@ -108,7 +108,7 @@ export function print(path: FastPath, options: ParserOptions, print: PrintFn): D
108108
* until this node's current line is out of room, at which `fill` will break at the
109109
* most convienient instance of `line`.
110110
*/
111-
return fill(join(line, node.data.split(/[\t\n\f\r ]+/)).parts);
111+
return fill(join(line, (node.raw || node.data).split(/[\t\n\f\r ]+/)).parts);
112112
case 'Element':
113113
case 'InlineComponent':
114114
case 'Slot':
@@ -520,5 +520,5 @@ function isInlineNode(node: Node): boolean {
520520
}
521521

522522
function isEmptyNode(node: Node): boolean {
523-
return node.type === 'Text' && node.data.trim() === '';
523+
return node.type === 'Text' && (node.raw || node.data).trim() === '';
524524
}

src/print/nodes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ElementNode extends BaseNode {
1919
export interface TextNode extends BaseNode {
2020
type: 'Text';
2121
data: string;
22+
raw: string;
2223
}
2324

2425
export interface MustacheTagNode extends BaseNode {

0 commit comments

Comments
 (0)