Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add leading+trailing line break to "Copy for Forum" content #1859

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Feb 3, 2023

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

  1. Select File > New Sketch from the Arduino IDE menus.
  2. Select Edit > Copy for Forum (Markdown) from the Arduino IDE menus.
  3. Type some introductory prose into a text editor.
  4. Without manually adding a newline first, paste the content from the clipboard to the text editor.
  5. Without manually adding a newline first, type some additional prose into the text editor.

Before the change proposed here, this will produce a forum post source content with invalid markup:

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:

}

```it dont work
PLZ HURRY HOMEWORK IZ DUE IN TOO HOURS

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:

}

PLZ HURRY HOMEWORK IZ DUE IN TOO HOURS

### Reviewer checklist

* [ ] PR addresses a single concern.
* [ ] The PR has no duplicates (please search among the [Pull Requests](https://github.com/arduino/arduino-ide/pulls) before creating one)
* [ ] PR title and description are properly filled.
* [ ] Docs have been added / updated (for bug fixes / features)

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.
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Feb 3, 2023
@per1234 per1234 self-assigned this Feb 3, 2023
Copy link
Contributor

@kittaakos kittaakos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified it; it works great. Thank you!


Please proceed with the merge, the homework is due in a couple of hours 😄

@per1234 per1234 merged commit 083a706 into arduino:main Feb 3, 2023
@per1234 per1234 deleted the markdown-linebreaks branch February 3, 2023 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants