MarkdownEditing icon indicating copy to clipboard operation
MarkdownEditing copied to clipboard

Feature Request: Smart Wrapping

Open tajmone opened this issue 7 years ago • 2 comments

It would be really cool if MarkdownEditing could handly smartly ST's "Wrap Paragraph at Ruler/n characters" function in lists and blockquotes.

For example, let's take this long blockquote:

> Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem scripta epicuri nec.

After using "Wrap paragraph at 72 characters", it becomes

> Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem
scripta epicuri nec.

... which is ok (lazy syntax), but it would be preferable — for the sake of human readibility of the plain source document — a smarter formatting of the wrapped praragraph:

> Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem
> scripta epicuri nec.

... preserving the > at the beginning of lines.

Similarly, wrapping lists (both numbered and ordered):

1. Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem scripta epicuri nec.
10. Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem scripta epicuri nec.

... currently produces:

1.  Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an
autem scripta epicuri nec. 10. Lorem ipsum dolor sit amet, ea pro
accommodare consectetuer, an autem scripta epicuri nec.

... where the two list items are merged into one due to lack of markdown awareness of the text block being actually a list. So, currently, the elements in the list would have to be spaced:

1. Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem scripta epicuri nec.

10. Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem scripta epicuri nec.

After wrapping them at 72 (using a single selection that embraces them all):

1. Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem
scripta epicuri nec.

10. Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an
autem scripta epicuri nec.

... where a more human readable output would have been:

1.  Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an autem
    scripta epicuri nec.

10. Lorem ipsum dolor sit amet, ea pro accommodare consectetuer, an
    autem scripta epicuri nec.

NOTE — I've intentionally used 1. and 10. in the above example, to remind the necessity of smart indenting in long lists. Besides, some markdown flavours support using specific numbers in lists, and if they don't they'll just treat all numbers alike.

Possibly, there are other cases where smart wrapping long blocks applies. These examples illustrate that if MarkdownEditing could implement smart wrapping in markdown documents it would allow to work nicely with markdown source docs — especially when converting from other formats — and produce a highly human readable source file.

For example, if you use pandoc to convert a document from markdown to markdown, what you get is cleaned up markdown document (even though you loose some things, like reference links, which are "flattened out" in the conversion process). If you invoke pandoc with the wrap option, you can see that it does a pretty smart job when it comes to wrapping lists and blockquotes — of course, pandoc is a full parser and benefits from an AST, which is not the case here. Nevertheless, I'm mentioning it since it represents a good example of what most users might expect in terms of human readable markdown source as a result of text manipulation done by MarkdownEditing.

tajmone avatar Feb 27 '18 10:02 tajmone

Very cool suggestion. It will take some efforts though. Let's see if some passionate contributor is willing to implement it or I will find time some day.

felixhao28 avatar May 03 '18 11:05 felixhao28

Related with #301

deathaxe avatar Aug 04 '21 16:08 deathaxe

Functionality available via Wrap Plus package.

deathaxe avatar Aug 08 '23 21:08 deathaxe

works like a charm!

tajmone avatar Aug 08 '23 23:08 tajmone