Exemplo n.º 1
0
        thumbnail = config.get('wordpress', 'thumbnail')
        here = path.dirname( postfile )
        thumb_url = path.join( here, thumbnail ) # Make path absolute

    # Wordpress related, create the post
    WP = Client( url, username, password )
    post = WordPressPost()


    # Take markdown, convert to HTML and put it as post content
    # Makes intermediate convertion to Panflute AST to apply the filters.
    postdocument = pf.convert_text(postcontent, input_format='markdown',
                                                output_format='panflute',
                                                standalone=True)

    pf.run_filters( [ imageURLs, codeBlocks ], doc = postdocument )
    content = pf.convert_text(postdocument, input_format='panflute',
                                            output_format='html')


    # Set post metadata
    post.title = title
    post.content = content
    post.post_status = post_status
    post.terms_names = terms_names

    if not thumb_url == None:
        thumb_mime = checkImage(thumb_url)
        if not thumb_mime == None:
            response = uploadFile(thumb_url, thumb_mime)
            post.thumbnail = response['id']
def listed(doc=None):
    inline = inline_listingtable()
    block = ListingTable()
    return pf.run_filters([inline.action, pf.yaml_filter], tag="listingtable", function=block.action, doc=doc)
Exemplo n.º 3
0
def main(doc=None):
    return run_filters([remove_badge, unwrap_code], doc=doc)
Exemplo n.º 4
0
def main(doc=None):
	#inputf = open('test.json', 'r')
	inputf=sys.stdin
	return pf.run_filters(actions=[remove_notes,add_pagebreaks],doc=doc,input_stream=inputf)
Exemplo n.º 5
0
    if not isinstance(elem, pf.Div) or elem.identifier != 'bibliography':
        return None

    def references(elem, doc):
        if isinstance(elem, pf.Div) and elem.identifier == 'refs':
            nonlocal refs
            refs = elem

    refs = pf.Div()
    elem.walk(references)
    if refs.content:
        # This should just be `return None`, but the HTML output
        # for headers seem to break with `<h1>` inside a `<div>`.
        elem.parent.content.extend(elem.content)

    return []


if __name__ == '__main__':
    pf.run_filters(
        [
            bibliography,
            divspan,
            tonytable,
            # after `tonytable` because...
            codeblock,  # produces raw html/latex, `tonytable` needs codeblocks.
            header,  # doesn't apply to the "headers" in tony table.
            table  # also applies to tables generated by `tonytable`.
        ],
        prepare=prepare)
Exemplo n.º 6
0
def main(doc=None, strip_spans=True):
    # type: (Doc, bool) -> None
    to_run = [format_math, format_image, format_table]
    if strip_spans:
        to_run.append(strip_labelled_spans)
    return pf.run_filters(to_run, prepare, finalize, doc=doc)
Exemplo n.º 7
0
def main(doc=None):
    return pf.run_filters([action],
                          prepare=prepare,
                          finalize=finalize,
                          doc=doc)
Exemplo n.º 8
0
#!/usr/bin/env python3
import panflute as pf

def h1hr(elem, doc):
    """
    Add a bottom border to all the <h1>s
    """
    if not isinstance(elem, pf.Header):
        return None

    if elem.level != 1:
        return None

    elem.attributes['style'] = 'border-bottom:1px solid #cccccc'
    return elem

def bq(elem, doc):
    """
    Add a ::: bq div to make a <blockquote>
    """
    if not isinstance(elem, pf.Div):
        return None

    if elem.classes == ['bq']:
        return pf.BlockQuote(*elem.content)

if __name__ == '__main__':
    pf.run_filters([h1hr, bq])
Exemplo n.º 9
0
                               '--syntax-definition',
                               os.path.join(syntaxdir, 'isocpp.xml')
                           ])

    def repl(match_obj):
        match = match_obj.group(1)
        if not match:  # @@
            return match_obj.group(0)
        if match.isspace():  # @  @
            return match
        return pf.convert_text(pf.Plain(*pf.convert_text(match)[0].content),
                               input_format='panflute',
                               output_format=doc.format)

    result = pf.RawBlock(escape_span.sub(repl, text), doc.format)

    return pf.Div(pf.RawBlock('{\\renewcommand{\\NormalTok}[1]{#1}', 'latex'),
                  result, pf.RawBlock('}', 'latex')) if is_raw else result


