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

Expose myst_substitions to RST

Open chancez opened this issue 1 year ago • 2 comments

While this doesn't fix the fact that .. replace:: does not work within eval-rst, it does make it possible to perform substitutions within eval-rst using the same substitutions available to Jinja substitutions.

Related: #680

Honestly I have very little experience with docutils, or even MyST but I basically figured out substitutions need to be registered by calling self.document.note_substitution_def from reading where the Undefined substitution referenced: error message comes from and determining that it reads from two dictionaries that the document.note_substitution_def updates. I then kind of got lucky and found that MyST already called the necessary function for the wordcount extension, which gave me a basic example of what I needed to do. I literally just copy and pasted the code used for the word count extension but using the values from self.md_config.substitutions which is where myst_substitutions values are stored, and it "just worked".

Let me know what you think, like I said, it was really just a stab at trying to make something substitution related work for eval-rst. I'd still love to get .. replace:: working but this will solve my needs pretty well I think.

chancez avatar Aug 22 '24 18:08 chancez

Codecov Report

Attention: Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.29%. Comparing base (1038800) to head (30e52eb).

Files Patch % Lines
myst_parser/mdit_to_docutils/base.py 85.71% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #966      +/-   ##
==========================================
- Coverage   90.30%   90.29%   -0.01%     
==========================================
  Files          24       24              
  Lines        3507     3514       +7     
==========================================
+ Hits         3167     3173       +6     
- Misses        340      341       +1     
Flag Coverage Δ
pytests 90.29% <85.71%> (-0.01%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 22 '24 18:08 codecov[bot]

Do what I expected it would do.

In my case, I have lots of "reusable" documents where I use 'substitutions' to eventually generate the right output when product names etc... get eventually defined. However I also intensively use "conditional compiling" (in RST) to get parts of docs included/excluded from the final output. I love using Myst-Parser but the lack of substitutions within RST refrained me to fully transition them to MD.

Thanks a lot for the time spend and the solution.

MacqGit avatar Dec 17 '24 09:12 MacqGit