Add leading+trailing line break to "Copy for Forum" content #1859
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
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 (example).
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 reduce the likelihood of markup being 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.
Change description
Adding a newline before and after the content added to the clipboard 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 source content, it will not have any effect on the rendered content because the additional newlines are ignored by the renderer.
Other information
Originally suggested at https://forum.arduino.cc/t/where-to-manipulate-serial-monitor-sending-cr-crlf/1085784/11
Demo
Before the change proposed here, this will produce a forum post source content with invalid markup:
It will not render as intended:
halp me with my ardunio sketch```cpp
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}