anki.tags
=========

.. py:module:: anki.tags

.. autoapi-nested-parse::

   Anki maintains a cache of used tags so it can quickly present a list of tags
   for autocomplete and in the browser. For efficiency, deletions are not
   tracked, so unused tags can only be removed from the list with a DB check.

   This module manages the tag cache and tags for notes.



Attributes
----------

.. autoapisummary::

   anki.tags.TagTreeNode
   anki.tags.CompleteTagRequest
   anki.tags.MARKED_TAG


Classes
-------

.. autoapisummary::

   anki.tags.TagManager


Module Contents
---------------

.. py:data:: TagTreeNode

.. py:data:: CompleteTagRequest

.. py:data:: MARKED_TAG
   :value: 'marked'


.. py:class:: TagManager(col: anki.collection.Collection)

   Bases: :py:obj:`anki._legacy.DeprecatedNamesMixin`


   Expose instance methods/vars as camelCase for legacy callers.


   .. py:attribute:: col


   .. py:method:: all() -> list[str]


   .. py:method:: tree() -> TagTreeNode


   .. py:method:: clear_unused_tags() -> anki.collection.OpChangesWithCount


   .. py:method:: set_collapsed(tag: str, collapsed: bool) -> anki.collection.OpChanges

      Set browser expansion state for tag, registering the tag if missing.



   .. py:method:: bulk_add(note_ids: collections.abc.Sequence[anki.notes.NoteId], tags: str) -> anki.collection.OpChangesWithCount

      Add space-separate tags to provided notes, returning changed count.



   .. py:method:: bulk_remove(note_ids: collections.abc.Sequence[anki.notes.NoteId], tags: str) -> anki.collection.OpChangesWithCount


   .. py:method:: find_and_replace(note_ids: collections.abc.Sequence[int], search: str, replacement: str, regex: bool, match_case: bool) -> anki.collection.OpChangesWithCount

      Replace instances of 'search' with 'replacement' in tags.
      Each tag is matched separately. If the replacement results in an empty string,
      the tag will be removed.



   .. py:method:: rename(old: str, new: str) -> anki.collection.OpChangesWithCount

      Rename provided tag and its children, returning number of changed notes.



   .. py:method:: remove(space_separated_tags: str) -> anki.collection.OpChangesWithCount

      Remove the provided tag(s) and their children from notes and the tag list.



   .. py:method:: reparent(tags: collections.abc.Sequence[str], new_parent: str) -> anki.collection.OpChangesWithCount

      Change the parent of the provided tags.
      If new_parent is empty, tags will be reparented to the top-level.



   .. py:method:: split(tags: str) -> list[str]

      Parse a string and return a list of tags.



   .. py:method:: join(tags: list[str]) -> str

      Join tags into a single string, with leading and trailing spaces.



   .. py:method:: rem_from_str(deltags: str, tags: str) -> str

      Delete tags if they exist.



   .. py:method:: canonify(tag_list: list[str]) -> list[str]


   .. py:method:: in_list(tag: str, tags: list[str]) -> bool

      True if TAG is in TAGS. Ignore case.



   .. py:method:: register(tags: collections.abc.Collection[str], usn: int | None = None, clear: bool = False) -> None


   .. py:method:: by_deck(did: anki.decks.DeckId, children: bool = False) -> list[str]


