Skip to content

Use PyMdownX's blocks extension in favour of admonition, details and tabs #60

@Andre601

Description

@Andre601

Since quite a while does PyDownX provide a blocks extension containing replacements for already existing extensions.

As an example, blocks.admonition can be used as a drop-in replacement for the Python Markdown's admonition extension.

Structure

The structure of a block:

/// <block identifer> [| optional title]
    <option> (Needs indentation)

[optional content]
///

you can also provide just | without a title to not have any title set, which in case of admonition boxes would only display the content without a title section.

Nested blocks (i.e. an admonition box inside a tab block) requires a different number of / than its "parent" block.
So f.e. when the parent is /// would the nested block require at least //// to work.

Benefits

Main benefit is removal of indentation, which can make the markdown file harder to read due to understanding 4+ spaces as a code block.

Below are some examples using a details element with a nested admonition element:

Current setup

Input:

??? question | "Lorem ipsum"
    Hello World!
    
    !!! info | "Lorem ipsum"
        Hello **again** World!

Rendered markdown:

??? question | "Lorem ipsum"
Hello World!

!!! info | "Lorem ipsum"
    Hello **again** World!

Blocks setup

Input:

/// details | Lorem ipsum
    type: question

Hello World!

//// admonition | Lorem ipsum
    type: info

Hello **again** World!
////
///

Rendered markdown:

/// details | Lorem ipsum
type: question

Hello World!

//// admonition | Lorem ipsum
type: info

Hello again World!
////
///

Downsides

One downside can be seen with the examples provided. Namely that by default there is no distinct name for each admonition type set due to the same syntax being used for multiple blocks.
You would need to define type: <type> as an option, which is done by indenting the lines after the opening block with 4 spaces and leaving an empty line after to separate it clearly.

However, blocks allow you to configure types that should be registered as block name to specify a specific type.
As an example, adding info to blocks.admonition's types setting would allow me to use

/// info | title

///

...to display an admonition box of type info.
The same system applies to the other blocks as this is a global setting.

More info

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