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 wrapped - orig_elem (
panflute.base.Element
) – Original element
Return type: Returns: elem
orelem
wrapped inpanflute.elements.Plain
- elem (
-
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.Example: >>> destringify('foo bar baz') [Str(foo), Space, Str(bar), Space, Str(baz)]
Parameters: string (str) – String to transform
Return type: Returns: list of
panflute.Str
andpanflute.Space
-
innoconv_mintmod.utils.
extract_identifier
(content)[source]¶ Extract identifier from content and remove annotation element.
\MLabel
commands that occur within environments are parsed in a child process (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. This function extracts the identifier and removes the annotation element.Parameters: content (list) – List of elements Return type: (list, str) Returns: updated content list and identifier (might be None
)
-
innoconv_mintmod.utils.
get_remembered_element
(doc)[source]¶ Retrieve rememembered element from the document and forget it.
To remember elements use
remember_element()
.Parameters: doc ( panflute.elements.Doc
) – Document where the element is storedReturn type: panflute.base.Element
Returns: The remembered element or None
-
innoconv_mintmod.utils.
log
(msg_string, level='INFO')[source]¶ Log messages when running as a panzer filter.
Parameters:
-
innoconv_mintmod.utils.
parse_cmd
(text)[source]¶ Parse a LaTeX command using regular expressions.
Parses a command like:
\foo{bar}{baz}
Parameters: text (str) – String to parse Return type: (str, list) Returns: command name and list of command arguments
-
innoconv_mintmod.utils.
parse_fragment
(parse_string, as_doc=False, from_format='latex+raw_tex')[source]¶ Parse a source fragment using panzer.
Parameters: - parse_string (str) – Source fragment
- as_doc (bool) – Return elements as
panflute.elements.Doc
- from_format (str) – Source format
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']
.Parameters: to_parse (str) – String to parse Return type: (list, str) Returns: parsed arguments and rest string
-
innoconv_mintmod.utils.
remember_element
(doc, elem)[source]¶ Rememember an element in the document for later.
To retrieve remembered elements use
get_remembered_element()
.Parameters: - doc (
panflute.elements.Doc
) – Document where to store the memory - elem (
panflute.base.Element
) – Element to remember
- doc (
-
innoconv_mintmod.utils.
remove_empty_paragraphs
(doc)[source]¶ Remove empty paragraphs from document.
Parameters: doc ( panflute.elements.Doc
) – Document