Skip to content

Commit d192ab5

Browse files
lionel-vezwork
authored andcommitted
Don't append lines to block code before formatting
1 parent 15d9762 commit d192ab5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

apps/vscode/src/providers/format.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ async function formatActiveCell(editor: TextEditor, engine: MarkdownEngine) {
209209

210210
async function formatBlock(doc: TextDocument, block: TokenMath | TokenCodeBlock, language: EmbeddedLanguage) {
211211
// Create virtual document containing the block
212-
const blockLines = lines(codeForExecutableLanguageBlock(block));
213-
blockLines.push("");
212+
const blockLines = lines(codeForExecutableLanguageBlock(block, false));
214213
const vdoc = virtualDocForCode(blockLines, language);
215214

216215
const edits = await executeFormatDocumentProvider(

packages/quarto-core/src/markdown/language.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ export function isExecutableLanguageBlock(token: Token) : token is TokenMath | T
3838
}
3939
}
4040

41-
export function codeForExecutableLanguageBlock(token: TokenMath | TokenCodeBlock) {
41+
export function codeForExecutableLanguageBlock(
42+
token: TokenMath | TokenCodeBlock,
43+
appendNewline = true,
44+
) {
4245
if (isMath(token)) {
4346
return token.data.text;
4447
} else if (isCodeBlock(token)) {
45-
return token.data + "\n";
48+
return token.data + (appendNewline ? "\n" : "");
4649
} else {
4750
return "";
4851
}

0 commit comments

Comments
 (0)