-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
:reflow
does not recognize \n\n
as paragraph end/start
#2419
Comments
Workaround(Maybe this is the intended way to format text in Helix?)
|
The above workaround does not work e.g. with block quotes A more general approach would be to refer to Treesitter to analyse the text's structure. |
This is a known shortcoming of the current approach. I'm not sure how to get textwrap, the underlying crate powering the feature, to recognize "blank" lines. We could try to manually do it and call textwrap on the individual paragraphs only, but then we'd have to re-implement the prefix detection to handle things like the following scenario: /// # title
///
/// some paragraph text
@mgeisler Any ideas? Is this something textwrap already handles and I just didn't find it? |
It seems to me that, WrapAlgorithm in textwrap::wrap_algorithms - Rust has a notion of "paragraph".
|
Hi @vlmutolo and @getreu, you're correct that
The notion of a paragraph is quite simple (primitive): functions like Basically, Textwrap would originally disregard all whitespace and put all words into a single wrapped paragraph. However, people expect newlines to be preserved, so Textwrap now splits on That is true for |
What about defining a custom WrapAlgorithm in textwrap::wrap_algorithms - Rust that honours paragraph boundaries? |
We probably need a custom wrap algorithm (WrapAlgorithm) for other unsoundness anyway: e.g. we do not want wrap in the middle of URLs and eventually not even after |
The job of the wrap algorithm is to turn a slice of words into wrapped lines. This is done via Under the hood,
It's the job of other functions to prepare these fragments — and these other functions decide if |
Another workaround
|
Well, your explanation confirms, that textwrap - Rust is highly customisable? |
Yes, I would say so :-) The most elaborate example of this is the WebAssembly demo, where I could put in toggles for all the options: https://mgeisler.github.io/textwrap. It also shows how Textwrap can wrap non-console text (it uses I wrote up a blurb of text about it in #136 in a reply to @cessen. I'm sorry for ending up with a discussion split across issues like this. |
In markup languages
\n\n
marks the end and start of a new paragraph. The current word wrap implementation does not recognise paragraph endings. Instead they are interpreted as usual white-space and the text is formatted as one big block.The text was updated successfully, but these errors were encountered: