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`.
|
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
|
## 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.
|
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.
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ class MarkdownBullet(Widget):
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
symbol = reactive("● ")
|
symbol = reactive("●")
|
||||||
"""The symbol for the bullet."""
|
"""The symbol for the bullet."""
|
||||||
|
|
||||||
def render(self) -> Text:
|
def render(self) -> Text:
|
||||||
@@ -381,6 +381,14 @@ class MarkdownListItem(MarkdownBlock):
|
|||||||
self._blocks.clear()
|
self._blocks.clear()
|
||||||
|
|
||||||
|
|
||||||
|
class MarkdownOrderedListItem(MarkdownListItem):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MarkdownUnorderedListItem(MarkdownListItem):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MarkdownFence(MarkdownBlock):
|
class MarkdownFence(MarkdownBlock):
|
||||||
"""A fence Markdown block."""
|
"""A fence Markdown block."""
|
||||||
|
|
||||||
@@ -452,6 +460,8 @@ class Markdown(Widget):
|
|||||||
"""
|
"""
|
||||||
COMPONENT_CLASSES = {"em", "strong", "s", "code_inline"}
|
COMPONENT_CLASSES = {"em", "strong", "s", "code_inline"}
|
||||||
|
|
||||||
|
BULLETS = ["⏺ ", "■ ", "• ", "‣ "]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
markdown: str | None = None,
|
markdown: str | None = None,
|
||||||
@@ -548,8 +558,15 @@ class Markdown(Widget):
|
|||||||
elif token.type == "ordered_list_open":
|
elif token.type == "ordered_list_open":
|
||||||
stack.append(MarkdownOrderedList())
|
stack.append(MarkdownOrderedList())
|
||||||
elif token.type == "list_item_open":
|
elif token.type == "list_item_open":
|
||||||
|
item_count = sum(
|
||||||
|
1 for block in stack if isinstance(block, MarkdownUnorderedListItem)
|
||||||
|
)
|
||||||
stack.append(
|
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":
|
elif token.type == "table_open":
|
||||||
stack.append(MarkdownTable())
|
stack.append(MarkdownTable())
|
||||||
|
|||||||
Reference in New Issue
Block a user