|
|
@ -75,7 +75,7 @@ def transform(e: Element, c: Context) -> Element: # Returns next sibling element |
|
|
|
## Shorthands |
|
|
|
if isinstance(e, Span) and len(e.content) == 1 and isinstance(e.content[0], Str): |
|
|
|
## Handle special command shorthand [!commandname]{} |
|
|
|
if re.match(r"^![\w.]+$", e.content[0].text): |
|
|
|
if re.match(r"^![\w]+$", e.content[0].text): |
|
|
|
e = InlineCommand(identifier=e.identifier, classes=e.classes, attributes={**e.attributes, "c": e.content[0].text[1:]}) |
|
|
|
|
|
|
|
## Handle import [#path/file.md]{} |
|
|
@ -86,6 +86,19 @@ def transform(e: Element, c: Context) -> Element: # Returns next sibling element |
|
|
|
importedDoc.walk(transform, c) |
|
|
|
return nullify(e) |
|
|
|
|
|
|
|
## Handle metadata print [$something.something]{} |
|
|
|
elif re.match(r"^\$[\w.]+$", e.content[0].text): |
|
|
|
val = c.get_metadata(e.content[0].text[1:], False) |
|
|
|
if isinstance(val, MetaInlines): |
|
|
|
e = Span(*val.content) |
|
|
|
e = e.walk(transform, c) |
|
|
|
elif isinstance(val, MetaString): |
|
|
|
e = Span(Str(val.string)) |
|
|
|
elif isinstance(val, MetaBool): |
|
|
|
e = Span(Str(str(val.boolean))) |
|
|
|
else: |
|
|
|
raise ValueError(f"Cannot print value of metadatum {e.content[0].text[1:]}") |
|
|
|
|
|
|
|
## Execute commands |
|
|
|
# panflute's walk transforms the children first, then the root element, so |
|
|
|
# the content of the element the command receives is already transformed. |
|
|
|