mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
docs and refactor
This commit is contained in:
1
docs/api/markdown.md
Normal file
1
docs/api/markdown.md
Normal file
@@ -0,0 +1 @@
|
||||
::: textual.widgets.Markdown
|
||||
1
docs/api/markdown_viewer.md
Normal file
1
docs/api/markdown_viewer.md
Normal file
@@ -0,0 +1 @@
|
||||
::: textual.widgets.MarkdownViewer
|
||||
28
docs/examples/widgets/markdown.py
Normal file
28
docs/examples/widgets/markdown.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Markdown
|
||||
|
||||
EXAMPLE_MARKDOWN = """\
|
||||
# Markdown Document
|
||||
|
||||
This is an example of Textual's `Markdown` widget.
|
||||
|
||||
## Features
|
||||
|
||||
Markdown syntax and extensions are supported.
|
||||
|
||||
- Typography *emphasis*, **strong**, `inline code` etc.
|
||||
- Headers
|
||||
- Lists (bullet and ordered)
|
||||
- Syntax highlighted code blocks
|
||||
- Tables!
|
||||
"""
|
||||
|
||||
|
||||
class MarkdownExampleApp(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Markdown(EXAMPLE_MARKDOWN)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = MarkdownExampleApp()
|
||||
app.run()
|
||||
60
docs/examples/widgets/markdown_viewer.py
Normal file
60
docs/examples/widgets/markdown_viewer.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import MarkdownViewer
|
||||
|
||||
EXAMPLE_MARKDOWN = """\
|
||||
# Markdown Viewer
|
||||
|
||||
This is an example of Textual's `MarkdownViewer` widget.
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
Markdown syntax and extensions are supported.
|
||||
|
||||
- Typography *emphasis*, **strong**, `inline code` etc.
|
||||
- Headers
|
||||
- Lists (bullet and ordered)
|
||||
- Syntax highlighted code blocks
|
||||
- Tables!
|
||||
|
||||
## Tables
|
||||
|
||||
Tables are displayed in a DataTable widget.
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --------------- | ------ | ------- | ---------------------------------- |
|
||||
| `show_header` | `bool` | `True` | Show the table header |
|
||||
| `fixed_rows` | `int` | `0` | Number of fixed rows |
|
||||
| `fixed_columns` | `int` | `0` | Number of fixed columns |
|
||||
| `zebra_stripes` | `bool` | `False` | Display alternating colors on rows |
|
||||
| `header_height` | `int` | `1` | Height of header row |
|
||||
| `show_cursor` | `bool` | `True` | Show a cell cursor |
|
||||
|
||||
|
||||
## Code Blocks
|
||||
|
||||
Code blocks are syntax highlighted, with guidelines.
|
||||
|
||||
```python
|
||||
class ListViewExample(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield ListView(
|
||||
ListItem(Label("One")),
|
||||
ListItem(Label("Two")),
|
||||
ListItem(Label("Three")),
|
||||
)
|
||||
yield Footer()
|
||||
```
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class MarkdownExampleApp(App):
|
||||
def compose(self) -> ComposeResult:
|
||||
yield MarkdownViewer(EXAMPLE_MARKDOWN, show_toc=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = MarkdownExampleApp()
|
||||
app.run()
|
||||
40
docs/widgets/markdown.md
Normal file
40
docs/widgets/markdown.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Markdown
|
||||
|
||||
A widget to display a Markdown document.
|
||||
|
||||
- [x] Focusable
|
||||
- [ ] Container
|
||||
|
||||
|
||||
!!! tip
|
||||
|
||||
See [MarkdownViewer](./markdown_viewer.md) for a widget that adds additional features such as a Table of Contents.
|
||||
|
||||
## Example
|
||||
|
||||
The following example displays Markdown from a string.
|
||||
|
||||
=== "Output"
|
||||
|
||||
```{.textual path="docs/examples/widgets/markdown.py"}
|
||||
```
|
||||
|
||||
=== "markdown.py"
|
||||
|
||||
~~~python
|
||||
--8<-- "docs/examples/widgets/markdown.py"
|
||||
~~~
|
||||
|
||||
## Messages
|
||||
|
||||
### ::: textual.widgets.Markdown.TOCUpdated
|
||||
|
||||
### ::: textual.widgets.Markdown.TOCSelected
|
||||
|
||||
### ::: textual.widgets.Markdown.LinkClicked
|
||||
|
||||
|
||||
## See Also
|
||||
|
||||
* [Markdown][textual.widgets.Markdown] code reference
|
||||
* [MarkdownViewer][textual.widgets.MarkdownViewer] code reference
|
||||
37
docs/widgets/markdown_viewer.md
Normal file
37
docs/widgets/markdown_viewer.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Markdown Viewer
|
||||
|
||||
A Widget to display Markdown content with an optional Table of Contents.
|
||||
|
||||
- [x] Focusable
|
||||
- [ ] Container
|
||||
|
||||
!!! note
|
||||
|
||||
This Widget adds browser-like functionality on top of the [Markdown](./markdown.md) widget.
|
||||
|
||||
|
||||
## Example
|
||||
|
||||
The following example displays Markdown from a string and a Table of Contents.
|
||||
|
||||
=== "Output"
|
||||
|
||||
```{.textual path="docs/examples/widgets/markdown_viewer.py" columns="100" lines="42"}
|
||||
```
|
||||
|
||||
=== "markdown.py"
|
||||
|
||||
~~~python
|
||||
--8<-- "docs/examples/widgets/markdown_viewer.py"
|
||||
~~~
|
||||
|
||||
## Reactive Attributes
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| ---------- | ---- | ------- | ----------------------------------------------------------------- |
|
||||
| `show_toc` | bool | True | Wether a Table of Contents should be displayed with the Markdown. |
|
||||
|
||||
## See Also
|
||||
|
||||
* [MarkdownViewer][textual.widgets.MarkdownViewer] code reference
|
||||
* [Markdown][textual.widgets.Markdown] code reference
|
||||
Reference in New Issue
Block a user