From c407ee2b1743164280371e9825d3c850252b991c Mon Sep 17 00:00:00 2001 From: nithin-sudarsan Date: Mon, 30 Sep 2024 20:18:31 +0530 Subject: [PATCH] python: Fix for comments starting or ending with double quotes. Fixes #1239 --- .../quicktype-core/src/language/Python/PythonRenderer.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/quicktype-core/src/language/Python/PythonRenderer.ts b/packages/quicktype-core/src/language/Python/PythonRenderer.ts index 63ec3c70d..adddd4558 100644 --- a/packages/quicktype-core/src/language/Python/PythonRenderer.ts +++ b/packages/quicktype-core/src/language/Python/PythonRenderer.ts @@ -60,11 +60,14 @@ export class PythonRenderer extends ConvenienceRenderer { protected emitDescriptionBlock(lines: Sourcelike[]): void { if (lines.length === 1) { const docstring = modifySource(content => { + if (content.startsWith('"')) { + content = ' ' + content; + } if (content.endsWith('"')) { - return content.slice(0, -1) + '\\"'; + content = content + ' '; } - return content; + return content.replace(/"/g, '\\"'); }, lines[0]); this.emitComments([{ customLines: [docstring], lineStart: '"""', lineEnd: '"""' }]); } else {