Skip to content
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

Improvements to unfill and refill from the runwrap crate #385

Open
mgeisler opened this issue Jun 6, 2021 · 2 comments
Open

Improvements to unfill and refill from the runwrap crate #385

mgeisler opened this issue Jun 6, 2021 · 2 comments

Comments

@mgeisler
Copy link
Owner

mgeisler commented Jun 6, 2021

In #224, @veikman mentioned his new runwrap library and it has this comment:

/// Preserve initial indentation on unwrapping.
/// This is a workaround for textwrap’s tendency to interpret non-alphanumeric leading characters
/// as indentation (e.g. comment syntax) and destroy it. What textwrap calls “subsequent_indent” is
/// destroyed without comment.

I would love to hear more and discuss how we can improve this.

A few weeks ago, I downloaded all public crates which depend on Textwrap and none of them use unfill or refill. In other words, these functions are pretty new and unproven. I'm sure we can make them better!

@veikman
Copy link

veikman commented Jun 7, 2021

I found the behaviour in question when I ran textwrap on an ordinary Markdown heading. There is a unit test case for this here. In that particular use case (Markdown), I don’t think of leading hash characters as indentation, but I suppose that could be a matter of opinion.

I imagine it would be possible to expand the Options struct with limitations on what can be considered indentation for the purpose of unfilling, but I don’t yet know enough about the problem to specify how, and I’m not sure it’s important. The workaround does what it should for now.

@mgeisler
Copy link
Owner Author

mgeisler commented Jun 8, 2021

Thanks for the explanation! So the problem is that unfill sees

# A heading

as "A heading" with "# " as initial_indent. That does indeed seem rather silly 😄

I guess it would work much better if we restrict the heuristic a bit:

  1. only look for initial and subsequent indentation in multi-line strings. That should prevent a lot of misinterpretations.

  2. perhaps only set initial_indent if it is equal to what we detect as subsequent_indent?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants