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
Return type

panflute.base.Element

Returns

elem or elem wrapped in panflute.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.

Example
>>> destringify('foo  bar       baz')
[Str(foo), Space, Str(bar), Space, Str(baz)]
Parameters

string (str) – String to transform

Return type

list

Returns

list of panflute.Str and panflute.Space

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.

Parameters

content (list) – List of elements

Return type

str

Returns

identifier (might be None)

innoconv_mintmod.utils.get_panzer_bin()[source]

Get path of panzer binary.

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
  • doc (panflute.elements.Doc) – Document where the element is stored

  • key (str) – Key under which element is stored

  • keep (bool) – If value should be kept after retrieving (default=False)

Return 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
  • msg_string (str) – Message that is logged

  • level (str) – Log level (INFO, WARNING, ERROR OR CRITICAL)

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, lang, as_doc=False, from_format='latex+raw_tex')[source]

Parse a source fragment using panzer.

Parameters
  • parse_string (str) – Source fragment

  • lang (str) – Language code

  • as_doc (bool) – Return elements as panflute.elements.Doc

  • from_format (str) – Source format

Return type

list of panflute.base.Element or panflute.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(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 memory

  • key (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

innoconv_mintmod.utils.remove_empty_paragraphs(doc)[source]

Remove empty paragraphs from document.

Parameters

doc (panflute.elements.Doc) – Document

innoconv_mintmod.utils.to_inline(elem, classes=[], attributes={})[source]

Convert any given pandoc element to inline element(s). Some information may be lost.