You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
615 B

#!/usr/bin/env python3
# Import local files
from whitespace import *
from panflute import *
from mj_show import show
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(show(doc))
transform(doc)
print("---------------------")
print(show(doc))
print(vars(doc))