Skip to content

Commit

Permalink
Continue refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
chdemko committed Apr 8, 2024
1 parent 7245ddf commit 17b5b5e
Showing 1 changed file with 27 additions and 40 deletions.
67 changes: 27 additions & 40 deletions pandoc_numbering/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,9 @@ def meta_cite(category, definition, defined):
)


# pylint:disable=too-many-branches
def meta_listing(category, definition, defined):
def meta_format(category, definition, defined, tag):
"""
Compute listing for a category.
Compute format text for a category and a tag.
Arguments
---------
Expand All @@ -1095,17 +1094,36 @@ def meta_listing(category, definition, defined):
The definition
defined
The defined parameter
tag
The tag parameter
"""
if "listing-title" in definition:
if isinstance(definition["listing-title"], MetaInlines):
defined[category]["listing-title"] = definition["listing-title"].content
if tag in definition:
if isinstance(definition[tag], MetaInlines):
# Detach from original parent
defined[category]["listing-title"].parent = None
defined[category][tag] = definition[tag].content
defined[category][tag].parent = None
else:
debug(
"[WARNING] pandoc-numbering: listing-title is not correct for category "
+ category
f"[WARNING] pandoc-numbering: "
f"{tag} is not correct for category {category}"
)


# pylint:disable=too-many-branches
def meta_listing(category, definition, defined):
"""
Compute listing for a category.
Arguments
---------
category
The category
definition
The definition
defined
The defined parameter
"""
meta_format(category, definition, defined, "listing-title")
for key in ("listing-unnumbered", "listing-unlisted"):
if key in definition:
if isinstance(definition[key], MetaBool):
Expand Down Expand Up @@ -1135,33 +1153,6 @@ def meta_listing(category, definition, defined):
)


def meta_format(category, definition, defined, tag):
"""
Compute format text for a category and a tag.
Arguments
---------
category
The category
definition
The definition
defined
The defined parameter
tag
The tag parameter
"""
if tag in definition:
if isinstance(definition[tag], MetaInlines):
# Detach from original parent
defined[category][tag] = definition[tag].content
defined[category][tag].parent = None
else:
debug(
f"[WARNING] pandoc-numbering: "
f"{tag} is not correct for category {category}"
)


def meta_format_text(category, definition, defined):
"""
Compute format text for a category.
Expand Down Expand Up @@ -1607,7 +1598,3 @@ def main(doc=None) -> None:
pandoc document
"""
run_filters([numbering, referencing], prepare=prepare, doc=doc, finalize=finalize)


if __name__ == "__main__":
main()

0 comments on commit 17b5b5e

Please sign in to comment.