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 description:
(fix) no empty line at the end of markdown embed
Prettier's markdown parser tries to strip the last hardline of the embedded docs, but fails to do so in our case because it does not recurse into concat parts -> we need to strip it ourselves.
Fixes #202

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4518d55..937c57f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # prettier-plugin-svelte changelog
 
+## 2.1.3 (Unreleased)
+
+* Don't print empty line at the end of the code if embedded inside markdown ([#202](https://github.com/sveltejs/prettier-plugin-svelte/issues/202))
+
 ## 2.1.2
 
 * Keep whitespace around `<script>`/`<style>` tags ([#197](https://github.com/sveltejs/prettier-plugin-svelte/issues/197))
diff --git a/src/print/index.ts b/src/print/index.ts
index 255641a..8e83e1d 100644
--- a/src/print/index.ts
+++ b/src/print/index.ts
@@ -4,7 +4,7 @@ import { extractAttributes } from '../lib/extractAttributes';
 import { getText } from '../lib/getText';
 import { hasSnippedContent, unsnipContent } from '../lib/snipTagContent';
 import { parseSortOrder, SortOrderPart } from '../options';
-import { isEmptyDoc, isLine, trim } from './doc-helpers';
+import { isEmptyDoc, isLine, trim, trimRight } from './doc-helpers';
 import { flatten, isASTNode, isPreTagContent } from './helpers';
 import {
     checkWhitespaceAtEndOfSvelteBlock,
@@ -673,6 +673,15 @@ function printTopLevelParts(
     ignoreNext = false;
     svelteOptionsDoc = undefined;
 
+    // If this is invoked as an embed of markdown, remove the last hardline.
+    // The markdown parser tries this, too, but fails because it does not
+    // recurse into concats. Doing this will prevent an empty line
+    // at the end of the embedded code block.
+    if (options.parentParser === 'markdown') {
+        const lastDoc = docs[docs.length - 1];
+        trimRight([lastDoc], isLine);
+    }
+
     return groupConcat([join(hardline, docs)]);
 }
 


Test patch:
diff --git a/test/printer/samples/markdown.md b/test/printer/samples/markdown.md
index c7ba83e..8ccd4bb 100644
--- a/test/printer/samples/markdown.md
+++ b/test/printer/samples/markdown.md
@@ -17,5 +17,4 @@ by offloading the formatting of the fenced code block to prettier-plugin-svelte.
         color: green;
     }
 </style>
-
 ```