def claim_filter(key, value, format, meta): if key == 'Link': (identifier, classes, attributes_list), content, target = value attributes = dict(attributes_list) if 'claim' in attributes: claim_test_command = attributes['claim'] if subprocess.call(claim_test_command, shell=True) == 0: return pandocfilters.Span((identifier, classes, attributes_list), content) else: return pandocfilters.Span((identifier, classes, attributes_list), [pandocfilters.Strong([pandocfilters.Strikeout(content)])])
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])
def math_replacement(self, key, value, format, metadata): """Create our own links to equations instead of relying on mathjax. http://meta.math.stackexchange.com/questions/3764/equation-and-equation-is-the-same-for-me """ mathtype, math = value label = re.findall(math_label, math)[-1] attr = PandocAttributes() attr.id = '#' + label if format == 'latex' or format == 'beamer': return pf.Math(mathtype, math) else: return pf.Span(attr.to_pandoc(), [pf.Math(mathtype, math)])
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>"] }]