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

[BUG] Incorrect ordering of markdown elements #1036

Closed
aroberge opened this issue Feb 21, 2021 · 6 comments
Closed

[BUG] Incorrect ordering of markdown elements #1036

aroberge opened this issue Feb 21, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@aroberge
Copy link

Read the docs
I didn't see this bug mentioned ... nor would I expect you not to know about it and not fix it! ;-)

Describe the bug
When a markdown file contains a indented block after an itemized list, the content of the indented block is shown before the itemized list.

To Reproduce
A minimal code example that reproduces the problem would be a big help if you can provide it. If the issue is visual in nature, consider posting a screenshot.

Here's the content of a simple markdown file:

This is a test.

1. first item
2. second item

       code block

Normal text

Here is how Rich renders it:

This is a test.

┌─────────────────────────────────────────────────────────────────┐
│ code block                                                      │
└─────────────────────────────────────────────────────────────────┘

 1 first item
 2 second item

Normal text

Platform
Windows, Windows terminal

Diagnose
I may ask you to cut and paste the output of the following commands. It may save some time if you do it now.

╭──────────────── <class 'rich.console.Console'> ─────────────────╮
│ A high level console interface.                                 │
│                                                                 │
│ ╭─────────────────────────────────────────────────────────────╮ │
│ │ <console width=67 ColorSystem.TRUECOLOR>                    │ │
│ ╰─────────────────────────────────────────────────────────────╯ │
│                                                                 │
│     color_system = 'truecolor'                                  │
│         encoding = 'utf-8'                                      │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w'  │
│                    encoding='utf-8'>                            │
│           height = 41                                           │
│ is_dumb_terminal = False                                        │
│   is_interactive = True                                         │
│       is_jupyter = False                                        │
│      is_terminal = True                                         │
│   legacy_windows = False                                        │
│         no_color = False                                        │
│          options = ConsoleOptions(size=ConsoleDimensions(width… │
│                    height=41), legacy_windows=False,            │
│                    min_width=1, max_width=67, is_terminal=True, │
│                    encoding='utf-8', justify=None,              │
│                    overflow=None, no_wrap=False,                │
│                    highlight=None, height=None)                 │
│            quiet = False                                        │
│           record = False                                        │
│         safe_box = True                                         │
│             size = ConsoleDimensions(width=67, height=41)       │
│        soft_wrap = False                                        │
│           stderr = False                                        │
│            style = None                                         │
│         tab_size = 8                                            │
│            width = 67                                           │
╰─────────────────────────────────────────────────────────────────╯

platform="Windows"
WindowsConsoleFeatures(vt=True, truecolor=True)

Rich version 9.11.0

Did I help?

If I was able to resolve your problem, consider sponsoring my work on Rich, or buy me a coffee to say thanks.

@willmcgugan willmcgugan added bug Something isn't working and removed Needs triage labels Feb 21, 2021
@willmcgugan
Copy link
Collaborator

Could be a bug in commonmark lib. But equally likely to be in Rich. Strange one though. What happens if you put an extra blank line after the list?

@aroberge
Copy link
Author

Same result with extra blank line.

The following:

This is a test.

1. first item
2. second item

   item


       code block

Normal text

yields

This is a test.

┌─────────────────────────────────────────────────────────────────┐
│ code block                                                      │
└─────────────────────────────────────────────────────────────────┘

 1 first item
 2 second item
   item

Normal text

Leaving the last line (Normal text) out does not change the result.

@willmcgugan
Copy link
Collaborator

willmcgugan commented Feb 21, 2021

Hi André,

Looks like this is a bug in commonmark, but it's a weird one.

The HTML output from commonmark appears to work, i.e. the code block is after the list, where you would expect. But looking at the HTML source, I can see the code block is inside the second list item, which is incorrect. The browser is fixing that because block level elements shouldn't go inside <p> tags -- and the end result looks ok.

I think this explains why the developers never saw it, because the output in the browser looks fine. I'll report that upstream, and hopefully they will fix it there.

BTW, thanks for the ko-fi!

@willmcgugan
Copy link
Collaborator

Understanding this a bit more. Tested with https://spec.commonmark.org/dingus/ and I now realise that the code block should go in side the second item of the list. The commonmark lib does generate the correct HTML, so I'm not sure why the order is wrong in Rich.

@willmcgugan
Copy link
Collaborator

Think I have a fix. Please try 9.12.0

@aroberge
Copy link
Author

It works with my test file, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants