-
Notifications
You must be signed in to change notification settings - Fork 826
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
The Markdown
widget isn't handling ordered lists correctly
#2002
Comments
Trying the live demo it looks like that does the right thing; which would suggest that the handling of this might need to be done in the code that uses the library (I'm not saying that for certain; just that on the surface it suggests that). |
Rendering html as shown in the live demo would only involve creating the appropriate According to the docs for So possibly the code here is actually just using the number from the original? ...
for token in parser.parse(markdown):
...
elif token.type == "list_item_open":
if token.info:
stack.append(MarkdownOrderedListItem(f"{token.info}. ")) |
Yup, I think we'll need to pull out the initial value and do some increment of our own. |
I suppose an alternative if you wanted to avoid adding your own code to handle this would be to run the markdown through a formatter before trying to parse it? I haven't read the docs in much detail yet but something like... import mdformat
unformatted = """
1. One
1. Two
1. Three
1. Four
1. Five
"""
formatted = mdformat.text(
unformatted,
options={
"number": True, # switch on consecutive numbering of ordered lists
},
)
print(formatted)
# 1. One
# 2. Two
# 3. Three
# 4. Four
# 5. Five |
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
In Markdown the number prefix for an item in an ordered list normally isn't important. Every item can start with any valid numeric value; rendering will have them as an ordered sequence of numbers starting with the number of the first item.
For example:
comes out as:
However, in our
Markdown
widget at the moment, it appears like this:This may be down to the underlying markdown parser we're using. It says it conforms to the CommonMark specification, and that specification does state:
so either we need to do something at our end to do that or enable that, or we may need to raise an issue upstream.
The text was updated successfully, but these errors were encountered: