kalekundert / stepwise

Modular, command-line scientific protocols
GNU General Public License v3.0
3 stars 0 forks source link

Add a `definition_list` formatting object #46

Closed kalekundert closed 3 years ago

kalekundert commented 3 years ago
key 1: value 1
key 2: longer value that wraps
  onto the next line.
kalekundert commented 3 years ago

Option to force all values to start on their own lines.

kalekundert commented 3 years ago

The problem is that there's not a clear way to wrap preformatted blocks that might be added to a defintiion list. In order to get the indentation effect shown above, I need to update format_text() to support the initial_indent and subsequent_indent arguments to textwrap.fill(). This itself takes some care, because the initial indent should only be applied once no matter how many times format_text() is recursively invoked. But for preformatted blocks, the bigger problem is that it doesn't make sense to have different indentation on different lines. The indentation is part of the "pre-formatting", and changing it could mess up the formatting.

I think the way to deal with this is to implement special logic for handling the indent arguments in pre.format_text(). (Related: I should also remove the NO_WRAP logic from format_text() and move it to pre.format_text(). It doesn't make sense to have a formatted block in a preformatted block. A formatted block is by definition not preformatted.) The algorithm I have in mind is:

kalekundert commented 3 years ago

Another issue is that I have to make sure to correctly manipulate the indent arguments when making nested lists.