KyleKing/mdformat-mkdocs

nested bullet points do not correctly implement integer word wrapping

acriphonic opened this issue · 6 comments

This is the output when wrap = 80:

- Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tes
    Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tested
    Te
    - Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test
        Test Test Test Test Test Test Test Test Test Test Test Test Test Test Te Tes
    - Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test
        Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tes Te

The second line of the non-nested bullet point gets formatted correctly. However, the second lines of both nested bullet points are 84 characters, with both "Tes" and "Te" beginning at 81 and 82.

For fun, I also checked with numbered lists (example slightly modified in length due to - being one less character than 1.)

This also affects numbered lists if align-semantic-breaks is not enabled:

1. Test
    1. Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tes
        Test Test Test Test Test Test Test Test Test Test Test Test Test Test Te
        Te
    1. Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tes
        Test Test Test Test Test Test Test Test Test Test Test Test Test Test Te T
    1. Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tes
        Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test

The second line of the second and third nested list items not handled correctly, though the second line of the first bullet point is. So it seems to be affected, but has a slightly different error cutoff due to the extra character in the 1. over the -.

However, this does not affect numbered lists if align-semantic-breaks is enabled:

1. Test
    1. Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tes
        Test Test Test Test Test Test Test Test Test Test Test Test Test Test Te
        Tes
    1. Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tes
        Test Test Test Test Test Test Test Test Test Test Test Test Test Test Tes
        Te

Thank you very much :)

Thanks for reporting the issue and trying out the plugin

This might be a problem with mdformat rather than here, but I'll take a look this week and try to replicate the bug and add some tests

Okay, I can replicate the behavior you've described. I've been testing:

# Content

- Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Tested Test
    - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Tested Test
    - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Tested Test 

1. Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Tested Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Tested Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st Tested Test

Which formats with mdformat tmp.md --wrap=80 to:

# Content

- Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
    Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
    Tested Test
    - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test
    - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test

1. Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test

Or with mdformat tmp.md --align-semantic-breaks-in-lists --wrap=80 to:

# Content

- Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
  Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
  Tested Test
    - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Tested Test
    - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Tested Test

1. Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
       Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
       Tested Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
       Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
       Tested Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
       Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
       Tested Test

Which ends up with lines longer than the specified wrap length

> mdformat --version
mdformat 0.7.16 (mdformat_tables: 0.4.1, mdformat_gfm: 0.3.5, mdformat_mkdocs: 1.0.3)

I can verify that installing mdformat-mkdocs breaks the word wrap logic:

> mdformat --version
mdformat 0.7.16 (mdformat_tables: 0.4.1, mdformat_gfm: 0.3.5)
# Content

- Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
  Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
  Tested Test
  - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
    Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
    Tested Test
  - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
    Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
    Tested Test

1. Test
   1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Tested Test
   1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Tested Test
   1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
      Tested Test
> pipx inject mdformat mdformat-mkdocs
  injected package mdformat-mkdocs into venv mdformat
done! ✨ 🌟 ✨
> mdformat --version
mdformat 0.7.16 (mdformat_tables: 0.4.1, mdformat_gfm: 0.3.5, mdformat_mkdocs: 1.0.3)
# Content

- Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
    Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
    Tested Test
    - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test
    - Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test

1. Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test
    1. Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Test Test Test Test T5st Test Test Test Test T5st Test Test Test Test T5st
        Tested Test

When adding the additional indents, I'm not accounting for how that impacts word wrap. I'll take a look at the mdformat implementation and will open a PR to fix mdformat-mkdocs

This isn't optimal and there are probably some missing edge cases, but word wrap should now stay within the specified max based on changes in #11

@acriphonic let me know when you have a chance to try 1.0.4rc2 from: https://pypi.org/project/mdformat_mkdocs/1.0.4rc2

If you have any questions about installing the release candidate version let me know how you have mdformat-mkdocs installed. For example, with pre-commit:

    - repo: https://github.com/executablebooks/mdformat
      rev: 0.7.16
      hooks:
          - id: mdformat
            additional_dependencies:
                - mdformat-mkdocs>=1.0.4rc2

I haven't heard back, so I'll assume this issue is resolved with the changes for v1.0.4. Feel free to reopen if you run into any issues