Beispiel #1
0
def afterframe(s):
    global lastsection, lastsubsection
    return [
        pf.Header(1, ('', ['unnumbered'], []), [pf.Str(lastsection)]),
        pf.Header(2, ('', ['unnumbered'], []), [pf.Str(lastsubsection)]),
        lb(s)
    ]
Beispiel #2
0
 def update(self, k, v, f, m):
     if k == 'Header':
         unnumbered = pf.Header(v[0], ('', ['unnumbered'], []), v[2])
         if v[0] == 1:
             self._sections = [unnumbered]
         elif v[0] == 2:
             self._sections = [self._sections[0], unnumbered]
def do_filter(k, v, f, m):
    if k == "Table":
        w = v[2]
        if sum(w) == 0:
            w = [1 for e in w]
            wd = ''
            ha = r'\centering'
        else:
            wd = '*'
            ha = r'\raggedright'
        return [
            latex(r'\begin{table' + wd + '}[!h]'),
            tbl_caption(v[0]),
            latex(ha),
            latex(r'\begin{tabu} spread 0pt {' + tbl_alignment(v[1], w) + '}'),
            latex(r'\toprule'),
            tbl_headers(v[3]),
            latex(r'\midrule'),
            tbl_contents(v[4]),
            latex(r'\bottomrule'
                  '\n'
                  r'\end{tabu}'),
            latex(r'\end{table' + wd + '}')
        ]
    if k == "Header":
        return [
            latex(r'\hypertarget{' + v[1][0] + r'}{}'),
            pf.Header(v[0], v[1], v[2])
        ]
Beispiel #4
0
def do_filter(k, v, f, m):
    global sec
    if sec > 2 or (k == "Header" and v[0] < 3):
        return []
    if k == "Header" and v[0] > 2:
        sec += 1
        v[1][1].append('unnumbered')
        return pf.Header(v[0], v[1], v[2])
Beispiel #5
0
def remove_attributes(blockquote):
    """Remove attributes from a blockquote if they are defined on a
    header that is the first thing in the blockquote.

    Modifies the blockquote inplace.
    """
    if blockquote[0]['t'] == 'Header':
        level, attr, inlines = blockquote[0]['c']
        attr = pf.attributes({})
        blockquote[0] = pf.Header(level, attr, inlines)
Beispiel #6
0
    def section_replacement(self, key, value, format, metadata):
        """Replace sections with appropriate representation.
        """
        level, attr, text = value
        label, classes, kvs = attr

        if 'unnumbered' in classes or not self.numbersections:
            pretext = ''
        else:
            ref = self.references[label]
            pretext = '{}. '.format(ref['id'])

        pretext = [pf.Str(pretext)]

        if format in ('html', 'html5', 'markdown'):
            return pf.Header(level, attr, pretext + text)

        elif format == 'latex' or format == 'beamer':
            # have to do this to get rid of hyperref
            return pf.Header(level, attr, text)

        else:
            return pf.Header(level, attr, pretext + text)
def blockquote2div(key, value, format, meta):
    """Convert a blockquote into a div if it begins with a header
    that has attributes containing a single class that is in the
    allowed classes.

    This function can be passed directly to toJSONFilter
    from pandocfilters.
    """
    if key == 'BlockQuote':
        blockquote = value

        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)

            # a blockquote is just a list of blocks, so it can be
            # passed directly to Div, which expects Div(attr, blocks)
            return pf.Div((id, classes, kvs), [panel_header, panel_body])
Beispiel #8
0
def do_filter(k, v, f, m):
    if k == "Header" and v[0] > 2:
        v[1][1].append('unnumbered')
        return pf.Header(v[0], v[1], v[2])
def blockquote2div(key, value, format, meta):
    """Convert a blockquote into a div if it begins with a header
    that has attributes containing a single class that is in the
    allowed classes.

    This function can be passed directly to toJSONFilter
    from pandocfilters.
    """
    if key == 'BlockQuote':
        blockquote = value

        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
            header = pf.Header(h_level, [h_attr[0], [], []], 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)

            # a blockquote is just a list of blocks, so it can be
            # passed directly to Div, which expects Div(attr, blocks)
            if classes[0] == "callout":
                return [{
                    "t":
                    "RawBlock",
                    "c": [
                        "html",
                        "<aside class=\"{0}\">".format(' '.join(classes))
                    ]
                }, panel_header, panel_body, {
                    "t": "RawBlock",
                    "c": ["html", "</aside>"]
                }]
            else:
                return [{
                    "t":
                    "RawBlock",
                    "c": [
                        "html",
                        "<section class=\"{0}\">".format(' '.join(classes))
                    ]
                }, panel_header, panel_body, {
                    "t": "RawBlock",
                    "c": ["html", "</section>"]
                }]