Skip to content

Commit 083a706

Browse files
committed
Add leading+trailing line break to "Copy for Forum" content
Arduino IDE's "Edit > Copy for Forum (Markdown)" feature copies the contents of the currently selected editor tab to the clipboard, with "fenced code block" markup added to provide correct formatting when the content is posted to a platform supporting Markdown language such as Arduino Forum, GitHub, Stack Exchange, etc. One of the most common points of friction between the volunteer helpers on the forum and the newcomers requesting assistance is the failure to use the correct markup when posting code. In the best case scenario the code and thread is made less readable and less convenient to copy to the IDE for further investigation. Components of the code often resemble markup, which causes it to be corrupted by the forum's renderer. Even in cases where the user was conscientious enough to attempt to add the right markup, which is facilitated by tools such as "Copy for Forum (Markdown)", they often still don't get it quite right. So it is worthwhile to make efforts to make it less likely for the markup to be inadvertently invalidated. "Fenced code block" markup must be on its own lines before and after the code content. Someone not familiar with Markdown won't know this fact and may simply paste the content copied via "Copy for Forum (Markdown)" without manually adding a newline before and after. Since the code content is preceded and succeeded by a newline, they will not have any visual indication of a problem. Adding a newline before and after the content will ensure the markup is valid regardless of the context it is pasted into. In cases where the user did add a newline and this introduces a redundant line break in the forum post, it will not have any effect on the rendered content because the additional newlines are ignored by the renderer.
1 parent f5621db commit 083a706

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/edit-contributions.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ export class EditContributions extends Contribution {
5757
execute: async () => {
5858
const value = await this.currentValue();
5959
if (value !== undefined) {
60-
this.clipboardService.writeText(`\`\`\`cpp
60+
this.clipboardService.writeText(`
61+
\`\`\`cpp
6162
${value}
62-
\`\`\``);
63+
\`\`\`
64+
`);
6365
}
6466
},
6567
});

0 commit comments

Comments
 (0)