Jan Černohorský
2 years ago
commit
4ca04d8202
4 changed files with 67 additions and 0 deletions
@ -0,0 +1 @@ |
|||||
|
**/__pycache__ |
@ -0,0 +1,35 @@ |
|||||
|
#!/usr/bin/env python3 |
||||
|
|
||||
|
# Import local files |
||||
|
from whitespace import * |
||||
|
|
||||
|
from panflute import * |
||||
|
|
||||
|
|
||||
|
ifs = ["dog"] |
||||
|
|
||||
|
|
||||
|
def transform(e: Element): |
||||
|
"""Transform the AST, making format-agnostic changes.""" |
||||
|
if isinstance(e, Whitespace) and bavlna(e): |
||||
|
e.parent.content[e.index] = NBSP() |
||||
|
|
||||
|
if hasattr(e, "attributes"): |
||||
|
if "if" in e.attributes: |
||||
|
if not e.attributes["if"] in ifs: |
||||
|
del e.parent.content[e.index] |
||||
|
|
||||
|
if hasattr(e, "content"): |
||||
|
for c in e.content: |
||||
|
transform(c) |
||||
|
|
||||
|
|
||||
|
doc = load() |
||||
|
|
||||
|
print(stringify(doc)) |
||||
|
transform(doc) |
||||
|
print("---------------------") |
||||
|
print(stringify(doc)) |
||||
|
print(vars(doc)) |
||||
|
|
||||
|
|
@ -0,0 +1,19 @@ |
|||||
|
# Hello world! |
||||
|
|
||||
|
This is an *example* **yay**! |
||||
|
|
||||
|
```python3 |
||||
|
def what(): |
||||
|
return no way |
||||
|
``` |
||||
|
:::{if=cat} |
||||
|
This should only be shown to cats |
||||
|
::: |
||||
|
|
||||
|
This should be seen by all. |
||||
|
|
||||
|
[This too!]{if=cat} |
||||
|
|
||||
|
[!woah]{a=b} <!-- A special command! WOW --> |
||||
|
|
||||
|
|
@ -0,0 +1,12 @@ |
|||||
|
from panflute import Space,SoftBreak |
||||
|
from typing import Union |
||||
|
|
||||
|
Whitespace = Union[Space,SoftBreak] |
||||
|
|
||||
|
class NBSP(Space): |
||||
|
pass |
||||
|
|
||||
|
def bavlna(e: Whitespace): |
||||
|
"""Determine if given piece of whitespace should be non-breakable.""" |
||||
|
return False |
||||
|
|
Loading…
Reference in new issue