Skip to content

Commit

Permalink
docs: add more usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
demetrius-mp committed Jul 10, 2023
1 parent 393a1c1 commit 4ecbdb1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pip install pymarkdown-builder

## Usage

> For more examples, see the [documentation](https://pymarkdown-builder.readthedocs.io/en/latest/usage).
```python
from pymarkdown_builder import MarkdownBuilder
from pymarkdown_builder import Tokens as t
Expand All @@ -32,6 +34,7 @@ builder = (
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"),
Expand All @@ -40,7 +43,7 @@ builder = (
)
)

assert builder.document == "# pymarkdown-builder\n\n> A Markdown document builder with line and span writing modes.A paragraph with an [inline link](https://google.com) and a **bold *and italic***"
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***"
```

## License
Expand Down
5 changes: 4 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pip install pymarkdown-builder

## Usage

> For more examples, see the [documentation](https://pymarkdown-builder.readthedocs.io/en/latest/usage).
```python
from pymarkdown_builder import MarkdownBuilder
from pymarkdown_builder import Tokens as t
Expand All @@ -37,6 +39,7 @@ builder = (
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"),
Expand All @@ -45,7 +48,7 @@ builder = (
)
)

assert builder.document == "# pymarkdown-builder\n\n> A Markdown document builder with line and span writing modes.A paragraph with an [inline link](https://google.com) and a **bold *and italic***"
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***"
```

## License
Expand Down
59 changes: 59 additions & 0 deletions docs/usage.md
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!')`"
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ markdown_extensions:
nav:
- Home: index.md
- Contribute: contribute.md
- Usage: usage.md
- API: api/

plugins:
Expand Down

0 comments on commit 4ecbdb1

Please sign in to comment.