# Path: panflute/elements.py
# class Str(Inline):
#     """
#     Text (a string)
# 
#     :param text: a string of unformatted text
#     :type text: :class:`str`
#     :Base: :class:`Inline`
#      """
# 
#     __slots__ = ['text']
# 
#     def __init__(self, text):
#         self.text = check_type(text, str)
# 
#     def __repr__(self):
#         return 'Str({})'.format(self.text)
# 
#     def _slots_to_json(self):
#         return self.text
# 
# class Span(Inline):
#     """Generic block container with attributes
# 
#     :param args: contents of the div
#     :type args: :class:`Inline`
#     :param identifier: element identifier (usually unique)
#     :type identifier: :class:`str`
#     :param classes: class names of the element
#     :type classes: :class:`list` of :class:`str`
#     :param attributes: additional attributes
#     :type attributes: :class:`dict`
#     :Base: :class:`Inline`
#      """
# 
#     __slots__ = ['_content', 'identifier', 'classes', 'attributes']
#     _children = ['content']
# 
#     def __init__(self, *args, identifier='', classes=[], attributes={}):
#         self._set_ica(identifier, classes, attributes)
#         self._set_content(args, Inline)
# 
#     def _slots_to_json(self):
#         return [self._ica_to_json(), self.content.to_json()]
# 
# class MetaInlines(MetaValue):
#     """
#     MetaInlines: list of arbitrary inlines within the metadata
# 
#     :param args: sequence of inline elements
#     :type args: :class:`Inline`
#     :Base: :class:`MetaValue`
# 
#      """
# 
#     __slots__ = ['_content']
#     _children = ['content']
# 
#     def __init__(self, *args):
#         self._set_content(args, Inline)
# 
#     def _slots_to_json(self):
#         return self.content.to_json()
# 
# Path: panflute/io.py
# def toJSONFilter(*args, **kwargs):
#     """
#     Wrapper for :func:`.run_filter`, which calls :func:`.run_filters`
# 
#     toJSONFilter(action, prepare=None, finalize=None, input_stream=None, output_stream=None, \*\*kwargs)
#     Receive a Pandoc document from stdin, apply the *action* function to each element, and write it back to stdout.
# 
#     See also :func:`.toJSONFilters`
#     """
#     return run_filter(*args, **kwargs)


from panflute import toJSONFilter, Span, Str, MetaInlines
import re
#!/usr/bin/env python

"""
Pandoc filter to allow interpolation of metadata fields
into a document.  %{fields} will be replaced by the field's
value.
"""


pattern = re.compile('%\{(.*)\}$')


def metavars(elem, doc):
    if type(elem) == Str:
        m = pattern.match(elem.text)
        if m:
            field = m.group(1)
            result = doc.get_metadata(field, None)

            if type(result) == MetaInlines:

# Path: panflute/elements.py
# class Str(Inline):
#     """
#     Text (a string)
# 
#     :param text: a string of unformatted text
#     :type text: :class:`str`
#     :Base: :class:`Inline`
#      """
# 
#     __slots__ = ['text']
# 
#     def __init__(self, text):
#         self.text = check_type(text, str)
# 
#     def __repr__(self):
#         return 'Str({})'.format(self.text)
# 
#     def _slots_to_json(self):
#         return self.text
# 
# class Span(Inline):
#     """Generic block container with attributes
# 
#     :param args: contents of the div
#     :type args: :class:`Inline`
#     :param identifier: element identifier (usually unique)
#     :type identifier: :class:`str`
#     :param classes: class names of the element
#     :type classes: :class:`list` of :class:`str`
#     :param attributes: additional attributes
#     :type attributes: :class:`dict`
#     :Base: :class:`Inline`
#      """
# 
#     __slots__ = ['_content', 'identifier', 'classes', 'attributes']
#     _children = ['content']
# 
#     def __init__(self, *args, identifier='', classes=[], attributes={}):
#         self._set_ica(identifier, classes, attributes)
#         self._set_content(args, Inline)
# 
#     def _slots_to_json(self):
#         return [self._ica_to_json(), self.content.to_json()]
# 
# class MetaInlines(MetaValue):
#     """
#     MetaInlines: list of arbitrary inlines within the metadata
# 
#     :param args: sequence of inline elements
#     :type args: :class:`Inline`
#     :Base: :class:`MetaValue`
# 
#      """
# 
#     __slots__ = ['_content']
#     _children = ['content']
# 
#     def __init__(self, *args):
#         self._set_content(args, Inline)
# 
#     def _slots_to_json(self):
#         return self.content.to_json()
# 
# Path: panflute/io.py
# def toJSONFilter(*args, **kwargs):
#     """
#     Wrapper for :func:`.run_filter`, which calls :func:`.run_filters`
# 
#     toJSONFilter(action, prepare=None, finalize=None, input_stream=None, output_stream=None, \*\*kwargs)
#     Receive a Pandoc document from stdin, apply the *action* function to each element, and write it back to stdout.
# 
#     See also :func:`.toJSONFilters`
#     """
#     return run_filter(*args, **kwargs)


# Path: examples/panflute/metavars.py
from panflute import toJSONFilter, Span, Str, MetaInlines
import re

#!/usr/bin/env python

"""
Pandoc filter to allow interpolation of metadata fields
into a document.  %{fields} will be replaced by the field's
value.
"""


pattern = re.compile('%\{(.*)\}$')


def metavars(elem, doc):
    if type(elem) == Str:
        m = pattern.match(elem.text)
        if m:
            field = m.group(1)
            result = doc.get_metadata(field, None)

            if type(result) == MetaInlines:

                return Span(*result.content, classes=['interpolated'],