Skip to content
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

Add substitution syntax(?) #172

Closed
SG-phimeca opened this issue Jun 23, 2020 · 11 comments · Fixed by #273
Closed

Add substitution syntax(?) #172

SG-phimeca opened this issue Jun 23, 2020 · 11 comments · Fixed by #273
Labels
discussion no fixed close condition enhancement New feature or request syntax descisions on syntax formats

Comments

@SG-phimeca
Copy link

Adding the following into conf.py

rst_prolog = """
.. |xyzzy| replace:: Nothing happens.
"""

allows to replace |xyzzy| by Nothing happens. in all ReST source files but not in Markdown files.
This would be a very useful feature, for instance for inline images, or simply to have a system for macros.

@SG-phimeca SG-phimeca added the enhancement New feature or request label Jun 23, 2020
@choldgraf
Copy link
Member

choldgraf commented Jun 23, 2020

Here's the relevant bit from the rST docs:

https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#substitution-definitions

Also - just to clarify, the configuration with conf.py is not integral to this issue, right?

@chrisjsewell chrisjsewell added discussion no fixed close condition syntax descisions on syntax formats labels Jun 23, 2020
@chrisjsewell chrisjsewell changed the title Enable rst substitution Add substitution syntax(?) Jun 23, 2020
@chrisjsewell
Copy link
Member

Thanks @SG-phimeca, yes this syntax is not (currently) implemented in MyST (or in markdown).

It is a syntax that has come up before in discussion here: #31 (comment)

@choldgraf
Copy link
Member

choldgraf commented Jun 23, 2020

I wonder if we could piggy-back on LinkDefinition for this?

E.g. support something like:

[key]: Any arbitrary text 

and then allow for [key][] in the text, and if that exists then assume the content should be replaced? As opposed to [text][key] which is the normal linkdefinition syntax

@chrisjsewell
Copy link
Member

chrisjsewell commented Jun 23, 2020

I wonder if we could piggy-back on LinkDefinition for this?

I'm very sceptical that this could be done in a way that didn't break commonmark compatibility 🤔

@choldgraf
Copy link
Member

yeah I was worried about that too...looks like commonmark does already render the syntax I showed:

image

@nickcrider
Copy link

+1 for the standard rst_prolog substitution syntax.

Our particular use-case involves the rST substitution syntax in code-blocks to keep example code up-to-date. Unfortunately not having this syntax is blocking me from switching our documentation over to MyST.

However, playing around with it, I found if you do:

```{eval-rst}

.. |sub| replace:: subbed

Test sub: |sub|
```

Sphinx throws a WARNING: Undefined substitution referenced: "sub" so at least it seems like the plumbing is partially there.

@mgielda
Copy link

mgielda commented Oct 20, 2020

👍

I have worked around the problem using sphinx-jinja, but of course it's not ideal, since sphinx-jinja lacks an inline syntax for simple one-word substitutions.

So definitely looking forward to some implementation of substitutions. Why not use {sub}something-something by the way and just detect this special role and emit a substitution instead?

@mgielda
Copy link

mgielda commented Oct 20, 2020

of course we'd also need a special sub directive to define the substitution, but I assume that would be doable, unless of course my rst fu is failing me and you cannot have a role and directive with the same name. (then we'd use another name?)

@AntonKrug
Copy link

AntonKrug commented Dec 14, 2020

Hi @mgielda what a surprise to find you here :)

https://jinja.palletsprojects.com/en/2.11.x/templates/#variables

You can wrap your whole document into the jinja directive with 'foo' argument and then in the body just use {{bar}}
I would include snippet here, but even the escaped Myst syntax is breaking this markdown.

Which then almost looks like inline one-word substitution

@chrisjsewell chrisjsewell linked a pull request Dec 17, 2020 that will close this issue
@chrisjsewell
Copy link
Member

@chrisjsewell
Copy link
Member

chrisjsewell commented Dec 17, 2020

Note substitutions and prologs are not strictly related, this issue is concerned with substitutions and #270 is specifically for prologs/epilogs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion no fixed close condition enhancement New feature or request syntax descisions on syntax formats
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants