Render code snippet from a file #526

Closed
opened 2026-01-29 14:38:48 +00:00 by claunia · 3 comments
Owner

Originally created by @rafaelarnosti on GitHub (Apr 4, 2022).

Hello,

I'd like to know if it's possible to render using markdig, a CodeSnippet from other file, like the exemple bellow:

    ~\View\Errorpage.cshtml
Originally created by @rafaelarnosti on GitHub (Apr 4, 2022). Hello, I'd like to know if it's possible to render using markdig, a CodeSnippet from other file, like the exemple bellow: ```csharp ~\View\Errorpage.cshtml ```
claunia added the question label 2026-01-29 14:38:48 +00:00
Author
Owner

@xoofx commented on GitHub (Apr 4, 2022):

I'm not sure to understand: in your example above, it is a cshtml file, not a markdown file. What is the link? Do you mean that you would like to include markdown files in other markdown files?

@xoofx commented on GitHub (Apr 4, 2022): I'm not sure to understand: in your example above, it is a cshtml file, not a markdown file. What is the link? Do you mean that you would like to include markdown files in other markdown files?
Author
Owner

@rafaelarnosti commented on GitHub (Apr 4, 2022):

I have a cshtml file and I want to put the path in my markdown and when it render the code inside the file will be render together with my markdown

@rafaelarnosti commented on GitHub (Apr 4, 2022): I have a cshtml file and I want to put the path in my markdown and when it render the code inside the file will be render together with my markdown
Author
Owner

@xoofx commented on GitHub (Apr 5, 2022):

So it's possible, you could maybe use the link syntax with a special character in the label e.g [@code](~\View\Errorpage.cshtml)

Then, you can parse the document, get all the links (e.g doc.Descendants<LinkInline>()) with a @code label and replace them with some FencedCodeBlock before rendering to HTML.

@xoofx commented on GitHub (Apr 5, 2022): So it's possible, you could maybe use the link syntax with a special character in the label e.g `[@code](~\View\Errorpage.cshtml)` Then, you can parse the document, get all the links (e.g `doc.Descendants<LinkInline>()`) with a `@code` label and replace them with some `FencedCodeBlock` before rendering to HTML.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#526