-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors when translating rst substitutions
to MyST-flavoured markdown
#33
Comments
Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗 |
Heya, yeh I have to admit, I hadn't noticed the "links with substitutions" syntax before, and never used it in my own work. Your proposed solutions both seem viable, thanks. I can't say I have time right now to do this myself 😬 but would certainly welcome any PRs Also interested to have a look at pyscaffold! |
Thank you very much @chrisjsewell. I am more or less in the same boat here in terms of time for contributing 😝, but in the future if I manage to get my hands on I have been using PyScaffold for years in a row now and I am really satisfied on how it helps me to creates Python packages (so much that I became one of the maintainers). Lately I have been trying to integrate Let me know if you want to some information about PyScaffold, I am more than happy to chat about it 😄 |
Due to an [issue] the output generated by rst-to-myst does not work 100%. Therefore a fixed template seems to be a temporary solution. [issue]: executablebooks/rst-to-myst#33
Due to an [issue] the output generated by rst-to-myst does not work 100%. Therefore a fixed template seems to be a temporary solution. [issue]: executablebooks/rst-to-myst#33
Describe the problem
The way
rst2myst
translates rst substitutions to Markdown does not seem to work properly.So far 2 inconsistencies have been identified:
rst2myst
relies on MyST ability to use Jinja2 for substitutions. However Jinja2 requires a valid identifier (i.e., valid Python variable names), which is a much more restrictive condition, and therefore not compatible withrst
(e.g.rst
accepts strings with spaces)rst2myst
fails on translating links with substitutions (e.g.|ref|_
), which are a very common use case when writingrst
(e.g. for creating links with bold, italic or monospaced text elements)This issue was first identified in pyscaffold/pyscaffoldext-markdown#25. A simplified description of the problem and steps to reproduce it can be found in this gist.
Link to your repository or website
https://gist.github.com/abravalheri/a9cdfa09f2809182fccca659b413da4a
Steps to reproduce
The following is a simplified example to reproduce the problem:
rst2myst stream original.rst > converted.md
), I obtain the following MyST-flavoured markdown:As we can see, converted markdown contains invalid Jinja2 syntax, e.g.
{{ the repository service }}
, and the original link with substitution was converted to a simple link, without a substitution.The version of Python you're using
3.8.0
Your operating system
Ubuntu 18.04.5 LTS
Versions of your packages
Direct installation:
The remaining packages where installed as dependencies of those 3 in an empty virtual environment created with:
Expected output
Two different behaviours could be expected from
rst2myst
:This include replacing or removing invalid characters, e.g.
|the repository service|
could be translated to{{ the_repository_service }}
.This approach in shown in
expected_option1
bellow.__
),e.g.
|the repository service|
could be translated to{{ __["the repository service"] }}
.This approach in shown in
expected_option2
bellowRegarding links with substitutions, CommonMark's full reference links in combination with Jinja2 seem to be a good alternative, e.g.
|ref|_
could be translated to[{{ ref }}][ref]
. This approach is shown in bothexpected_option1
andexpected_option2
.expected_option1
expected_option2
In
expected_option2
, instead of using a nested dict__
inside ofsubstitutions
, thesubstititions
dict itself could also be directly assigned to__
in the Jinja2 template context, this would allow users using any substitution key directly if they are valid identifiers and invalid identifiers via the__
helper.(code blocks around
git push ...
inexpected_option1|2
omitted due to GitHub's inability of dealing with nested code blocks)The text was updated successfully, but these errors were encountered: