Skip to content

Commit

Permalink
Detect pandoc api version
Browse files Browse the repository at this point in the history
  • Loading branch information
chdemko committed Jul 30, 2023
1 parent b2b1809 commit 6794faa
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pandoc_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)


# pylint: disable=broad-exception-caught,unused-argument
# pylint: disable=broad-exception-caught
def figure(elem, doc):
"""
Transform a div element into a figure element.
Expand All @@ -32,7 +32,8 @@ def figure(elem, doc):
Figure or None.
"""
if (
isinstance(elem, Div)
doc.api_version >= (1, 23)
and isinstance(elem, Div)
and "figure" in elem.classes
and "caption" in elem.attributes
):
Expand All @@ -52,6 +53,23 @@ def figure(elem, doc):
return None


def prepare(doc):
"""
Prepare the pandoc document.
Arguments
---------
doc
The pandoc document
"""
if doc.api_version < (1, 23):
debug(
f"[WARNING] pandoc-figure: pandoc api version "
f"{'.'.join(str(value) for value in doc.api_version)} "
"is not compatible"
)


def main(doc=None):
"""
Convert the pandoc document.
Expand All @@ -65,7 +83,7 @@ def main(doc=None):
-------
The modified pandoc document
"""
return run_filter(figure, doc=doc)
return run_filter(figure, prepare=prepare, doc=doc)


if __name__ == "__main__":
Expand Down

0 comments on commit 6794faa

Please sign in to comment.