def create_figures(key, value, format, metadata): """Convert Images with attributes to Figures. Images are [caption, (filename, title)]. Figures are [caption, (filename, title), attrs]. This isn't a supported pandoc type, we just use it internally. """ if isattrfigure(key, value): image = value[0] attr = PandocAttributes(pf.stringify(value[1:]), 'markdown') caption, target = image['c'] return Figure(caption, target, attr.to_pandoc()) elif isdivfigure(key, value): # use the first image inside attr, blocks = value images = [b['c'][0] for b in blocks if b['c'][0]['t'] == 'Image'] image = images[0] caption, target = image['c'] return Figure(caption, target, attr) else: return None
def test_pandoc(): attr = PandocAttributes(attr_pandoc, 'pandoc') print attr_dict print attr.to_dict() nt.assert_dict_equal(attr_dict, attr.to_dict()) nt.assert_equal(attr_html, attr.to_html()) nt.assert_equal(attr_markdown.replace('\n', ' '), attr.to_markdown()) assert(attr_pandoc == attr.to_pandoc())
def test_pandoc(): attr = PandocAttributes(attr_pandoc, 'pandoc') print attr_dict print attr.to_dict() nt.assert_dict_equal(attr_dict, attr.to_dict()) nt.assert_equal(attr_html, attr.to_html()) nt.assert_equal(attr_markdown.replace('\n', ' '), attr.to_markdown()) assert (attr_pandoc == attr.to_pandoc())
def figure_replacement(self, key, value, format, metadata): """Replace figures with appropriate representation. This works with Figure, which is our special type for images with attributes. This allows us to set an id in the attributes. The other way of doing it would be to pull out a '\label{(.*)}' from the caption of an Image and use that to update the references. """ _caption, (filename, target), attrs = value caption = pf.stringify(_caption) attr = PandocAttributes(attrs) if 'unnumbered' in attr.classes: star = '*' fcaption = caption else: self.fig_replacement_count += 1 if not attr.id: attr.id = self.auto_fig_id(self.fig_replacement_count) ref = self.references[attr.id] star = '' if caption: fcaption = u'Figure {n}: {caption}'.format(n=ref['id'], caption=caption) else: fcaption = u'Figure {n}'.format(n=ref['id']) if 'figure' not in attr.classes: attr.classes.insert(0, 'figure') if format in self.formats: figure = self.figure_styles[format].format(attr=attr, filename=filename, alt=fcaption, fcaption=fcaption, caption=caption, star=star).encode('utf-8') return RawBlock(format, figure) else: alt = [pf.Str(fcaption)] target = (filename, '') image = pf.Image(alt, target) figure = pf.Para([image]) return pf.Div(attr.to_pandoc(), [figure])
def create_tableattrs(key, value, format, metadata): """Convert Tables with attributes to TableAttr. Tables are [caption, alignment, size, headers, rows] TableAttrs are [caption, alignment, size, headers, rows, attrs] Like Figures, this isn't supported pandoc type but only used internally. """ if key == 'Table': captionList, alignment, size, headers, rows = value caption, attrs = tableattrCaption(captionList) if attrs: attrs = PandocAttributes(attrs, 'markdown') return TableAttrs(caption, alignment, size, headers, rows, attrs.to_pandoc()) else: return None
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 in ['latex', 'beamer']: return pf.Math(mathtype, math) else: return pf.Span(attr.to_pandoc(), [pf.Math(mathtype, math)])
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 test_properties(): attr = PandocAttributes(attr_markdown, 'markdown') assert(attr.html == attr.to_html()) assert(attr.markdown == attr.to_markdown()) assert(attr.dict == attr.to_dict()) assert(attr.list == attr.to_pandoc())
def test_properties(): attr = PandocAttributes(attr_markdown, 'markdown') assert (attr.html == attr.to_html()) assert (attr.markdown == attr.to_markdown()) assert (attr.dict == attr.to_dict()) assert (attr.list == attr.to_pandoc())
def test_properties(): attr = PandocAttributes(attr_markdown, 'markdown') nt.assert_equal(attr.html, attr.to_html()) nt.assert_equal(attr.markdown, attr.to_markdown()) nt.assert_equal(attr.dict, attr.to_dict()) nt.assert_equal(attr.list, attr.to_pandoc())