Skip to content

Commit

Permalink
(fix) markdown newline (#204)
Browse files Browse the repository at this point in the history
There were situations where the trim of the last line was not working.
#202
  • Loading branch information
dummdidumm authored Feb 10, 2021
1 parent 6783173 commit 674eab3
Show file tree
Hide file tree
Showing 2 changed files with 35 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);
}
}
}
28 changes: 28 additions & 0 deletions test/printer/samples/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,31 @@ by offloading the formatting of the fenced code block to prettier-plugin-svelte.
}
</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 674eab3

Please sign in to comment.