From b62f0d7aa0ded6d1dd4d2848d74af131e525fc09 Mon Sep 17 00:00:00 2001 From: Raphael Forment Date: Sat, 26 Aug 2023 21:07:34 +0200 Subject: [PATCH] slightly better by converting to ES5 string --- src/Documentation.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Documentation.ts b/src/Documentation.ts index eb77485..a45f9c3 100644 --- a/src/Documentation.ts +++ b/src/Documentation.ts @@ -37,6 +37,22 @@ const injectAvailableSamples = (application: Editor): string => { }; export const documentation_factory = (application: Editor) => { + function convert(template: string): string { + // Escape special characters in the string + const escapedString = template + .replace(/\\/g, "\\\\") + .replace(/'/g, "\\'") + .replace(/"/g, '\\"'); + + // Split the template string by line breaks + const lines = escapedString.split("\n"); + + // Concatenate the lines using the + operator + const concatenatedString = lines.map((line) => `'${line}'`).join(" +\n"); + + return concatenatedString; + } + const makeExample = ( description: string, code: string, @@ -44,7 +60,9 @@ export const documentation_factory = (application: Editor) => { ): string => { return `
-${description} +${description}