Open goyalyashpal opened 1 year ago
OT:
while searching for possible duplicates, i stumbled upon this: https://github.com/mgeisler/textwrap/issues/205#issuecomment-692941623 and wow, that can be used to implement typora like markup table source prettifier. nice.
Hi @goyalyashpal, thanks for writing! I'm glad you like this (mostly unknown) feature :smile:
- Do you have any idea how will you generate that list of widths?
I'm no expert on this, but I would imagine a desktop publishing (DTP) program would want to reserve a certain height and width for an embedded figure. So the program would do something like this
Thus, we need to shrink 10 lines by 40 mm. If the picture starts on line 3, the DTP program would have to use [150, 150, 110, 110, 110, 110, 150]
as the line widths (the last line width is repeated as necessary). This should allow the DTP program to format a single paragraph with a cut-out for the figure.
Note that Textwrap fundamentally likes to format paragraphs. It also works with multiple paragraphs, but that's just because it splits on \n
and formats each line by itself. A program that anchors a figure to paragraph would definitely want to format that paragraph by itself.
In the example above, one could imagine that the formatted paragraph is not height enough to contain the full figure:
Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore +--------+
magnam aliquam quaerat . | |
| |
+--------+
The program can detect this because the wrapped paragraph has a height of 4 lines = 24 mm, but the picture started 2 lines down (12 mm) and it 24 mm tall. So the program knows that the picture sticks out by 12 mm or 2 lines. It can use this information to wrap the following paragraph appropriately (using [110, 150]
as the line widths, assuming the paragraphs are spaced by 1 line of 6 mm).
Originally posted by @mgeisler in https://github.com/helix-editor/helix/issues/136#issuecomment-1399416641
wowww, that's super nice. Exactly what i was thinking.
Title inspired by inkscape: ddg 🔍 : inkscape flow text