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

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

Open
Andre601 opened this issue Jan 30, 2025 · 0 comments

Comments

@Andre601
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant