def vertical_card(card_data: JSONType) -> Element: assert "title" in card_data and "text" in card_data title = card_data["title"] text = convert_text(card_data["text"]) content = [] if "image" in card_data: content.append( Plain( Image(url=card_data["image"], title=title, classes=["card-img-top"]))) body = [ Header(Str(title), level=3, classes=["card-title"]), Div(*text, classes=["card-text"]) ] if "link" in card_data: body.append( Plain( Link(Str(card_data["link"]["content"]), url=card_data["link"]["href"], classes=["btn", "btn-secondary", "mt-auto", "mx-4"]))) content.append( Div(*body, classes=["card-body", "d-flex", "flex-column"])) content = Div(Div(*content, classes=["card", "h-100", "rounded-lg"]), classes=["col"]) return content
def referencing_cite(elem, doc): """ reference cite. Arguments --------- elem: element to reference doc: pandoc document """ if len(elem.content) == 1 and isinstance(elem.content[0], Str): match = re.match( "^(@(?P<tag>(?P<category>[a-zA-Z][\\w.-]*):(([a-zA-Z][\\w.-]*)|(\\d*(\\.\\d*)*))))$", elem.content[0].text, ) if match: category = match.group("category") if category in doc.defined and doc.defined[category][ "cite-shortcut"]: # Deal with @prefix:name shortcut tag = match.group("tag") if tag in doc.information: ret = Link( doc.information[tag].link, url="#" + tag, title=doc.information[tag].caption.replace( "%c", str(doc.count[doc.information[tag].category])), ) replace_count( ret, str(doc.count[doc.information[tag].category])) return ret return None
def horizontal_card(card_data: JSONType) -> Element: assert "title" in card_data and "text" in card_data title = card_data["title"] text = convert_text(card_data["text"]) content = [] body = [ Header(Str(title), level=3, classes=["card-title"]), Div(*text, classes=["card-text"]) ] if "link" in card_data: body.append( Plain( Link(Str(card_data["link"]["content"]), url=card_data["link"]["href"], classes=["btn", "btn-secondary", "mt-auto", "mx-4"]))) card_img = Div(Plain( Image(url=card_data["image"], title=title, attributes={"width": "100%"})), classes=["col-4"]) card_body = Div(Div(*body, classes=["card-body"]), classes=["col-8"]) if card_data["imageLocation"] == "Left": content = [card_img, card_body] else: content = [card_body, card_img] content = Div(Div(*content, classes=["row", "no-gutters"]), classes=["card", "rounded-lg"]) return content
def _create_images(doc, icons, size): # Generate the LaTeX image code images = [] for icon in icons: # Get the image from the App cache folder image_dir = os.path.join( doc.folder, icon["collection"], icon["version"], icon["variant"], icon["color"], ) image = os.path.join(image_dir, icon["extended-name"] + ".png") # Create the image if not existing in the cache try: if not os.path.isfile(image): # Create the image in the cache category = _category( icon["collection"], icon["version"], icon["variant"] ) doc.get_icon_font[category]["font"].export_icon( icon["extended-name"], 512, color=icon["color"], export_dir=image_dir, ) # Add the LaTeX image image = Image( url=image, attributes={"width": size + "pt", "height": size + "pt"} ) if icon["link"] == "": elem = image else: elem = Link(image, url=icon["link"]) images.append( convert_text( Plain(elem), input_format="panflute", output_format="latex" ) ) except TypeError: debug( "[WARNING] pandoc-latex-tip: icon name " + icon["name"] + " does not exist in variant " + icon["variant"] + " for collection " + icon["collection"] + "-" + icon["version"] ) except FileNotFoundError: debug("[WARNING] pandoc-latex-tip: error in generating image") return images
def hyperlink_manpages(elem, doc): if MANPAGE_URL_TMPL is None: return if isinstance(elem, Str): match = re.match( '(?P<page>(\w|-|\.)+)\((?P<section>[0-9]+)\)', elem.text, ) if match: return Link(elem, url=MANPAGE_URL_TMPL.format(**match.groupdict()))
def action(elem, doc): if isinstance(elem, CodeBlock) and "inject" in elem.attributes: name = elem.identifier label = Emph(Str(f"«{name}»=")) itemNav = Link(Str(f"{name} output"), url=f"#{name}", classes=["nav-item", "nav-link", "active"], identifier="nav-source-tab", attributes={ "data-toggle": "tab", "aria-controls": f"{name}", "aria-selected": "true" }) sourceNav = Link(label, url="#nav-source", classes=["nav-item", "nav-link"], identifier="nav-source-tab", attributes={ "data-toggle": "tab", "aria-controls": "nav-source", "aria-selected": "false" }) nav = Div(Plain(itemNav, sourceNav), classes=["nav", "nav-tabs"], identifier=f"{name}-nav") elem.identifier = f"{name}-source" elem.attributes["annotated"] = "true" targetPane = Div(classes=["tab-pane", "fade", "show", "active"], identifier=name) sourcePane = Div(elem, classes=["tab-pane", "fade"], identifier="nav-source") content = Div(targetPane, sourcePane, classes=["tab-content"], identifier=f"{name}-content") expanded_source = tangle.get_code(doc.code_map, name) script = RawBlock(f"<script>\n{expanded_source}\n</script>") return Div(nav, content, script, classes=["entangled-inject"])
def table_other(doc, category, _): """ Compute other code for table. Arguments --------- doc: pandoc document category: category numbered definition: definition """ if category in doc.collections: # Prepare the list elements = [] # Loop on the collection for tag in doc.collections[category]: # Add an item to the list elements.append( ListItem(Plain(Link(doc.information[tag].entry, url="#" + tag)))) # Return a bullet list return BulletList(*elements) return None
def links_to_footnotes(elem, doc): """ Will shift a header level from the filter-header-shift metadata value (which must exist) """ if doc.format != 'latex': return if isinstance(elem, Link): if elem.url.startswith('#'): return if elem.url.startswith('mailto:'): return if elem.url == stringify(elem): return return [ elem, Note( Para(RawInline(stringify(elem), format='tex'), Str(':'), Space(), Link(Str(elem.url), title=elem.title, url=elem.url))) ]