Skip to content

Commit e28d1cf

Browse files
authored
Format html using only the plugin itself (withastro#107)
1 parent fb8a946 commit e28d1cf

File tree

9 files changed

+19
-38
lines changed

9 files changed

+19
-38
lines changed

.changeset/tasty-vans-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'prettier-plugin-astro': patch
3+
---
4+
5+
Format html using only the plugin itself

src/printer.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,6 @@ function print(path: AstPath, opts: ParserOptions, print: printFn): Doc {
142142

143143
if (!isNodeWithChildren(node) || node.children.every(isEmptyTextNode)) return '';
144144

145-
// If we don't see any JSX expressions, this is just embedded HTML
146-
// and we can skip a bunch of work. Hooray!
147-
const hasInlineComponent = node.children.filter((x) => x.type === 'InlineComponent').length > 0;
148-
if (text.indexOf('{') === -1 && !hasInlineComponent) {
149-
// TODO:CHECK 'node.__isRawHTML'
150-
node.__isRawHTML = true;
151-
node.content = text;
152-
return path.call(print);
153-
// return path.map(print, 'children');
154-
}
155-
156145
if (!isPreTagContent(path)) {
157146
trimChildren(node.children);
158147
const output = trim(
@@ -547,14 +536,6 @@ function embed(path: AstPath, print: printFn, textToDoc: (text: string, options:
547536
return [openingTag, indent(group([hardline, formatttedMarkdown])), hardline, `</${node.name}>`];
548537
}
549538

550-
// TODO: ADD TYPES OR FIND ANOTHER WAY TO ACHIVE THIS
551-
// @ts-ignore
552-
if (node.__isRawHTML) {
553-
// TODO: ADD TYPES OR FIND ANOTHER WAY TO ACHIVE THIS
554-
// @ts-ignore
555-
return textToDoc(node.content, { ...opts, parser: 'html' });
556-
}
557-
558539
return null;
559540
}
560541

test/fixtures/embedded-in-markdown/output.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ For best results, you should only have one `<style>` tag per-Astro component. Th
5959
...;
6060
</style>
6161
</head>
62-
<body>
63-
...
64-
</body>
62+
<body> ... </body>
6563
</html>
6664
```
6765

@@ -261,9 +259,9 @@ An Astro component template can render as many top-level elements as you'd like.
261259

262260
```astro
263261
<!-- An Astro component can contain multiple top-level HTML elements: -->
264-
<div id="a" />
265-
<div id="b" />
266-
<div id="c" />
262+
<div id="a"></div>
263+
<div id="b"></div>
264+
<div id="c"></div>
267265
```
268266

269267
When working inside a JSX expression, however, you must wrap multiple elements inside of a **Fragment**. Fragments let you render a set of elements without adding extra nodes to the DOM. This is required in JSX expressions because of a limitation of JavaScript: You can never `return` more than one thing in a JavaScript function or expression. Using a Fragment solves this problem.

test/fixtures/option-html-whitespace-sensitivity-ignore/input.astro

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
<div class="voluptatem architecto at 1">Architecto rerum architecto incidunt sint.</div>
66
<div class="voluptatem architecto at 2"> Architecto rerum architecto incidunt sint.</div>
77
<div class="voluptatem architecto at 3">Architecto rerum architecto incidunt sint. </div>
8-
<div class="voluptatem architecto at 4"> Architecto rerum architecto incidunt sint. </div>
9-
<p>lorem</p><p>lorem</p><span>lorem</span><span>lorem</span>
8+
<div class="voluptatem architecto at 4"> Architecto rerum architecto incidunt sint. </div>

test/fixtures/option-html-whitespace-sensitivity-ignore/output.astro

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@
2929
<div class="voluptatem architecto at 4">
3030
Architecto rerum architecto incidunt sint.
3131
</div>
32-
<p>lorem</p>
33-
<p>lorem</p>
34-
<span>lorem</span>
35-
<span>lorem</span>

test/fixtures/option-html-whitespace-sensitivity-strict/input.astro

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55
<div class="voluptatem architecto at 1">Architecto rerum architecto incidunt sint.</div>
66
<div class="voluptatem architecto at 2"> Architecto rerum architecto incidunt sint.</div>
77
<div class="voluptatem architecto at 3">Architecto rerum architecto incidunt sint. </div>
8-
<div class="voluptatem architecto at 4"> Architecto rerum architecto incidunt sint. </div>
9-
<p>lorem</p><p>lorem</p><span>lorem</span><span>lorem</span>
8+
<div class="voluptatem architecto at 4"> Architecto rerum architecto incidunt sint. </div>

test/fixtures/option-html-whitespace-sensitivity-strict/output.astro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@
2929
<div class="voluptatem architecto at 4">
3030
Architecto rerum architecto incidunt sint.
3131
</div>
32-
<p>lorem</p><p>lorem</p><span>lorem</span><span>lorem</span>

test/fixtures/preserve-tag-case/input.astro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Footer from "./Footer.astro";
33
import {Body} from "lib";
44
---
55

6+
<div>
67
<Footer>this is a footer component</Footer>
78
<footer>this is a regular footer element</footer>
8-
<Body></Body>
9+
<Body></Body>
10+
</div>

test/fixtures/preserve-tag-case/output.astro

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Footer from "./Footer.astro";
33
import { Body } from "lib";
44
---
55

6-
<Footer>this is a footer component</Footer>
7-
<footer>this is a regular footer element</footer>
8-
<Body />
6+
<div>
7+
<Footer>this is a footer component</Footer>
8+
<footer>this is a regular footer element</footer>
9+
<Body />
10+
</div>

0 commit comments

Comments
 (0)