Skip to content

feat: add AnkiConnect plugin support#29

Open
MarkoSagadin wants to merge 3 commits intoMochitto:mainfrom
MarkoSagadin:feature/ankiconnect
Open

feat: add AnkiConnect plugin support#29
MarkoSagadin wants to merge 3 commits intoMochitto:mainfrom
MarkoSagadin:feature/ankiconnect

Conversation

@MarkoSagadin
Copy link
Collaborator

This commit support adds for uploading cards via AnkiConnect plugin.

Generated cards are now by default uploaded to the Anki via the plugin.
The accompanying images references in the cards are also uploaded via
the plugin.

The addition of the AnkiConnect support means that frontmatter block is
mandatory, since some of the fields are required by the plugin to
upload the cards to the correct Anki deck, to use the correct note type,
etc.

The mandatory formatter fields are:

  • deck_name
  • note_type_basic
  • note_type_cloze

The tags field is optional.

The generation of Anki cards in CSV format is now marked as a legacy
feature, it is by default turned off.

User can also change the default URL of the AnkiConnect server via the
.ini config file.

Future work:

  • The code currently skips when trying to upload a card duplicate. In
    the future there an update system could be implemented. This would
    support a usecase where users would like to fix the already uploaded
    card via the markdown input file.
  • Currently the users need to provide the images file to the md2anki
    config file. This is not really needed, as the information about the
    image location is in the input markdown document itself. So that could
    be removed and thus UX would be a bit better, since that would be one
    less config option to carry about.
  • Currently the images must be local, there is no support for providing
    URL image links. Support for that could be added.

Related: #16
Closes: #3

Note

This PR was branched out from #28 PR. #28 should be first merged, and then this PR will show valid changes.

Copy link
Owner

@Mochitto Mochitto left a comment

Choose a reason for hiding this comment

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

Looks awesome! :))
Minor comments on documentation

README.md Outdated
Mandatory fields:
- `deck_name` - The name of the deck where the cards will be imported.
- `note_type_basic` - The name of the note type for basic cards.
- `note_type_clode` - The name of the note type for cards with clozes.
Copy link
Owner

Choose a reason for hiding this comment

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

Typo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

- Support for continuous integration with GitHub Actions. Backend and frontend will now build with every push to the `main` branch or to the opened PR. (@MarkoSagadin)
- Automated release process with GitHub Actions. A new release can now be manually triggered by providing the next version tag under the _Actions_ tab in the GitHub Web UI. (@MarkoSagadin)
- Added information on how to build the backend project for developers.
- Added first configuration option for frontmatter metadata blocks in the input markdown files! [Frontmatter blocks] allow you to configure options per single markdown file. The first added property is called `no_tabs`. When set to `True`, it disables tabs in generated cards. (@MarkoSagadin)
Copy link
Owner

Choose a reason for hiding this comment

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

Missing notes on the other frontmatter options and ankiconnect support

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

Images that are already present won't be added twice and will be skipped (based on filename).
If you prefer checking the images before importing them manually, you can point to another folder or leave the default one.
**Notice:** when images are copied, they lose their metadata: this is due to security, as others' could read your images metadata if you were to share your cards, and for how the python library that handles the copying process is implemented.
[legacy CSV file]: ./docs/legacy_importing_cards_with_csv.md
Copy link
Owner

Choose a reason for hiding this comment

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

You can turn this into a markdown link [Legacy CSV imports]( ./docs/legacy_importing_cards_with_csv.md) and put them in-line instead of as a foot-note

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually this also a markdown link, it just uses a bit different syntax. Markdown footnotes are a bit different.

Copy link
Owner

Choose a reason for hiding this comment

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

This is just great :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks :)

@Mochitto
Copy link
Owner

Oops I commented on the commits one by one here :')

There seems to be conflicts 🙈 I think the changes are great and ready to be pushed to pypi; I'll do that as soon as the comments are solved :)

Great job!

@Mochitto Mochitto moved this from Backlog to In Progress in Markdown2Anki Feb 25, 2025
Copy link
Owner

@Mochitto Mochitto left a comment

Choose a reason for hiding this comment

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

I've also noticed that you've added some notes for future developments in one of the commit messages; you might like to open issues so that you can use the Markdown2Anki kanban to handle their development and track them :)

deck_name: str,
note_type_basic: str,
note_type_cloze: str,
tags: list[str] | None = None,
Copy link
Owner

Choose a reason for hiding this comment

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

It would be useful to add a md2anki tag to all cards made by markdown2anki by default, so that users can query them easily #21.

This should be easy to add as "default" and have the incoming list append to it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added.

@MarkoSagadin
Copy link
Collaborator Author

I have cleaned up the merge conflicts in the PRs below this one, I only need to add the md2anki for this one, however I fear that this will have to wait until the next week (busy weekend ahead). Will ping you when I get back to this.

@MarkoSagadin MarkoSagadin force-pushed the feature/ankiconnect branch 2 times, most recently from 2b8387e to 89bc314 Compare March 3, 2025 18:43
@MarkoSagadin
Copy link
Collaborator Author

Added the default md2anki tag. This PR is ready for final review, just keep in mind that #28 should be first merged (and that one is also on top of another branch).

With this change is now possible to disable presence of tabs, by adding
the below frontmatter snippet to the top of the markdown file:

---
no_tabs: True
---

If present then:
- 'L', 'R', '-', '+' tab flags are ignored, only 'F' and 'B' matter.
- Tab labels don't matter

To avoid possible styling interference two new classes were created:
body and body__content. They are a direct copy of the  tab__body and
tab__body_content classes, only that their display property is set to
'flex' instead of none.

The python code now generates the html out of markdown as it would
normally and wraps content in the above two mentioned containers.
That way no tab-related styling is present.

Finally, all the changes in the main.ts make the presence of the
.tab_group selector optional. If not found then no extra logic is
enabled and content is present on single page.
It is now expected that every markdown document contains frontmatter
block with three required fields:
- deck_name,
- note_type_basic and
- note_type_clozes

tags and no_tabs fields are optional. Currently only no_tabs field is
actually used.

Closes: Mochitto#11
This commit adds support for uploading cards via AnkiConnect plugin.
Generated cards are now by default uploaded to the Anki via the plugin.
The accompanying images references in the cards are also uploaded via
the plugin.

The addition of the AnkiConnect support means that frontmatter block is
mandatory, since some of the fields are required by the plugin to
upload the cards to the correct Anki deck, to use the correct note type,
etc.

The mandatory formatter fields are:
- deck_name
- note_type_basic
- note_type_cloze

The tags field is optional.

The generation of Anki cards in CSV format is now marked as a legacy
feature, it is by default turned off.

User can also change the default URL of the AnkiConnect server via the
.ini config file.

Future work:
- The code currently skips when trying to upload a card duplicate. In
  the future there an update system could be implemented. This would
  support a usecase where users would like to fix the already uploaded
  card via the markdown input file.
- Currently the users need to provide the images file to the md2anki
  config file. This is not really needed, as the information about the
  image location is in the input markdown document itself. So that could
  be removed and thus UX would be a bit better, since that would be one
  less config option to carry about.
- Currently the images must be local, there is no support for providing
  URL image links. Support for that could be added.

Related: Mochitto#16
Closes: Mochitto#3, Mochitto#21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Use Anki's API to send cards to Anki

2 participants