markdownfmt icon indicating copy to clipboard operation
markdownfmt copied to clipboard

Do not delete soft lines (optionally?)

Open karelbilek opened this issue 4 years ago • 4 comments

Currently we put together newlines. That is

foo bar
baz baz

will be formatted as

foo bar baz baz

This is basically correct.

A conforming parser may render a soft line break in HTML either as a line break or as a space.

https://spec.commonmark.org/0.29/#soft-line-breaks

However, as the spec says also,

A renderer may also provide an option to render soft line breaks as hard line breaks.

I have now saw an issue in one project where those soft lines were actually interpreted as hard lines, and this option was "on by default", so these soft lines were actually important. (Related to https://github.com/nhn/tui.editor/issues/1347 )

We can see goldmark for inspiration; goldmark has option WithHardLines for renderer; we can copy that directly almost.

karelbilek avatar Jan 19 '21 21:01 karelbilek

sorry, it is WithHardWraps

https://github.com/yuin/goldmark/blob/da9729d1345128edf7c0a411b0912b61582f915b/renderer/html/html.go#L88-L89

karelbilek avatar Jan 19 '21 21:01 karelbilek

Or we could actually automatically tell what max char length should it be (:

bwplotka avatar Aug 03 '21 10:08 bwplotka

Taking max width and breaking on that is a different thing from preserving current lines.

Both would be fine :P

I'm now kind of busy, PR welcome :D

karelbilek avatar Aug 03 '21 11:08 karelbilek

Looks like this is done with #36? Should this issue be closed?

abhinav avatar Nov 02 '22 21:11 abhinav

Done in #36

abhinav avatar Nov 30 '22 21:11 abhinav