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

Markdown to formatted text #1604

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions examples/print-text/markdown-sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Heading

## Sub-heading

## Long heading with lots of words which will wrap the words onto multiple lines on a narrow screen

*Italic*, **bold**, `code`, ~~strikethrough~~.

Inline [hyperlinks](https://python-prompt-toolkit.readthedocs.io/) and images ![](https://python-prompt-toolkit.readthedocs.io/en/master/_static/logo_400px.png) inline too.

> Quote blocks

- Lists
- Sublists

1. Numbered
2. lists
1. with
3. sublists

---

| **Table** | Header | Row |
|:-------------|:------:|---------:|
| Left | Centre | Right |
| *Formatting* | **in** | `tables` |


```python
def code_blocks():
print("Hello world!")
```

Fin.
93 changes: 93 additions & 0 deletions src/prompt_toolkit/border.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""Defines borders."""

from abc import ABCMeta


class Border(metaclass=ABCMeta):
"""Base border type."""

TOP_LEFT: str
TOP_SPLIT: str
TOP_RIGHT: str
HORIZONTAL: str
VERTICAL: str
LEFT_SPLIT: str
RIGHT_SPLIT: str
CROSS: str
BOTTOM_LEFT: str
BOTTOM_SPLIT: str
BOTTOM_RIGHT: str


class NoBorder(Border):
"""Invisible border."""

TOP_LEFT = " "
TOP_SPLIT = " "
TOP_RIGHT = " "
HORIZONTAL = " "
INNER_VERTICAL = " "
VERTICAL = " "
LEFT_SPLIT = " "
RIGHT_SPLIT = " "
CROSS = " "
BOTTOM_LEFT = " "
BOTTOM_SPLIT = " "
BOTTOM_RIGHT = " "


class SquareBorder(Border):
"""Square thin border."""

TOP_LEFT = "┌"
TOP_SPLIT = "┬"
TOP_RIGHT = "┐"
HORIZONTAL = "─"
VERTICAL = "│"
LEFT_SPLIT = "├"
RIGHT_SPLIT = "┤"
CROSS = "┼"
BOTTOM_LEFT = "└"
BOTTOM_SPLIT = "┴"
BOTTOM_RIGHT = "┘"


class RoundBorder(SquareBorder):
"""Thin border with round corners."""

TOP_LEFT = "╭"
TOP_RIGHT = "╮"
BOTTOM_LEFT = "╰"
BOTTOM_RIGHT = "╯"


class DoubleBorder(Border):
"""Square border with double lines."""

TOP_LEFT = "╔"
TOP_SPLIT = "╦"
TOP_RIGHT = "╗"
HORIZONTAL = "═"
VERTICAL = "║"
LEFT_SPLIT = "╠"
RIGHT_SPLIT = "╣"
CROSS = "╬"
BOTTOM_LEFT = "╚"
BOTTOM_SPLIT = "╩"
BOTTOM_RIGHT = "╝"


class ThickBorder(Border):
"""Square border with thick lines."""

TOP_LEFT = "┏"
TOP_SPLIT = "┳"
TOP_RIGHT = "┓"
HORIZONTAL = "━"
VERTICAL = "┃"
LEFT_SPLIT = "┣"
RIGHT_SPLIT = "┫"
CROSS = "╋"
BOTTOM_LEFT = "┗"
BOTTOM_SPLIT = "┻"
BOTTOM_RIGHT = "┛"
3 changes: 3 additions & 0 deletions src/prompt_toolkit/formatted_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
to_formatted_text,
)
from .html import HTML
from .markdown import Markdown
from .pygments import PygmentsTokens
from .utils import (
fragment_list_len,
Expand All @@ -45,6 +46,8 @@
"ANSI",
# Pygments.
"PygmentsTokens",
# Markdown
"Markdown",
# Utils.
"fragment_list_len",
"fragment_list_width",
Expand Down
Loading