jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.2k stars 3.36k forks source link

Markdown writer: incorrect word wrapping when a list item has a very long word #5033

Closed lollipopman closed 5 years ago

lollipopman commented 5 years ago

When a list item has a word that extends beyond the column setting, the previous list entry is not wrapped correctly:

test:

; pandoc -f gfm -t gfm <<EOF
>   - The next line should be joined
>     here.
>   - asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> EOF
  - The next line should be joined
    here.
  - asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

expected output:

  - The next line should be joined here.
  - asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

version:

; pandoc -v
pandoc 2.3.1
Compiled with pandoc-types 1.17.5.1, texmath 0.11.1, skylighting 0.7.2
jgm commented 5 years ago

Possibly an issue in Text.Pandoc.Pretty.

agusmba commented 5 years ago

Isn't this what --wrap is for?

$ pandoc -f gfm -t gfm --wrap=none <<EOF
>   - The next line should be joined
>     here.
>   - asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> EOF
  - The next line should be joined here.
  - asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
agusmba commented 5 years ago

My previous comment could be a workaround as I believe that the default --wrap=auto should also yield the expected result, but it doesn't:

$ pandoc -f gfm -t gfm --wrap=auto --columns=72 <<EOF
>   - The next line should be joined
>     here.
>   - asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> EOF
  - The next line should be joined
    here.
  - asaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

EDIT: note that if the second list item line isn't as long, the wrapping works correctly

jgm commented 5 years ago

If anyone wants to diagnose this, I'd do it by using traceShowId from Debug.Trace to inspect the Doc produced by the markdown writer before it is rendered. Then try to reproduce the issue directly with Text.Pandoc.Pretty.

Ignore that: it's gfm, so libcmark is doing the formatting/wrapping. Nothing to do with any code in pandoc itself.

jgm commented 5 years ago

This can be reproduced with the cmark executable:

% ./cmark -t commonmark --width 80
  - the next line should be joined
    here
  - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  - the next line should be joined
    here
  - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

So the issue should really be reported to cmark

jgm commented 5 years ago

Never mind, I just fixed this on cmark. The fix will propagate to pandoc after the cmark change floats up to cmark-gfm and then the gfm haskell wrapper.