Browse Source

Initial very WIP commit.

pull/28/head
Jan Černohorský 2 years ago
commit
4ca04d8202
  1. 1
      .gitignore
  2. 35
      formatitko.py
  3. 19
      test.md
  4. 12
      whitespace.py

1
.gitignore

@ -0,0 +1 @@
**/__pycache__

35
formatitko.py

@ -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

@ -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

@ -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…
Cancel
Save