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

Improve markdown list rendering #2687

Merged

Conversation

Frojdholm
Copy link
Contributor

Render line breaks parsed by the markdown parser.

Before:
python-list

After:
python-list-fixed

@archseer
Copy link
Member

archseer commented Jun 7, 2022

Does that correctly indent multi-level lists? I tried fixing this before but the code needed significantly more changes to track indentation levels (I briefly looked at https://codeberg.org/flausch/mdcat/src/branch/main/src/render.rs)

@the-mikedavis the-mikedavis linked an issue Jun 7, 2022 that may be closed by this pull request
@Frojdholm
Copy link
Contributor Author

Does that correctly indent multi-level lists?

No, though the previous solution doesn't seem to work with it either. I'm writing some tests to investigate that further.

This doesn't actually change how lists work. Rather I think the keyword arguments are not even recognized as lists, but the line endings themselves are converted into line breaks. This change simply inserts line breaks in the same way as line breaks are inserted at the end of for example paragraphs.

@Frojdholm Frojdholm force-pushed the fix-markdown-line-break-rendering branch from e277459 to bb010c3 Compare June 8, 2022 17:42
@Frojdholm
Copy link
Contributor Author

Frojdholm commented Jun 8, 2022

@archseer now it handles nested lists, however it's very brittle since depending on the input source the parser can start inserting paragraphs into the list items.

For example this input

- item 1
    - subitem 1
- item 2
    - subitem 2

- item 1
    - subitem 1

breaks the formatting since paragraphs are inserted into the list items causing extra newlines to be added in the output.

The problem seems pretty complex with tagged events being able to nest almost arbitrarily.

EDIT:
Seems like that input breaks the GitHub formatting as well:

  • item 1

    • subitem 1
  • item 2

    • subitem 2
  • item 1

    • subitem 1

@Frojdholm Frojdholm changed the title Fix markdown line break rendering Improve markdown rendering Jun 8, 2022
@Frojdholm Frojdholm force-pushed the fix-markdown-line-break-rendering branch from bb010c3 to cc86011 Compare June 9, 2022 23:12
Copy link
Contributor Author

@Frojdholm Frojdholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code now handles nested, numbered and multi-paragraph lists. Hard and soft line breaks and multiple paragraphs are indented on a best effort to match the overall indentation of the list.

Two spaces are currently chosen as the default indentation per level, but could be changed.

Known bugs:

  • Fenced code blocks are not working properly inside of lists.

helix-term/src/ui/markdown.rs Outdated Show resolved Hide resolved
@Frojdholm Frojdholm force-pushed the fix-markdown-line-break-rendering branch from cc86011 to f92c861 Compare June 9, 2022 23:18
@Frojdholm Frojdholm marked this pull request as ready for review June 9, 2022 23:18
@Frojdholm Frojdholm force-pushed the fix-markdown-line-break-rendering branch 2 times, most recently from 3126803 to b569cb2 Compare June 10, 2022 16:19
@Frojdholm Frojdholm force-pushed the fix-markdown-line-break-rendering branch from b569cb2 to e34c8e6 Compare June 11, 2022 15:57
@Frojdholm Frojdholm changed the title Improve markdown rendering Improve markdown list rendering Jun 11, 2022
Copy link
Member

@archseer archseer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks

@archseer archseer merged commit 402f285 into helix-editor:master Jun 15, 2022
@Frojdholm Frojdholm deleted the fix-markdown-line-break-rendering branch June 15, 2022 08:32
lazytanuki pushed a commit to lazytanuki/helix that referenced this pull request Jun 21, 2022
* Cleanup old commented code

* Implement line breaks in markdown rendering

* Implement markdown nested, numbered and multiparagraph lists
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

Successfully merging this pull request may close these issues.

Implement soft and hard line breaks in markdown rendering
2 participants