Testable code snippets #4373
Replies: 1 comment 6 replies
-
I think something like this is achievable but is there already a canned what to do this? Probably not. I'm not 100% certain as to what you envision your solution to look like, but there are ways to include code from snippets as code content: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/. Is this extension powerful enough to use in the way you wish to? 🤷🏻 There are plans to extend the aforementioned plugin to some extent, but I have no idea as to the complexity you wish to employ and whether that exceeds the scope of the plugin. But, could something be constructed with such a plugin as it exists currently, I believe so, yes. We also have custom-fenced code blocks. Theoretically, a user could construct a special fence that overrides the default. It could run some tests on a given code block and then pass it on to be highlighted by the underlying default highlighter. There is a lot that can be done with custom fences, one example is what you see in this example. Our code block source has code that is executed to create the examples seen in the documentation. They are then able to edit the original source and execute it live. You could possibly parse the exported HTML, find code blocks, and do some sort of validation on the code as well. I have no idea as to what your actual requirements are, but with proper motivation and time, I am sure some solution could be crafted. Now, is there a canned solution that can already achieve what you'd like? Probably not, but I think it is possible. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Code snippets easily go out of date.
In a different $job we acutely felt this pain in tutorials and reduced it by writing a Hugo short code that let us include the snippet from "real" source code files.
The code files blocks were annotated with comments to begin-and-identify the block, and end the block.
This meant that the code snippets that were exposed in docs:
Is this something that can be achieved inside this ecosystem too? Where would I start to look for it?
Beta Was this translation helpful? Give feedback.
All reactions