def create_pandoc_multilink(strings, refs): inlines = [[pf.Str(str(s))] for s in strings] targets = [(r, "") for r in refs] links = [pf.Link(inline, target) for inline, target in zip(inlines, targets)] return join_items(links)
def convert_internal_refs(self, key, value, format, metadata): """Convert all internal links from '#blah' into format specified in self.replacements. """ if key != 'Cite': return None citations, inlines = value if len(citations) > 1: ''' Note: Need to check that *all* of the citations in a multicitation are in the reference list. If not, the citation is bibliographic, and we want LaTeX to handle it, so just return unmodified. ''' for citation in citations: if citation['citationId'] not in self.references: return return self.convert_multiref(key, value, format, metadata) else: citation = citations[0] prefix = pf.stringify(citation['citationPrefix']) suffix = pf.stringify(citation['citationSuffix']) if prefix: prefix += ' ' label = citation['citationId'] if label not in self.references: return rtype = self.references[label]['type'] n = self.references[label]['id'] text = self.replacements[rtype].format(n) if format == 'latex' and self.autoref: link = u'{pre}\\autoref{{{label}}}{post}'.format(pre=prefix, label=label, post=suffix) return pf.RawInline('latex', link) elif format == 'latex' and not self.autoref: link = u'{pre}\\ref{{{label}}}{post}'.format(pre=prefix, label=label, post=suffix) return pf.RawInline('latex', link) else: link_text = '{}{}{}'.format(prefix, text, suffix) link = pf.Link([pf.Str(link_text)], ('#' + label, '')) return link
def convert_internal_refs(self, key, value, format, metadata): """Convert all internal links from '#blah' into format specified in self.replacements. """ if key != 'Cite': return None citations, inlines = value if len(citations) > 1: ''' Note: Need to check that *all* of the citations in a multicitation are in the reference list. If not, the citation is bibliographic, and we want LaTeX to handle it, so just return unmodified. ''' for citation in citations: if citation['citationId'] not in self.references: return return self.convert_multiref(key, value, format, metadata) else: citation = citations[0] prefix = citation['citationPrefix'] suffix = citation['citationSuffix'] label = citation['citationId'] if label not in self.references: return if prefix: prefix += [pf.Space()] rtype = self.references[label]['type'] n = self.references[label]['id'] text = self.replacements[rtype].format(n) if format in ['latex', 'beamer'] and self.autoref: link = pf.RawInline('latex', '\\cref{{{label}}}'.format(label=label)) return prefix + [link] + suffix elif format in ['latex', 'beamer'] and not self.autoref: link = pf.RawInline('latex', '\\ref{{{label}}}'.format(label=label)) return prefix + [link] + suffix else: link = pf.Link(["", [], []], [pf.Str(text)], ('#' + label, '')) return prefix + [link] + suffix
def _filter(key, value, format, meta): # remove HTML specific stuff if key == "Link": # remove relative path prefix and .html suffix internal, [href, text] = value if href.endswith(".html"): href = href[:-5] # FIXME: this stupid detection will not work # or just leave the full path? # if href.startswith("./"): # href = href[2:] # elif href.startswith("../"): # href = href[3:] return pandocfilters.Link(internal, [href, text])