shuzijun / markdown-editor

IntelliJ Platform A full-featured WYSIWYG editor for markdown
https://plugins.jetbrains.com/plugin/17254-markdown-editor
Apache License 2.0
155 stars 35 forks source link

Incorrect wrapping of multiline markdown text #74

Open winston-zillow opened 1 year ago

winston-zillow commented 1 year ago

One reason people use markdown is that it is text friendly without any viewer. For example this multiline paragraph is rendered as one paragraph in target format, even though it is written with line breaks in between, like:

One reason people use markdown is that it is text friendly 
without any viewer. For example this multiline paragraph is [rendered as one paragraph](https://www.markdownguide.org/basic-syntax/#paragraphs-1) 
in target format, even though it is written 
with line breaks in between, like:

However, the Markdown Editor (and this github preview too :-( ), the text of the above paragraph is wrapped at the line breaks rather than at the end of the margin.

The desired behaviors are

  1. obey multi-line convention of markdown and wrap at the margin;
  2. better yet re-format the original markdown text as well so it looks pretty in non-rendered text view.

I don't know if item 1 should be fixed/handled by Markdown Editor or the underlying vdictor but item 2 should be handled by Markdown Editor.

winston-zillow commented 1 year ago

@shuzijun hi, what do you think about this?

shuzijun commented 1 year ago

I checked the documentation of vditor:

目前大部分 Markdown 引擎会自动将换行符 \n 转换为 \
,即软换行转硬换行。所以结尾用两个或更多空格的写法虽然稳妥,但是可能也会造成一些小问题:结尾空格在一些编辑器中并不可视;不小心按到或者习惯性按到会造成错误排版。介于这些小问题,可能用 \
来折行是最稳妥的做法,但这又不太优雅。另外,在 CommonMark 规范中可以在文本结尾使用反斜杠 \ 来折行,但我也不太推荐这种写法。

综上,我的建议是不要使用结尾空格、\ 或者 \
,因为现在几乎所有的 Markdown 引擎基本都已经支持软换行转硬换行了。

At present, most Markdown engines will automatically convert line breaks \n to \
, that is, soft line breaks to hard line breaks. So, although it is safe to write with two or more spaces at the end, it may also cause some minor problems: the trailing space is not visible in some editors; accidental or habitual pressing will cause wrong typesetting. Between these little problems, it's probably safest to wrap lines with \
, but it's not very elegant. Also, in the CommonMark specification you can use a backslash \ to wrap lines at the end of text, but I don't recommend it very much either.

To sum up, my suggestion is not to use trailing spaces, \ or \
, because almost all Markdown engines now basically support soft line breaks to hard line breaks.

Sorry, this is a feature of vditor, including reformatting file contents too.