innoconv_mintmod.utils¶
Utility module
-
innoconv_mintmod.utils.
block_wrap
(elem, orig_elem)[source]¶ Wraps an element in a block if necessary.
If the original element was block panflute expects the return value to be also block. In many places we need to detect this and wrap an inline.
- Parameters
elem (
panflute.base.Element
) – Element to be wrappedorig_elem (
panflute.base.Element
) – Original element
- Return type
- Returns
elem
orelem
wrapped inpanflute.elements.Plain
-
innoconv_mintmod.utils.
convert_simplification_code
(code)[source]¶ Convert binary flags to string flags.
-
innoconv_mintmod.utils.
destringify
(string)[source]¶ Takes a string and transforms it into list of Str and Space objects.
This function breaks down strings with whitespace. It could be done by calling
parse_fragment()
but doesn’t have the overhead involed.
-
innoconv_mintmod.utils.
extract_identifier
(content)[source]¶ Extract identifier from content and remove annotation element.
\MLabel
/MDeclareSiteUXID
commands that occur within environments are parsed in a child process (e.g.innoconv_mintmod.mintmod_filter.commands.handle_mlabel()
). The id attribute can’t be set directly as they can’t access the whole doc tree. As a workaround they create a fake element and add the identifier.
-
innoconv_mintmod.utils.
get_remembered
(doc, key, keep=False)[source]¶ Retrieve rememembered element from the document and forget it.
To remember elements use
remember()
.- Parameters
- Return type
- Returns
The remembered element or None
-
innoconv_mintmod.utils.
log
(msg_string, level='INFO')[source]¶ Log messages when running as a panzer filter.
-
innoconv_mintmod.utils.
parse_cmd
(text)[source]¶ Parse a LaTeX command using regular expressions.
Parses a command like:
\foo{bar}{baz}
-
innoconv_mintmod.utils.
parse_fragment
(parse_string, lang, as_doc=False, from_format='latex+raw_tex')[source]¶ Parse a source fragment using panzer.
- Parameters
- Return type
list of
panflute.base.Element
orpanflute.elements.Doc
- Returns
parsed elements
- Raises
OSError – if panzer executable is not found
RuntimeError – if panzer recursion depth is exceeded
RuntimeError – if panzer output could not be parsed
-
innoconv_mintmod.utils.
parse_nested_args
(to_parse)[source]¶ Parse LaTeX command arguments that can have nested commands. Returns arguments and rest string.
Parses strings like:
{bar}{baz{}}rest
into[['bar', 'baz{}'], 'rest']
.
-
innoconv_mintmod.utils.
remember
(doc, key, elem)[source]¶ Rememember an element in the document for later.
To retrieve remembered elements use
get_remembered()
.- Parameters
doc (
panflute.elements.Doc
) – Document where to store the memorykey (str) – Key under which element is stored
elem (
panflute.base.Element
) – Element to remember
-
innoconv_mintmod.utils.
remove_annotations
(doc)[source]¶ Remove left-over annotation elements from document.
- Parameters
doc (
panflute.elements.Doc
) – Document