Error parsing relative path in `{glue}` role with subcommand
Describe the bug
If I use the {glue} role with a specific subcommand (e.g. {glue:text}), I get a warning that the key is not found, even when the path is specified correctly. For example, this: {glue:text}demographics.md::num_respondents` gives the following warning:
WARNING: No key 'demographics.md:' found in glue data for this document. (use `path::key`, to glue from another document) [mystnb.glue] [mystnb.glue]
The structure of the warning to me implies that there is a problem with the parsing of colons here, as the demographics.md: part of the warning is very suspicious.
Indeed when I remove the :text subcommand from the {glue} directive, the warning disappears: {glue}demographics.md::num_respondents`.
Possibly related to #591
Reproduce the bug
For ease of reproduction, I recommend creating two new dummy files in the same directory of an existing myst-nb project:
- Create
foo.mdwith the following contents:
---
jupytext:
formats: md:myst
text_representation:
format_name: myst
kernelspec:
display_name: Python 3
name: python3
---
# FOO
```{code-cell} ipython3
---
tags: [hide-input]
---
from myst_nb import glue
glue("answer", 42, display=False)
```
- Create
bar.mdwith the following contents:
---
jupytext:
formats: md:myst
text_representation:
format_name: myst
kernelspec:
display_name: Python 3
name: python3
---
# BAR
This line warns and fails to link: {glue:text}`foo.md::answer`.
This line is fine: {glue}`foo.md::answer`.
- Add
fooandbarto the toctree - Then build the project:
make html. This should give the warning:
<path/to>/bar.md:13: WARNING: No key 'foo.md:' found in glue data for this document. (use `path::key`, to glue from another document) [mystnb.glue] [mystnb.glue]
List your environment
I'm using myst-nb via sphinx directly without the jupyter-book CLI, so hopefully relevant info:
myst-nb 1.1.1
myst-parser 4.0.0
Sphinx 8.0.2
@rossbar - please open a PR once you've found a solution for this 😉
Hi 😊
The problem here comes from the fact that the PendingGlueReferences are only implemented for text/plain and text/html in {glue} and not {glue:text}
https://github.com/executablebooks/MyST-NB/blob/60ed01dfa597e62090d43b89b68cc658bd1c6706/myst_nb/ext/glue/directives.py#L39-L55
I think one option here is to add the PendingGlueReferences to all glue directives, but this needs a rework of the transformation later since the specified directives {glue:text|md|math|figure} introduce extra options which are lost in the current implementation of ReplacePendingGlueReferences
The other option is to update the docs in order to clarify that this feature is only available with unspecified glue :honey_pot:
related to #675