Include directive: Allow separate includes for reference links and reference definition
See original GitHub issueDescribe the bug
foo.md
<!-- contents-begin-md -->
Hello world [Test][test].
<!-- contents-end-md -->
MyST-Parser is awesome!!!
<!-- references-begin-md -->
[test]: http://example.com/
<!-- references-end-md -->
bar.rst
.. contents-begin-rst
Hello world `Test <test_>`__
.. contents-end-rst
.. references-begin-rst
.. _test: http://example.com/
.. references-end-rst
1.
When I include parts of foo.md in another md.
```{include} foo.md
---
start-after: <!-- contents-begin-md -->
end-before: <!-- contents-end-md -->
---
```
```{include} foo.md
---
start-after: <!-- references-begin-md -->
end-before: <!-- references-end-md -->
---
```
When rendering you get where the reference is lost:
Hello world [Test][test].
2.
When I include parts of bar.rst in an md.
```{eval-rst}
.. include:: bar.rst
:start-after: contents-begin-rst
:end-before: contents-end-rst
.. include:: bar.rst
:start-after: references-begin-rst
:end-before: references-end-rst
```
So it renders as a link but points to: host/#test
instead of to http://example.com/
3.
If I include foo.md in an .rst:
.. include:: foo.md
:parser: myst_parser.sphinx_
:start-after: <!-- contents-begin-md -->
:end-before: <!-- contents-end-md -->
.. include:: foo.md
:parser: myst_parser.sphinx_
:start-after: <!-- references-begin-md -->
:end-before: <!-- references-end-md -->
Hello world [Test][test].
is obtained. The link is not rendered.
4.
When I include parts of bar.rst in another .rst
.. include:: bar.rst
:start-after: contents-begin-rst
:end-before: contents-end-rst
.. include:: bar.rst
:start-after: references-begin-rst
:end-before: references-end-rst
It renders correctly.
Reproduce the bug
Source code: https://github.com/eyllanesc/myst_bug Output: https://myst-bug.readthedocs.io/en/latest/index.html
List your environment
- sphinx==4.4.0
- myst_parser==0.16.1, 0.17.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Include directive - Wikipedia
Many programming languages and other computer files have a directive, often called include (sometimes copy or import ), that causes the contents of...
Read more >Includes | Asciidoctor Docs
An include directive imports content from a separate file or URL into the content of the current document. When the current document is...
Read more >JSP - Include Directive - Tutorialspoint
The include directive is used to include a file during the translation phase. This directive tells the container to merge the content of...
Read more >java - What's the difference between including files with JSP ...
Include directive uses file attribute to specify resources to be included while include action uses page attribute for the same purpose. Share.
Read more >Documentation - Triple-Slash Directives - TypeScript
Triple-slash directives are single-line comments containing a single XML tag. The contents of the comment are used as compiler directives.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, I did some digging.
The problem is basically the order in which things are done:
{include}
directive.This means that if the included file defines some references, they are not available, when the references in the original file are resolved.
There would be a few ways to potentially solve this:
MystParser.parse
intercept anyinclude
directives before callingrender
and just add that content to theinputstring
. You would need to make sure to handle recursion correctly.markdown_it
plugin that provides the include file functionality. I think, this might be doable but at the moment, myst-parser comes with a set of pre-activated plugins and I could not find a way to tell it to activate more…For me, having a collection of references in an included file is really something that makes my life easier…
@chrisjsewell and maybe @choldgraf : is there any chance of this getting included? I would be happy and capable of contributing code and time. But I would need some feedback from you:
I might have found a “workaround” for the first problem . Using the MySt directive with syntax from rst works in my case:
(note the extra colon before “start-after” and missing dashes)
myst-parser 0.18.0 Sphinx 5.1.1