How to use snippets to show code? #1921
-
I do have some code blocks (triple backtick) for which I do want to load the content from an external file, so snippets was the most likely candidate. Still, when I inserted the snippet as the body of the code block it did render as plain text instead of including the external code. What is the solution for showing code from external files with mkdocs?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Please provide a minimal reproducible example. I'm not sure how you've configured anything, how the files are relative to each other. |
Beta Was this translation helpful? Give feedback.
-
As there has been no response back, I'll give my official statement. You must configure Snippets with a base path. Python Markdown has no concept of file location as it only deals with a text buffer. The file information, assuming there even is one associated with the buffer, is not tracked in Python Markdown. For this reason, a base path is needed. If you give it one or more base paths, the specified snippet path will be compared relatively against each base path until it finds the file. All of this is covered in the documentation: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/. If you have a specific question about something in the documentation, please feel free to ask more specific questions, particularly with examples of what you are doing. |
Beta Was this translation helpful? Give feedback.
As there has been no response back, I'll give my official statement. You must configure Snippets with a base path. Python Markdown has no concept of file location as it only deals with a text buffer. The file information, assuming there even is one associated with the buffer, is not tracked in Python Markdown. For this reason, a base path is needed. If you give it one or more base paths, the specified snippet path will be compared relatively against each base path until it finds the file. All of this is covered in the documentation: https://facelessuser.github.io/pymdown-extensions/extensions/snippets/.
If you have a specific question about something in the documentation, please feel free…