Skip to content

Add substitution syntax(?) #172

Description

@SG-phimeca

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.

Activity

  1. choldgraf commented on Jun 23, 2020

    @choldgraf
    Member

    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?

  2. changed the title [-]Enable rst substitution[/-] [+]Add substitution syntax(?)[/+] on Jun 23, 2020
  3. chrisjsewell commented on Jun 23, 2020

    @chrisjsewell
    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)

  4. choldgraf commented on Jun 23, 2020

    @choldgraf
    Member

    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

  5. chrisjsewell commented on Jun 23, 2020

    @chrisjsewell
    Member

    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 🤔

  6. choldgraf commented on Jun 23, 2020

    @choldgraf
    Member

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

    image

  7. nickcrider commented on Sep 2, 2020

    @nickcrider

    +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.

  8. mgielda commented on Oct 20, 2020

    @mgielda

    👍

    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?

  9. mgielda commented on Oct 20, 2020

    @mgielda

    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?)

  10. AntonKrug commented on Dec 14, 2020

    @AntonKrug

    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

  11. linked a pull request that will close this issue🔀 MERGE: Improve optional syntaxes #273on Dec 17, 2020
  12. chrisjsewell commented on Dec 17, 2020

    @chrisjsewell
    Member
  13. chrisjsewell commented on Dec 17, 2020

    @chrisjsewell
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionno fixed close conditionenhancementNew feature or requestsyntaxdescisions on syntax formats

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions