diff --git a/ftl/core/card-templates.ftl b/ftl/core/card-templates.ftl index 18a7a76b4..7ecda1968 100644 --- a/ftl/core/card-templates.ftl +++ b/ftl/core/card-templates.ftl @@ -37,6 +37,7 @@ card-templates-card = Card { $val } card-templates-card-types-for = Card Types for { $val } card-templates-cloze = Cloze { $val } card-templates-deck-override = Deck Override... +card-templates-copy-info = Copy Info to Clipboard card-templates-delete-the-as-card-type-and = Delete the '{ $template }' card type, and its { $cards }? card-templates-enter-deck-to-place-new = Enter deck to place new { $val } cards in, or leave blank: card-templates-enter-new-card-position-1 = Enter new card position (1...{ $val }): diff --git a/qt/aqt/clayout.py b/qt/aqt/clayout.py index 6fb50f0b7..14796391a 100644 --- a/qt/aqt/clayout.py +++ b/qt/aqt/clayout.py @@ -754,6 +754,31 @@ class CardLayout(QDialog): dst["afmt"] = "{{FrontSide}}\n\n
\n\n%s" % src["qfmt"] dst["qfmt"] = m.group(2).strip() + def onCopyMarkdown(self) -> None: + template = self.current_template() + + def sanitizeMarkdown(md): + return md.replace("```", "\\`\\`\\`") + + markdown = ( + f"## Front Template\n" + "```html\n" + f"{sanitizeMarkdown(template['qfmt'])}\n" + "```\n" + "## Back Template\n" + "```html\n" + f"{sanitizeMarkdown(template['afmt'])}\n" + "```\n" + "## Styling\n" + "```css\n" + f"{sanitizeMarkdown(self.model['css'])}\n" + "```\n" + ) + clipboard = QApplication.clipboard() + assert clipboard is not None + clipboard.setText(markdown) + tooltip(tr.about_copied_to_clipboard()) + def onMore(self) -> None: m = QMenu(self) @@ -794,6 +819,10 @@ class CardLayout(QDialog): assert a is not None qconnect(a.triggered, self.onTargetDeck) + a = m.addAction(tr.card_templates_copy_info()) + assert a is not None + qconnect(a.triggered, self.onCopyMarkdown) + a = m.addAction(tr.card_templates_browser_appearance()) assert a is not None qconnect(a.triggered, self.onBrowserDisplay)