mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
list item improvements
This commit is contained in:
@@ -42,6 +42,22 @@ Two tildes indicates strikethrough, e.g. `~~cross out~~` render ~~cross out~~.
|
||||
|
||||
Inline code is indicated by backticks. e.g. `import this`.
|
||||
|
||||
## Lists
|
||||
|
||||
1. Lists can be ordered
|
||||
2. Lists can be unordered
|
||||
- Foo
|
||||
- Bar
|
||||
- Jessica
|
||||
- Reg
|
||||
- Green
|
||||
- January
|
||||
- February
|
||||
- March
|
||||
- Blue
|
||||
- Paul
|
||||
- Baz
|
||||
|
||||
## Fences
|
||||
|
||||
Fenced code blocks are introduced with three back-ticks and the optional parser. Here we are rendering the code in a sub-widget with syntax highlighting and indent guides.
|
||||
|
||||
@@ -381,6 +381,14 @@ class MarkdownListItem(MarkdownBlock):
|
||||
self._blocks.clear()
|
||||
|
||||
|
||||
class MarkdownOrderedListItem(MarkdownListItem):
|
||||
pass
|
||||
|
||||
|
||||
class MarkdownUnorderedListItem(MarkdownListItem):
|
||||
pass
|
||||
|
||||
|
||||
class MarkdownFence(MarkdownBlock):
|
||||
"""A fence Markdown block."""
|
||||
|
||||
@@ -452,6 +460,8 @@ class Markdown(Widget):
|
||||
"""
|
||||
COMPONENT_CLASSES = {"em", "strong", "s", "code_inline"}
|
||||
|
||||
BULLETS = ["⏺ ", "■ ", "• ", "‣ "]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
markdown: str | None = None,
|
||||
@@ -548,8 +558,15 @@ class Markdown(Widget):
|
||||
elif token.type == "ordered_list_open":
|
||||
stack.append(MarkdownOrderedList())
|
||||
elif token.type == "list_item_open":
|
||||
item_count = sum(
|
||||
1 for block in stack if isinstance(block, MarkdownUnorderedListItem)
|
||||
)
|
||||
stack.append(
|
||||
MarkdownListItem(f"{token.info}. " if token.info else "● ")
|
||||
MarkdownOrderedListItem(f" {token.info}. ")
|
||||
if token.info
|
||||
else MarkdownUnorderedListItem(
|
||||
self.BULLETS[item_count % len(self.BULLETS)]
|
||||
)
|
||||
)
|
||||
elif token.type == "table_open":
|
||||
stack.append(MarkdownTable())
|
||||
|
||||
Reference in New Issue
Block a user