Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Copy template as markdown" button. #3719

Merged
merged 9 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ftl/core/card-templates.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
card-templates-copy-info = Copy Info to Clipboard
card-templates-copy-info = Copy to Clipboard

Copy link
Member

@dae dae Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong feelings, but is 'info' really adding much here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong feelings either but I just wanted to make it clear that you couldn't paste it into another template or something like that.

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 }):
Expand Down
29 changes: 29 additions & 0 deletions qt/aqt/clayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,31 @@ def _flipQA(self, src: dict, dst: dict) -> None:
dst["afmt"] = "{{FrontSide}}\n\n<hr id=answer>\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)

Expand Down Expand Up @@ -794,6 +819,10 @@ def onMore(self) -> None:
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)
Expand Down