# https://github.com/jgm/pandoc/issues/5529
def strikeout(elem, doc):
    if not isinstance(elem, pf.Strikeout):
        return None

    elem.walk(protect_code)


if __name__ == '__main__':
    pf.run_filters([divspan, tonytable, codeblock, strikeout], prepare=prepare)
Exemplo n.º 10
0
def main():
    doc = pf.load(input_stream=sys.stdin)
    merge_settings(doc)
    pf.dump(pf.run_filters([gloss, gloss_refs], doc=doc),
            output_stream=sys.stdout)
Exemplo n.º 11
0
Arquivo: wg21.py Projeto: mpark/wg21
            '--syntax-definition', os.path.join(syntaxdir, 'isocpp.xml')
        ])

    def repl(match_obj):
        match = match_obj.group(1)
        if not match:  # @@
            return match_obj.group(0)
        if match.isspace():  # @  @
            return match
        return pf.convert_text(
            pf.Plain(*pf.convert_text(match)[0].content),
            input_format='panflute',
            output_format=doc.format)

    result = pf.RawBlock(escape_span.sub(repl, text), doc.format)

    return pf.Div(
        pf.RawBlock('{\\renewcommand{\\NormalTok}[1]{#1}', 'latex'),
        result,
        pf.RawBlock('}', 'latex')) if is_raw else result

# https://github.com/jgm/pandoc/issues/5529
def strikeout(elem, doc):
    if not isinstance(elem, pf.Strikeout):
        return None

    elem.walk(protect_code)

if __name__ == '__main__':
    pf.run_filters([divspan, tonytable, codeblock, strikeout], prepare=prepare)
Exemplo n.º 12
0
                    child_elems += [SoftBreak(), RawInline(">")] * 2 + [
                        Space()
                    ]
                child_elems.append(child)
                if isinstance(child, SoftBreak):
                    child_elems += [RawInline(">"), Space()]
            after_paragraph = isinstance(child, Para)

        elem.walk(append)
        return Para(*child_elems)


def line_break(elem, _doc):
    if isinstance(elem, SoftBreak):
        return LineBreak()


def raw_string(elem, _doc):
    if isinstance(elem, Str) and re_uri.match(elem.text):
        return RawInline(elem.text)


if __name__ == "__main__":
    run_filters([
        code_block,
        horizontal_rule,
        stripped_quote,
        line_break,
        raw_string,
    ])
Exemplo n.º 13
0
def main(doc=None):
    # type: (Doc) -> None
    return pf.run_filters(
        [resolve_tables, resolve_equations_images], prepare, finalize, doc=doc
    )
Exemplo n.º 14
0
def main(doc=None):
	#inputf = open('test.json', 'r')
	inputf=sys.stdin
	return pf.run_filters(actions=[filter_lang,title_hacks,dual_img], doc=doc,input_stream=inputf,prepare=prepare)
Exemplo n.º 15
0
    return pf.Table(*rows, **kwargs)


def table(elem, doc):
    if not isinstance(elem, pf.Table):
        return None

    def header(elem, doc):
        if not isinstance(elem, pf.Plain):
            return None

        return pf.Div(pf.Plain(pf.RawInline('\\centering', 'latex'),
                               pf.Strong(*elem.content)),
                      attributes={'style': 'text-align:center'})

    if elem.header is not None:
        elem.header.walk(header)


if __name__ == '__main__':
    pf.run_filters(
        [
            divspan,
            cmptable,
            # after `cmptable` because...
            header,  # doesn't apply to the "headers" in comparison table.
            table,  # also applies to tables generated by `cmptable`.
        ],
        prepare,
        finalize)
Exemplo n.º 16
0
def main(doc=None):
    replacements = {'\\\\(cite[tp]?|ref)\{(.*)\}': r'\\\1{\2}', '$': r'\$'}
    return pf.run_filters((labels, striptags, destring),
                          doc=doc,
                          replacements=replacements)