Skip to content

Regex: Flashcards from native callout blocks (admonitions) #332

@GBergatto

Description

@GBergatto

This regex creates a flashcards from callout blocks, that are now native to Obsidian as of v0.14.0.

Regex line: (?:\> \[!anki\]-) ([^\n]+)\n(.+(?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))*)

To make it more specific, the regex will only match a callout block that start with > [!anki]-.
This allows you to keep using all defaults callout blocks without any issues.

Example

> [!anki]- First flashcard
> This is the body of the callout
> $Math$ and `inline code` both work.  
> $$\dfrac{\sum _{i}m_{i}\vec{a}_{i}}{m}$$

> [!check]- Any other callout block will be left untouched
> This will NOT generate a flashcard

> [!anki]- Second flashcard
Lines of the body don't have to start with a > just like for Obsidian
These lines will be displayed by Obsidian as part of the callout block's body and will be part of the flashcard.

This is not part of the flashcard as it's separated by a blank line. 

image

image

Why this regex?

I see this regex as a replacement for the Markdown table style. The goal is the same: it looks nice when rendered in the Preview view of Obsidian.

The benefits over the markdown table are:

  • callout blocks can be collapsed
  • more selective: only one type of callout is matched while all other are left untouched
  • more customizable: it's possible to create a CSS snippet to style this custom block any way you like. (See image below)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions