mte-kernel icon indicating copy to clipboard operation
mte-kernel copied to clipboard

Don't strip non-breaking whitespace when reformatting (e.g. for Pandoc output)

Open mbroedl opened this issue 7 years ago • 6 comments

I would like to preserve trailing whitespace in my table to create a list-like feel. I thought maybe non-breaking whitespaces might be preserved, but I assume they fall victim to the trimLeft command here: https://github.com/susisu/mte-kernel/blob/master/lib/table-cell.js#L22

Would it be possible to preserve trailing non-breaking whitespaces?

mbroedl avatar Jun 15 '18 15:06 mbroedl

Thank you for reaching out, but I could not get the point.

"Trailing whitespace" you mean is (1) right padding of cells, or (2) right margin of rows?

| ABC     | DEF |   
| ------- | --- |
| abc     | def |
      ^^^         ^^^
      (1)         (2)

And can you describe more detail what behavior you expect?

susisu avatar Jun 15 '18 20:06 susisu

Oh, sorry, it looks like I confused the words leading with trailing, sorry.

What I would like to do:

| ABC | DEF   |
| --- | ----- |
| ABC | DEF   |
|     |   HIJ |
        ^^

but reformatting leads to

| ABC | DEF |
| --- | --- |
| ABC | DEF | 
|     | HIJ |

regardless of whether the spaces are breaking or non-breaking. (Which seems to be expected looking at the spec of the javascript trim function.)

Compiled with Pandoc to PDF this looks like this with normal spaces (that are stripped when reformatted) image and like this with non-breaking spaces (that are also stripped when reformatted) image

I was hoping there is a way that spaces could be preserved if they are non-breaking but not when they are breaking. Maybe the same could go for trailing spaces when items are right-aligned (and both sides if they are centered?). If you are hesitant, maybe one could only keep them if there are two or more to assert intentionality?

Thanks for your quick reply!

PS. I use your plug-in in atom, which I really really enjoy!

mbroedl avatar Jun 15 '18 20:06 mbroedl

Oh, I see. Thank you for explaining.

I checked that both leading and trailing non-breaking spaces (U+00A0) are kept by Pandoc, while they are all stripped by marked and markdown-it (used by markdown-preview and markdown-preview-plus packages of Atom). Maybe I should add an option to keep or strip them.

FYI, an HTML escape sequence   can be used for non-breaking spaces, which is a bit verbose but less confusing.

susisu avatar Jun 16 '18 04:06 susisu

Thanks for the note on   I totally forgot about that option. It certainly does not look as nice in the formatting, but should suffice for now! I would welcome an option to keep non-breaking spaces (not sure about half-width non-breaking spaces); at least on my keyboard there is virtually no chance I would ever make these accidentally.

Do you think I should file an issue at marked and markdown-it, as well? (I hardly ever use them though, because I enjoy monospace prose too much, haha.)

mbroedl avatar Jun 16 '18 12:06 mbroedl

I think you should not unless you really want them to keep NBSPs! There are no well-accepted Markdown spec and thus we have ultimately no answer which is better.

The option will be added in the next version.

susisu avatar Jun 17 '18 15:06 susisu

Thanks a lot, I'm looking forward to the next version! :)

mbroedl avatar Jun 17 '18 17:06 mbroedl