-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
393a1c1
commit 4ecbdb1
Showing
4 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
hide: | ||
- navigation | ||
--- | ||
|
||
# Usage | ||
|
||
## Basic | ||
|
||
```python | ||
from pymarkdown_builder import MarkdownBuilder | ||
from pymarkdown_builder import Tokens as t | ||
|
||
|
||
builder = ( | ||
MarkdownBuilder() | ||
.lines( | ||
t.h1("pymarkdown-builder"), | ||
t.quote("A Markdown document builder with line and span writing modes."), | ||
) | ||
.br() | ||
.spans( | ||
t.p("A paragraph with an "), | ||
t.link("https://google.com", "inline link"), | ||
t.p(" and a "), | ||
t.bold | "bold " | t.italic | "and italic" | t.italic | t.bold, | ||
) | ||
) | ||
|
||
assert builder.document == "# pymarkdown-builder\n\n> A Markdown document builder with line and span writing modes.\n\nA paragraph with an [inline link](https://google.com) and a **bold *and italic***" | ||
``` | ||
|
||
## Adding more tokens | ||
|
||
You can add more tokens by subclassing the [`Tokens`][pymarkdown_builder.Tokens] class. | ||
|
||
|
||
```python | ||
from pymarkdown_builder import MarkdownBuilder | ||
from pymarkdown_builder import Tokens as BaseTokens | ||
|
||
class Tokens(BaseTokens): | ||
@staticmethod | ||
def inline_python(code: str) -> str: | ||
return f"`#!python {code}`" | ||
|
||
|
||
t = Tokens | ||
|
||
builder = ( | ||
MarkdownBuilder() | ||
.lines( | ||
t.h1("pymarkdown-builder"), | ||
t.inline_python("print('Hello, world!')"), | ||
) | ||
) | ||
|
||
assert builder.document == "# pymarkdown-builder\n\n`#!python print('Hello, world!')`" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters