Extracting unformatted fences just as SuperFences would #2214
-
Hi, thanks for the extension; it's used in a couple of projects I help maintain 👋 I'm using SuperFences and have a slightly related question to #1291. Is there a suggested way to extract the source form of fences via the same parsing as SuperFences? My use case is reading Markdown source files, extracting what would be permitted SuperFences code blocks from that source, and generating tests from those blocks for pytest. 1 That is, given a simplified Markdown document such as follows: This is some text.
```lang1
codeblock1
```
This is some more text.
> ```{.lang2 .extra-class linenums="1"}
codeblock 2
``` I would like to be able to access the content of the code in the Markdown source — It's the first time I've really had to look at the pymdown-extensions or Python-Markdown source. I've spent a couple of hours trying things with the SuperFences source, and looking at the Python Markdown API documentation. But I'm having trouble getting anywhere, and not sure if I'm trying to do something that isn't easily possible in a hack-free, maintainable way. Do I have to resort to writing my own code entirely, reimplementing the parsing of SuperFences to extract the code blocks? Or is there a simple approach I'm missing due to my naivety here? Footnotes
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can access the content with custom fences which we document: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/?h=custom+fe#custom-fences. You can do whatever you want with them. We use them to do some things like code blocks that we execute the content of: https://facelessuser.github.io/coloraide/ We also have an example where we take the content, and parse it in a Markdown sandbox: https://github.com/facelessuser/pymdown-extensions/blob/main/tools/pymdownx_md_render.py |
Beta Was this translation helpful? Give feedback.
You can access the content with custom fences which we document: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/?h=custom+fe#custom-fences.
You can do whatever you want with them. We use them to do some things like code blocks that we execute the content of: https://facelessuser.github.io/coloraide/
We also have an example where we take the content, and parse it in a Markdown sandbox: https://github.com/facelessuser/pymdown-extensions/blob/main/tools/pymdownx_md_render.py