mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-04 05:44:50 +00:00
Markdown fragment files #350
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @WattsC-90 on GitHub (Mar 1, 2020).
Is it possible, with the library as it is, to suport fragmented markdown files? I am looking to hse this library as a documentation tool, and the only feature i cant see listed is file fragments! If not, ill have a dig through the code when i get a moment..
@MihaZupan commented on GitHub (Mar 1, 2020):
Can you show a small example of what you mean? Like C#'s partial classes, but for markdown?
@WattsC-90 commented on GitHub (Mar 1, 2020):
Kind of, but with the ability for the partial file to be unpackaged at the inclusion line..
See this plugin for vs code https://marketplace.visualstudio.com/items?itemName=yzane.markdown-pdf in the section markdown-it-include. Unfortunately i cant permalink
@MihaZupan commented on GitHub (Mar 1, 2020):
There is no out-of-the-box support for something like this, but it should be rather straight forward to implement as an extension.
For example, you can implement a parser to catch the include syntax and emit a
MarkdownIncludeBlock.Then implement an
HtmlRenderer<MarkdownIncludeBlock>to emit theMarkdown.ToHtmlof the specified file.@WattsC-90 commented on GitHub (Mar 4, 2020):
@MihaZupan I have a preliminary cut of the code working, I have found some restrictions though with potential rendering implementation.. I dont want to ruin the commit history though.. is it OK to commit and push on a branch to the repo?
@MihaZupan commented on GitHub (Mar 4, 2020):
If you have a local change, you can fork this repo and push your changes there.
@WattsC-90 commented on GitHub (Mar 5, 2020):
done =] welcome the feedback (but will add a disclaimer.. it was late and i was tired) not that a coder has used THAT excuse before ;)
The SimpleExample project has two markdown files and shows the include line working/rendering
@MihaZupan commented on GitHub (Mar 5, 2020):
That's when the cool code appears.
Thanks. Yes, that would be the general idea for approaching it.
From the comments in the code, I see you've also thought about a few problems I'll mention below.
This could be a neat extension, but it would require a few more usability additions, at minimum:
UseMarkdownIncludeor somthing similar), or alternatively a callback that fetches the filepath/source based on the path (just aFunc<string, string>).main.md > header.md > main.md > header.md (boom), as we see the included file name.I would be careful about using
:[alternate-text](includeTest.md)as the syntax as it could be easy to produce false-positives with links to other files. What the extension you linked to does is!!!include(header.md)!!!, but that's up to personal preference and could be made configurable if needed.Comments about the implementation:
For example you have
MarkdownPipelineBuilder.UseMarkdownInclude(SomeConfig)which adds anew MarkdownIncludeExtension(SomeConfig)to the pipeline. The extension then adds the parser and renderer while flowing the configuration to them. It can also capture the pipeline, so that you can use it in the renderer.new StringBuilder()withStringBuilderCache.Local(). A side note on StringBuilder: it's more efficient to reuse it by doingsb.Length = 0than to allocate a new one.To concider: Optionally cache the included files? I would expect the common use case for this to include the header/footer that doesn't change.
@WattsC-90 commented on GitHub (Mar 5, 2020):
That's weird.. this confused me so I looked at the page i linked to, the
markdown-it-includeuses the format you suggest, but the markdown pdf extension for VS Code uses the one I implemented.. I agree the formatinclude(path)is better given the closeness to the link style/format. I will switch it over to use themarkdown-it-includeformat instead, in addition the "alternate name" doesnt actually make sense in this context either so its just plain unnecessary.The path is assumed to always be local/relative, but a check could be added to enable that not being the case.
See what I mean about coding tired! I knew that ! :( I didn't know about the
StringBuilderCachethough, that will be a definite improvement and reduce the allocations.So moving forward:
!!!include(file)!!!.)Thanks for the feedback!
@xoofx commented on GitHub (Mar 5, 2020):
I have suggested this in the past, but sometimes this problem is handled differently through a text templating (e.g Jekyll with GitHub pages). You can use something like scriban for example (I did use it along Markdig to implement a prototype of static website generator for instance).
But if a markdown syntax is not enough common (supported by a few of the major Markdown engine), I would prefer not to be included in Markdig default extensions. For example, they are using their own include syntax in DocFx and it is working fine for their case.
@ipoley-r7 commented on GitHub (Apr 7, 2020):
@WattsC-90 - Do you have your latest changes committed anywhere? I'd love to leverage what you've created so far and extend upon it if need be. Nice work!!!
@WattsC-90 commented on GitHub (Apr 7, 2020):
Unfortunately not, given everything covid related at the moment iv been working from home and as such tried to stay away from code in the evenings! Wasnt ever leaving the screen otherwise. My intention was to try do a couple of hours this weekend which will move it to an extension as opposed to fully inside the main engine.
I will let you know where I get to..