MyST-Parser icon indicating copy to clipboard operation
MyST-Parser copied to clipboard

Allow at least one kind of substitution inside directive

Open senges opened this issue 1 year ago • 2 comments

Context

This issue is closely related to #172, especially https://github.com/executablebooks/MyST-Parser/issues/172#issuecomment-685923790.

As @nickcrider was explaining, there is an edge case where users needs to use {eval-rst} but are unable to use any kind of substitution as Jinja's {{ }} won't be evaluated and reST substitution .. |any| replace:: does not work either (throwing Undefined substitution referenced: "any" error).

To be a bit more precise, in my case, I'm using {eval-rst} to handle more complex tables offered by reST (to merge cells essentially). And it's quite a known fact that tables are hard to maintain when the content gets a bit large.

Until now, with basic markdown tables I was able to use Jinja substitution :

---
myst:
  substitutions:
    large_text: A very long long text here that would make table super ugly...
---

| Key   | Content          |
| :---- | :--------------- |
| Story | {{ large_text }} |

But with reST tables, I cannot manage to make it work :

---
myst:
  substitutions:
    large_text: A very long long text here that would make table super ugly...
---

```{eval-rst}
+------------------------+------------+----------+----------+
| Header row, column 1   | Header 2   | Header 3 | Header 4 |
| (header rows optional) |            |          |          |
+========================+============+==========+==========+
| body row 1, column 1   | column 2   | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2             | {{ large_text }}                 |
+------------------------+------------+----------+----------+
```
```{eval-rst}
.. |large| replace:: A very long long text...

+------------------------+------------+----------+----------+
| Header row, column 1   | Header 2   | Header 3 | Header 4 |
| (header rows optional) |            |          |          |
+========================+============+==========+==========+
| body row 1, column 1   | column 2   | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2             | |large|                          |
+------------------------+------------+----------+----------+
```

Proposal

I understand that this is not that simple, but that would be really great to have some kind of support for reST substitution inside {eval-rst} blocks.

Or any other way of doing text substitution.

I am aware that sphinx-substitution-extention supports rst_prolog but I cannot set these text variables inside the conf.py file. Each text is very page related and that would be very confusing to move it in the config file.

Maybe I'm missing something here ? Thank you very much :pray:

Tasks and updates

No response

senges avatar Jan 11 '23 14:01 senges

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar Jan 11 '23 14:01 welcome[bot]

Related to #637.

dbitouze avatar Jan 11 '23 19:01 dbitouze