Repository: sveltejs/prettier-plugin-svelte (ts)

Issue:
Don't append trailing newline when parsing markdown code blocks
Every other code block formatter (tested with `ts`, `js`, and `html`) leaves the fenced code blocks with no trailing newlines, but this one appends a trailing newline, which is therefore out of place and distracting. It would be great if this could leave 0 trailing newlines in these fenced blocks.

EDIT: namely, remove line 20 of test/printer/samples/markdown.md.

Pull request:
(fix) markdown newline
There were situations where the trim of the last line in #203 was not working.
Fixes #202

Patch:
diff --git a/src/print/doc-helpers.ts b/src/print/doc-helpers.ts
index fa6ed4d..c54cc77 100644
--- a/src/print/doc-helpers.ts
+++ b/src/print/doc-helpers.ts
@@ -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);
+        }
     }
 }


Test patch:
diff --git a/test/printer/samples/markdown.md b/test/printer/samples/markdown.md
index 8ccd4bb..b2b6d8d 100644
--- a/test/printer/samples/markdown.md
+++ b/test/printer/samples/markdown.md
@@ -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
+```