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

Keep leading spaces in paragraphs when there's a list #290

Closed
wants to merge 1 commit into from

Conversation

AfzalivE
Copy link

@AfzalivE AfzalivE commented Apr 7, 2023

When there are no blockParserFactories, leading spaces should be preserved. Here's a use case:

Input

- one
  - two

When this is parsed with a Parser without any enabledBlockTypes, before this PR, it results in this:

- one
- two

But it should preserve the list hierarchy with the leading whitespace.

@AfzalivE
Copy link
Author

@robinst Would you please be able to review this?

@AfzalivE
Copy link
Author

Ping @robinst, would you please be able to review this? Thanks!

@robinst
Copy link
Collaborator

robinst commented Mar 9, 2024

Note that this doesn't really have anything to do with lists, it's the same for a paragraph like this:

aaa
  bbb
    ccc

The reason for this is in the spec, leading spaces are skipped: https://spec.commonmark.org/0.31.2/#example-222
Final spaces in a paragraph are also skipped, see here: https://spec.commonmark.org/0.31.2/#example-226

Having said that, we should probably have a way to preserve these skipped spaces in the nodes somehow. Some ideas:

  • Add a SkippedSpaces node that HTML rendering ignores but other renderers can make use of (e.g. the new MarkdownRenderer might also want to render it).
  • Add some properties to Text nodes to indicate any leading/trailing spaces. Not sure how feasible this is with how inline parsing works. Not sure if Text would be enough, what if the line starts/ends with an inline element (e.g. emphasis, link etc).
  • Add some properties to Paragraph nodes to indicate any leading/trailing spaces. This would have to store the line numbers somehow, and might not be super convenient to consume.

We also need to consider interaction with e.g. getMarkerIndent on ListItem. Maybe that could be replaced by whatever we build for this if it's generic enough.

@robinst
Copy link
Collaborator

robinst commented Mar 12, 2024

Closing this as it's not the right approach, see comment above and #301.

@robinst robinst closed this Mar 12, 2024
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.

2 participants