Initial very WIP commit.
This commit is contained in:
commit
4ca04d8202
4 changed files with 67 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
**/__pycache__
|
35
formatitko.py
Normal file
35
formatitko.py
Normal file
|
@ -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))
|
||||||
|
|
||||||
|
|
19
test.md
Normal file
19
test.md
Normal file
|
@ -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 -->
|
||||||
|
|
||||||
|
|
12
whitespace.py
Normal file
12
whitespace.py
Normal file
|
@ -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 a new issue