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
orlist[str]
ordict
) – can also be panflute.Docfilter_func – the filter function or a list of filter functions
out_format (
str
) – for use by pandoc or, if ‘panflute’, return the panflute.Docin_format="markdown" (
str
) –strip_meta=False (
bool
) – strip the document metadata before final conversionstrip_blank_lines (
bool
) –strip_ends (
bool
) – strip any blank lines or space from the start and endreplace_api_version (
bool
) – for dict input only, if True, find the api_version of the available pandoc and reformat the json as appropriatedry_run (
bool
) – If True, return the Doc object, before applying the filterkwargs – to parse to filter func
- Returns
- Return type
-
ipypublish.filters_pandoc.utils.
convert_attributes
(attr)[source]¶ attempt to convert values to python types, e.g. float, list, dict
-
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
- Returns
- {“classes”: list[str], “attributes”: dict[str],
”id”: str, “elements”: list[Element]}, where elements is the elements containing the attributes (including space)
- Return type
-
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 inkeypath (
list[str]
orstr
) – a key path to search in, if str, then split by delimiterdefault=None (
object
) – a default value to returndelimiter (
str
) – if a str then the keypath is expected to be a strerror_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