How to use the panflute.stringify function in panflute

To help you get started, we’ve selected a few panflute examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sergiocorreia / panflute / docs / source / _static / wiki.py View on Github external
def action(elem, doc):
    if isinstance(elem, pf.Link) and elem.url.startswith('wiki://'):
        title = pf.stringify(elem).strip()
        baseurl = 'https://en.wikipedia.org/w/api.php'
        query = {'format': 'json', 'action': 'query', 'prop': 'extracts',
            'explaintext': '', 'titles': title}
        r = requests.get(baseurl, params=query)
        data = r.json()
        extract = list(data['query']['pages'].values())[0]['extract']
        extract = extract.split('.', maxsplit=1)[0]
        return pf.RawInline(extract)
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
def _compute_basic_category(self):
        if self._match.group("prefix") is None:
            self._basic_category = Numbered._identifier(
                "".join(map(stringify, self._description))
            )
        else:
            self._basic_category = self._match.group("prefix")
        if self._basic_category not in self._doc.defined:
            define(self._basic_category, self._doc)
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
self._get_content()[0].content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-text-classic"]
            )
            self._link.content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-link-classic"]
            )
            self._entry.content = copy.deepcopy(
                self._doc.defined[self._basic_category]["format-entry-classic"]
            )
            self._caption = self._doc.defined[self._basic_category][
                "format-caption-classic"
            ]

        # Compute caption (delay replacing %c at the end since it is not known for the moment)
        title = stringify(Span(*self._title))
        description = stringify(Span(*self._description))
        self._caption = self._caption.replace("%t", title.lower())
        self._caption = self._caption.replace("%T", title)
        self._caption = self._caption.replace("%d", description.lower())
        self._caption = self._caption.replace("%D", description)
        self._caption = self._caption.replace("%s", self._section_number)
        self._caption = self._caption.replace("%g", self._global_number)
        self._caption = self._caption.replace("%n", self._local_number)
        self._caption = self._caption.replace("#", self._local_number)
        if self._doc.format == "latex":
            self._caption = self._caption.replace("%p", "\\pageref{" + self._tag + "}")

        # Compute content
        replace_description(self._elem, self._description)
        replace_title(self._elem, self._title)
        replace_global_number(self._elem, self._global_number)
        replace_section_number(self._elem, self._section_number)
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
def meta_classes(category, definition, defined):
    """
    Compute classes for a category.

    Arguments
    ---------
        category:
        definition:
        defined:
    """
    if "classes" in definition and isinstance(definition["classes"], MetaList):
        classes = []
        for elt in definition["classes"].content:
            classes.append(stringify(elt))
        defined[category]["classes"] = classes
github ickc / pantable / pantable / table_to_csv.py View on Github external
"""convert Table element and to csv table in code-block with class "table" in panflute AST"""
    if isinstance(elem, panflute.Table):
        # get options as a dictionary
        options = {}
        # options: caption: panflute ast to markdown
        if elem.caption:
            options['caption'] = ast_to_markdown(panflute.Para(*elem.caption))
        # options: alignment
        parsed_alignment = [ALIGN_TO_LETTER[i] for i in elem.alignment]
        options['alignment'] = "".join(parsed_alignment)
        # options: width
        options['width'] = elem.width
        # options: table-width from width
        options['table-width'] = sum(options['width'])
        # options: header: False if empty header row, else True
        options['header'] = bool(panflute.stringify(elem.header)) if elem.header else False
        # options: markdown
        options['markdown'] = True

        # option in YAML
        yaml_metadata = yaml.safe_dump(options)

        # table in panflute AST
        table_body = elem.content
        if options['header']:
            table_body.insert(0, elem.header)
        # table in list
        table_list = [[ast_to_markdown(cell.content)
                       for cell in row.content]
                      for row in table_body]
        # table in CSV
        with io.StringIO() as file:
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
defined:
    """
    if "format-caption-classic" in definition:
        if isinstance(definition["format-caption-classic"], MetaInlines):
            defined[category]["format-caption-classic"] = stringify(
                definition["format-caption-classic"]
            )
        else:
            debug(
                "[WARNING] pandoc-numbering: format-caption-classic is not correct for category "
                + category
            )

    if "format-caption-title" in definition:
        if isinstance(definition["format-caption-title"], MetaInlines):
            defined[category]["format-caption-title"] = stringify(
                definition["format-caption-title"]
            )
        else:
            debug(
                "[WARNING] pandoc-numbering: format-caption-title is not correct for category "
                + category
            )
github chdemko / pandoc-numbering / pandoc_numbering.py View on Github external
def meta_format_caption(category, definition, defined):
    """
    Compute format caption for a category.

    Arguments
    ---------
        category:
        definition:
        defined:
    """
    if "format-caption-classic" in definition:
        if isinstance(definition["format-caption-classic"], MetaInlines):
            defined[category]["format-caption-classic"] = stringify(
                definition["format-caption-classic"]
            )
        else:
            debug(
                "[WARNING] pandoc-numbering: format-caption-classic is not correct for category "
                + category
            )

    if "format-caption-title" in definition:
        if isinstance(definition["format-caption-title"], MetaInlines):
            defined[category]["format-caption-title"] = stringify(
                definition["format-caption-title"]
            )
        else:
            debug(
                "[WARNING] pandoc-numbering: format-caption-title is not correct for category "