MyST-Parser
MyST-Parser copied to clipboard
`only` directive does not work when it contains an `include` directive and the included file contians Markdown
Describe the bug
context
The only directive mocked from Sphinx does not work when it contains an include directive that includes a file containing Markdown.
It works as expected when the file is not Markdown (In the reproducer, remove the ## from the test file).
expectation
When using {only} not html and building with make html, the content from the included file should not be there.
bug But instead its content is included.
problem
This defeats the purpose of the only directive.
Reproduce the bug
Here is a reproducer:
virtualenv .venv
. .venv/bin/activate
pip install sphinx myst-parser
sphinx-quickstart --sep -p test -a test -v test -r test -l en --extensions myst_parser
rm source/index.rst
echo '## this is a test' > source/test
echo '# Hello world!
````{only} not html
```{include} test
```
````
' > source/index.md
make html
grep 'this is a test' build/html/index.html
List your environment
$ python --version
Python 3.10.5
$ uname -srvmo
Linux 5.18.0-2-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.18.5-1 (2022-06-16) x86_64 GNU/Linux
$ pip list
Package Version
----------------------------- ---------
alabaster 0.7.12
Babel 2.10.3
certifi 2022.6.15
charset-normalizer 2.1.0
docutils 0.18.1
idna 3.3
imagesize 1.4.1
Jinja2 3.1.2
markdown-it-py 2.1.0
MarkupSafe 2.1.1
mdit-py-plugins 0.3.0
mdurl 0.1.1
myst-parser 0.18.0
packaging 21.3
pip 22.2
Pygments 2.12.0
pyparsing 3.0.9
pytz 2022.1
PyYAML 6.0
requests 2.28.1
setuptools 59.6.0
snowballstemmer 2.2.0
Sphinx 5.1.1
sphinxcontrib-applehelp 1.0.2
sphinxcontrib-devhelp 1.0.2
sphinxcontrib-htmlhelp 2.0.0
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 1.0.3
sphinxcontrib-serializinghtml 1.1.5
typing_extensions 4.3.0
urllib3 1.26.11
wheel 0.37.1
I can confirm similar behavior with myst-parser==2.0.0 where the following snippet will end up in the LaTeX generated pdf file
```{{only}} html
## The Section
* Should exist in the html report
* Should not exist in the pdf
```