ipypublish.filters_pandoc.utils module

ipypublish.filters_pandoc.utils.apply_filter(in_object, filter_func=None, out_format='panflute', in_format='markdown', strip_meta=False, strip_blank_lines=False, replace_api_version=True, dry_run=False, **kwargs)[source]

convenience function to apply a panflute filter(s) to a string, list of string lines, pandoc AST or panflute.Doc

Parameters
  • in_object (str or list[str] or dict) – can also be panflute.Doc

  • filter_func – the filter function or a list of filter functions

  • out_format (str) – for use by pandoc or, if ‘panflute’, return the panflute.Doc

  • in_format="markdown" (str) –

  • strip_meta=False (bool) – strip the document metadata before final conversion

  • strip_blank_lines (bool) –

  • strip_ends (bool) – strip any blank lines or space from the start and end

  • replace_api_version (bool) – for dict input only, if True, find the api_version of the available pandoc and reformat the json as appropriate

  • dry_run (bool) – If True, return the Doc object, before applying the filter

  • kwargs – to parse to filter func

Returns

Return type

str

ipypublish.filters_pandoc.utils.compare_version(target, comparison)[source]

Set docstring here.

Parameters
  • target (str) – target version of pandoc

  • comparison (str) – one of ‘>’, ‘<’, ‘<=’, ‘>=’, ‘==’

Returns

Return type

bool

ipypublish.filters_pandoc.utils.convert_attributes(attr)[source]

attempt to convert values to python types, e.g. float, list, dict

ipypublish.filters_pandoc.utils.convert_units(string, out_units)[source]
ipypublish.filters_pandoc.utils.create_ipub_meta(options)[source]
ipypublish.filters_pandoc.utils.find_attributes(element, allow_space=True, search_left=False, include_element=False)[source]

find an attribute ‘container’ for an element, of the form <element><space>{#id .class1 .class2 a=1 b=”a string”} and extract its content

Parameters
  • element – the element to find attributes for

  • allow_space=True (bool) – whether to allow space between the element and attribute container

  • search_left=False (bool) – search to the left of the element, rather than the right

  • include_element=False (bool) – whether to include the element in the search

Returns

{“classes”: list[str], “attributes”: dict[str],

”id”: str, “elements”: list[Element]}, where elements is the elements containing the attributes (including space)

Return type

dict or None

ipypublish.filters_pandoc.utils.get_option(locations, keypath, default=None, delimiter='.', error_on_missing=False)[source]

fetch an option variable from a hierarchy of preferred locations

The value returned will be from the first available location or the default

Parameters
  • locations (list[dict]) – a list of mappings to search in

  • keypath (list[str] or str) – a key path to search in, if str, then split by delimiter

  • default=None (object) – a default value to return

  • delimiter (str) – if a str then the keypath is expected to be a str

  • error_on_missing (bool) – raise KeyError if not found in any of the options

Examples

>>> a = {"m": 1}
>>> b = {"x": {"y": 2}}
>>> c = {"x": {"y": 3}}
>>> get_option([a, b, c], keypath=("x", "y"))
2
>>> get_option([a, c, b], keypath=("x", "y"))
3
>>> get_option([a, c, b], keypath="x.y")
3
>>> get_option([a, c, b], keypath="l", default=4)
4
ipypublish.filters_pandoc.utils.get_panflute_containers(element)[source]

return list of all possible container classes for an element

ipypublish.filters_pandoc.utils.get_pf_content_attr(container, target)[source]
ipypublish.filters_pandoc.utils.process_attributes(attr_string)[source]

process a string of classes and attributes, e.g. ‘.class-name .other a=1 b=”some text”’ will be returned as: [“class-name”, “other”], {“a”: 1, “b”: “some text”}

Returns: list: classes dict: attributes

ipypublish.filters_pandoc.utils.strip_quotes(string)[source]