Skip to content

Commit

Permalink
(fix) markdown newline
Browse files Browse the repository at this point in the history
There were situations where the trim of the last line was not working.
sveltejs#202
  • Loading branch information
Simon Holthausen committed Feb 10, 2021
1 parent 031c44f commit 3d848fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/print/doc-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ export function trimRight(group: Doc[], isWhitespace: (doc: Doc) => boolean): Do
}

function getParts(doc: Doc): Doc[] | undefined {
if (typeof doc === 'object' && (doc.type === 'fill' || doc.type === 'concat')) {
return doc.parts;
if (typeof doc === 'object') {
if (doc.type === 'fill' || doc.type === 'concat') {
return doc.parts;
}
if (doc.type === 'group') {
return getParts(doc.contents);
}
}
}
27 changes: 27 additions & 0 deletions test/printer/samples/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,32 @@ by offloading the formatting of the fenced code block to prettier-plugin-svelte.
color: green;
}
</style>
```

```svelte
<script>
const name = "world";
</script>
```

```svelte
<h1>{greeting}, {name}!</h1>
<style>
h1 {
color: green;
}
</style>
```

```svelte
<script>
const name = "world";
</script>
<h1>{greeting}, {name}!</h1>
```

```svelte
<h1>{greeting}, {name}!</h1>
```

0 comments on commit 3d848fd

Please sign in to comment.