mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
"Copy template as markdown" button. (#3719)
* Added: Copy template info button * Consistent with Ankidroid * Fix: Missing newline * Renamed variables * ./check * Fix: Remove ``` from templates * Stylistic changes * ./check
This commit is contained in:
parent
39e293b27d
commit
146a0b2dcf
2 changed files with 30 additions and 0 deletions
|
@ -37,6 +37,7 @@ card-templates-card = Card { $val }
|
||||||
card-templates-card-types-for = Card Types for { $val }
|
card-templates-card-types-for = Card Types for { $val }
|
||||||
card-templates-cloze = Cloze { $val }
|
card-templates-cloze = Cloze { $val }
|
||||||
card-templates-deck-override = Deck Override...
|
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-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-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 }):
|
card-templates-enter-new-card-position-1 = Enter new card position (1...{ $val }):
|
||||||
|
|
|
@ -754,6 +754,31 @@ class CardLayout(QDialog):
|
||||||
dst["afmt"] = "{{FrontSide}}\n\n<hr id=answer>\n\n%s" % src["qfmt"]
|
dst["afmt"] = "{{FrontSide}}\n\n<hr id=answer>\n\n%s" % src["qfmt"]
|
||||||
dst["qfmt"] = m.group(2).strip()
|
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:
|
def onMore(self) -> None:
|
||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
|
|
||||||
|
@ -794,6 +819,10 @@ class CardLayout(QDialog):
|
||||||
assert a is not None
|
assert a is not None
|
||||||
qconnect(a.triggered, self.onTargetDeck)
|
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())
|
a = m.addAction(tr.card_templates_browser_appearance())
|
||||||
assert a is not None
|
assert a is not None
|
||||||
qconnect(a.triggered, self.onBrowserDisplay)
|
qconnect(a.triggered, self.onBrowserDisplay)
|
||||||
|
|
Loading…
Reference in a new issue