New Blocks Extensions in 9.10! #1973
Replies: 22 comments 73 replies
-
Release has been made. |
Beta Was this translation helpful? Give feedback.
-
Should I be able to use an Should I move this to an "Issue"? Given /// html | a[src="./basics/getting-started/"]
### Getting Started
More content that may use markdown.
/// I receive an error:
full error
These elements (just for testing) do not give an error: Update (after the reply): I was using |
Beta Was this translation helpful? Give feedback.
-
I just released version 0.1 of bootstrap4markdown which uses Blocks to define some Bootstrap components. So far only alerts and carousels are supported. |
Beta Was this translation helpful? Give feedback.
-
On the initial documentation page when it lists the different extensions associated with blocks it reads:
when it really should be:
|
Beta Was this translation helpful? Give feedback.
-
Could |
Beta Was this translation helpful? Give feedback.
-
Really like this syntax direction. I wonder if there's room to make the specifying of details more ergonomic. Class namesDoes present syntax presume blocks names to not contain spaces? If so: it'd be nice to take words preceding the block name and read them as classes. e.g
Open/closedIt'd also be nice to shortcut the
Combined with the above would make for some really satisfying fallbacks to plain text.
|
Beta Was this translation helpful? Give feedback.
-
Looks like |
Beta Was this translation helpful? Give feedback.
-
Is there a way to not include the title? When I define this in the original admonition does it not display any title:
However, since the way you define titles in blocks is different, I can't use the above. And using this here won't work either:
It will use the admonition type as title then. And using a So, is there a way in blocks to have it not include the title? |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to have an option to override what title is being displayed by default for an admonition block if no title is defined? Like, f.e. markdown_extensions:
- pymdownx.blocks.admonition:
types:
- custom # custom admonition type
titles:
custom: Custom Title This would use
while reducing the number of times to write the title... Would also help if you want to change the title, because then you only change it once instead of n times... |
Beta Was this translation helpful? Give feedback.
-
I wonder how you all match opening block sequence with the closing one when you have a big tab/admonition? Consider the following example:
It is hard to match opening and ending blocks without ide to color tagging them. |
Beta Was this translation helpful? Give feedback.
-
I love this new syntax! 🚀 🎉 I wrote a script to automatize upgrading the syntax of my admonition blocks in my markdown files. I just used it for SQLModel, I'll use it later to also upgrade FastAPI, Typer, and Asyncer. import os
import re
import subprocess
from pathlib import Path
base_dir = Path(__file__).parent.parent
def update_admonition():
os.chdir(base_dir)
md_files = list(Path("docs").glob("**/*.md"))
# md_files = [Path("docs/db-to-code.md")]
re_str = r"!!! (?P<type>[^\n\"]*)\s?(\"(?P<title>[^\n\"]*)\")?\n(?P<content>(\n| .*)*)\n*"
# md_file = md_files[25]
for md_file in md_files:
content = md_file.read_text()
def replace(match: re.Match):
type_ = match.group("type")
title = match.group("title")
block = match.group("content")
deindented_block = block.replace(" ", "")
result = f"/// {type_}"
if title:
result += f" | {title}"
result += f"\n\n{deindented_block.strip()}\n\n"
result += "///\n\n"
return result
new_content = re.sub(re_str, replace, content)
md_file.write_text(new_content)
if __name__ == "__main__":
update_admonition() |
Beta Was this translation helpful? Give feedback.
-
@facelessuser and all, It is a common perception, that md table syntax is not particularly enjoyable not convenient to define tables. What if Blocks could come to the rescue?
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Was there a fix for Blocks extension not being rendered in mkdocs-material when attrs contain not only classes but IDs as well? Here is a snippet that works
And the one that doesn't render
pymdown-extensions - 10.5 |
Beta Was this translation helpful? Give feedback.
-
I've found The equivalent tabs notation in the previous version didn't work with:
As the image was not being shown and tabs got broken. Just something not working: For images, we are using the plugins Resuming: this new version will kill ;-) |
Beta Was this translation helpful? Give feedback.
-
Can tabs be nested? What I'm trying:
What I'm getting: |
Beta Was this translation helpful? Give feedback.
-
I miss the |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I am searching for an inline/block delimiter that I can use in my MkDocs Material extension. I have two use cases where I am still looking for a good implementation:
This made me realize that the current delimiter isn't quite optimal. I cannot distinguish one-liners from blocks. Therefore, a start and end delimiter such as Some text {{{ latex | \textbf{ }}}bold in LaTeX only{{{ latex | }}}} Or for LaTeX blocks {{{ latex | \begin{something}
spam
}}} latex | \end{something} Not quite sure where I am going with this... |
Beta Was this translation helpful? Give feedback.
-
Not sure why, but code blocks aren't rendered inside details blocks? The ` are removed from the rendered page, but nothing else seems to change here. Here's the markdown file: https://github.com/DecentSoftware-eu/DecentHolograms-Wiki/blob/main/docs/general/actions.md?plain=1 And its corresponding, rendered page: https://wiki.decentholograms.eu/general/actions/ Edit: Nevermind... There are simply code blocks missing and it just so happens that I only checked those on the site.... Stupid me. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I'm trying to build a blocks extension but I'm not sure it's the right approach. 😅 (sorry for the long post). I want to include multiple source file examples inline in multiple tabs in a summary, from a new block (?) with a config. Use CaseIn my docs I have some sections that include external files inline. For that I use mdx-include. Now, in many cases, I have several versions of the same file, with old syntax for Python 3.8+ and newer syntax in 3.9 and 3.10. I also have versions using So, it's a lot of different Python example files for the same example (a matrix of combinations). Then I include them in tab blocks. Here's an example from SQLModel: https://github.com/fastapi/sqlmodel/blob/1eb40b1f33aaebd02f03fd1986e242b65c79d573/docs/tutorial/fastapi/read-one.md#L17 Currently, I include some lines of the file (not the entire file). And then at the end, I include a details block with the entire file (in case people want to copy-paste or check the entire thing), I currently do this only in the SQLModel docs. I have been wanting to refactor it, to make it much less verbose to write in Markdown and automatize including the other versions (Python 3.10, 3.8, Annotated, etc). My idea is to have one main file shown and include only the specific lines for that file, the highlighted lines only for that file, and then have a details block below including tabs with all the versions, with the entire files. I imagine it could be something like this: /// include Then the (block?) extension would look for that source file to include, check what versions are there, include inline the highest version available of the file (e.g. Python 3.10 with Annotated), only with the lines specified, add a comment in between the included lines like I tried for a few days to follow the tutorials and read all the docs for extensions with the Markdown package, the pymdown blocks docs, and the docs for Maybe my whole approach is wrong, because maybe don't need a block that wraps content, only has metadata that is then used to include new content on the fly. I also see that mdx_include is a preprocessor instead of a block processor and maybe that's what I should be doing instead of trying to do it with the block processors, not really sure. Side note, do you do any freelance work @facelessuser? Would you be willing to help me out start this? If so, please contact me on my email (I didn't find a way to reach out to you). 🤓 |
Beta Was this translation helpful? Give feedback.
-
9.10 introduces a new block extension type called Blocks. It provides a new generic block syntax inspired by reStructuredText Directives, but, while similar in some ways, they are different and should not be directly compared.
Blocks allow developers to more easily create special block containers for Markdown. In this release, we've actually reimplemented a number of plugins using the new Blocks approach: Tabbed and Details. We've also provided Blocks variants for Python Markdown's Admontions and Dictionary Lists. In addition, we've added a new HTML extension as well.
The aim of Blocks is to help eliminate the need for multiple levels of nesting when crating Markdown containers that nest. Additionally, it aims to provide a way to create new containers without having to constantly reinvent a new syntax that doesn't collide with other extensions.
Before, if we wanted to test some containers you could end up with something like this:
Now we can utilize the new Blocks extension to do:
Only Blocks that require raw content require the content to be indented code blocks, but they do not allow for nesting of other Blocks as raw content is ignored by the new Blocks extensions. Any Blocks extension that requires raw content will make that requirement known and under what circumstances.
Any and all feedback is welcome as this is a new experimental feature. While it is likely that no major changes will be made at this time, we are happy to hear if there are maybe some areas in which it could be improved.
Beta Was this translation helpful? Give feedback.
All reactions