mystmd icon indicating copy to clipboard operation
mystmd copied to clipboard

Support including only part of a file with the `{include}` directive

Open choldgraf opened this issue 1 year ago • 0 comments

Currently, you can use {literalinclude} to include only a subset of a file for inclusion. For example, based on line number of text match.

It would be useful if the same were possible for {include}. This allows you to re-use subsets of content via {include}, which is particularly useful if you'd like a markdown file to be readable outside of MyST (like in GitHub) but also used within MyST as well.

Here's a PR where we're trying to use this to have CONTRIBUTING.md be re-usable for MyST:

  • https://github.com/executablebooks/mystmd/pull/1095

Here's a testimonial from one user that mentions how this is useful:

From @LecrisUT:

In order to better display these links, I suggest to use reference-style link, i.e.

[Text to display][link-id]

[Link-id]: /path/to/object

Combined with include with start-after end-before, you can use html comments like <!-- MYST-START --> to separate the text part from the actual link and have inv: style links in the html document and actual links in the Github rendered view.

Hope such design works in mystmd as well. Might depend on the order of markdown rendering

Example: https://github.com/LecrisUT/CMake-Template/blob/main/README.md?plain=1

choldgraf avatar Apr 11 '24 19:04 choldgraf