How to use the pandocfilters.Span function in pandocfilters

To help you get started, we’ve selected a few pandocfilters 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 chdemko / pandoc-numbering / tests / test_numbering.py View on Github external
def test_numbering_title():
    init()

    src = Para(createListStr(u'Exercise (The title) #'))
    dest = Para([
        Span(
            [u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
            [
                Strong(createListStr(u'Exercise 1')),
                Space(),
                Emph(createListStr(u'(') + createListStr(u'The title') + createListStr(u')'))
            ]
        )
    ])

    assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
github chdemko / pandoc-numbering / tests / test_numbering.py View on Github external
def test_numbering_prefix_single():
    init()

    src = Para(createListStr(u'Exercise #ex:'))
    dest = Para([
        Span(
            [u'ex:1', ['pandoc-numbering-text', 'ex'], []],
            [Strong(createListStr(u'Exercise 1'))]
        )
    ])

    assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest

    src = Para(createListStr(u'Exercise #'))
    dest = Para([
        Span(
            [u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
            [Strong(createListStr(u'Exercise 1'))]
        )
    ])

    assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
github chdemko / pandoc-numbering / tests / test_numbering.py View on Github external
def test_numbering():
    init()

    src = Para(createListStr(u'Exercise #'))
    dest = Para([
        Span(
            [u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
            [Strong(createListStr(u'Exercise 1'))]
        )
    ])

    assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
github chdemko / pandoc-numbering / tests / test_numbering.py View on Github external
def test_numbering_sectioning_map():
    init()

    meta = getMeta2()

    sectioning(meta)

    src = Para([Str(u'Exercise'), Space(), Str(u'#')])
    dest = Para([
        Span(
            [u'exercise:2.2.1', ['pandoc-numbering-text', 'exercise'], []],
            [Strong(createListStr(u'Exercise 2.1'))]
        )
    ])

    assert pandoc_numbering.numbering(src['t'], src['c'], '', meta) == dest
github chdemko / pandoc-numbering / tests / test_numbering.py View on Github external
src = Para(createListStr(u'Exercise +.+.#'))
    dest = Para([
        Span(
            [u'exercise:1.1.2', ['pandoc-numbering-text', 'exercise'], []],
            [Strong(createListStr(u'Exercise 1.1.2'))]
        )
    ])

    assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest

    src = Header(2, [u'second-section', [], []], createListStr(u'Second section'))
    pandoc_numbering.numbering(src['t'], src['c'], '', {})

    src = Para(createListStr(u'Exercise +.+.#'))
    dest = Para([
        Span(
            [u'exercise:1.2.1', ['pandoc-numbering-text', 'exercise'], []],
            [Strong(createListStr(u'Exercise 1.2.1'))]
        )
    ])

    assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
github chdemko / pandoc-numbering / tests / test_numbering.py View on Github external
],
        [
            createListStr(u'Exercise #'),
            [Plain([createListStr(u'Content B')])]
        ]
    ])
    dest = DefinitionList([
        [
            [Span(
                [u'exercise:1', ['pandoc-numbering-text', 'exercise'], []],
                [Strong(createListStr(u'Exercise 1'))]
            )],
            [Plain([createListStr(u'Content A')])]
        ],
        [
            [Span(
                [u'exercise:2', ['pandoc-numbering-text', 'exercise'], []],
                [Strong(createListStr(u'Exercise 2'))]
            )],
            [Plain([createListStr(u'Content B')])]
        ]
    ])
    assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest
github swcarpentry / sql-novice-survey / tools / filters / blockquote2div.py View on Github external
header = find_header(blockquote)
        if not header:
            return
        else:
            level, attr, inlines = header

        id, classes, kvs = attr

        if len(classes) == 1 and classes[0] in SPECIAL_CLASSES:
            panel_kind, glyphicon_kind = SPECIAL_CLASSES[classes[0]]

            h_level, h_attr, h_inlines = blockquote[0]['c']

            # insert an icon as the first sub-item of the header
            span = pf.Span(["", ["glyphicon", glyphicon_kind], []], [])
            h_inlines.insert(0, span)

            # only the header goes into panel-heading
            # WARNING: pandoc doesn't preserve header attributes when the
            #          header is nested under blockquote.  This makes it
            #          impossible to alter header's "class" attribute, for
            #          example.
            header = pf.Header(h_level, h_attr, h_inlines)
            panel_header = pf.Div(("", ["panel-heading"], []), [header])

            # the rest of the blockquote goes into panel-body
            panel_body = pf.Div(("", ["panel-body"], []), blockquote[1:])

            # apply Bootstrap panel classes to the div
            classes.append("panel")
            classes.append(panel_kind)
github tomduck / pandoc-eqnos / pandoc_eqnos.py View on Github external
insert_secnos = insert_secnos_factory(Math)
    delete_secnos = delete_secnos_factory(Math)
    altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta),
                               [attach_attrs_math, insert_secnos,
                                process_equations, delete_secnos,
                                detach_attrs_math], blocks)

    # Second pass
    process_refs = process_refs_factory(LABEL_PATTERN, references.keys())
    replace_refs = replace_refs_factory(references,
                                        cleveref, eqref,
                                        plusname if not capitalise or \
                                        plusname_changed else
                                        [name.title() for name in plusname],
                                        starname)
    attach_attrs_span = attach_attrs_factory(Span, replace=True)
    altered = functools.reduce(lambda x, action: walk(x, action, fmt, meta),
                               [repair_refs, process_refs, replace_refs,
                                attach_attrs_span],
                               altered)

    if fmt in ['latex', 'beamer']:
        add_tex(meta)
    elif fmt in ['html', 'html5', 'epub', 'epub2', 'epub3']:
        add_html(meta)

    # Update the doc
    if PANDOCVERSION >= '1.18':
        doc['blocks'] = altered
    else:
        doc = doc[:1] + altered