question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using myst_parser's new "substitutions" feature

See original GitHub issue

Describe the bug

I’m trying to get the new “substitution” directive from myst_parser v0.13 and running into some trouble translating the “conf.py” file to jupyterbook’s “_config.yml”.

Problem 1: dependency issues

Trying to upgrade myst_parser to v0.13 caused some issues with dependencies for myst-nb

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
myst-nb 0.10.1 requires myst-parser~=0.12.9, but you have myst-parser 0.13.0 which is incompatible.
jupytext 1.6.0 requires markdown-it-py~=0.5.2; python_version >= "3.6", but you have markdown-it-py 0.6.0 which is incompatible.

I think this was just a warning, and I ended up upgrading myst_parser anyway.

Problem 2: myst_enable_extensions

The Myst docs say:

To enable all the syntaxes explained below:

myst_enable_extensions = [
    "amsmath",
    "colon_fence",
    "deflist",
    "dollarmath",
    "html_image",
    "linkify",
    "replacements",
    "smartquotes",
    "substitution"
]

What is the way to enable these in jupyterbook? Here is my attempt in _config.yml:

# bunch of stuff that's not relevant here

sphinx:
  config:
    html_show_copyright: false
    html_extra_path: ['files']

parse:
  myst_extended_syntax: true

myst_enable_extensions: 
  - amsmath
  - colon_fence
  - deflist
  - dollarmath
  - html_image
  - linkify
  - replacements
  - smartquotes
  - substitution

myst_substitutions:
  course: 'THISISAMAZING1010'

Problem 3: Using substitutions

I imagine that with the _config.yml file above, this should work in any md file:

This is the official syllabus and course outline for COSC 123 {{ course }}.

… but {{ course }} doesn’t replace the text as I expected.

I also tried to add the substitution definition at the top of the file as “front-matter” using three dashes, but that doesn’t work either (no error, just leaves it as {{ varname }}.

E.g.,

---
substitutions:
  course2: "I'm a substitution"
---

To Reproduce

See above.

Expected behavior

{{ course }} should be replaced with “THISISAMAZING1010”

Environment

  • Python Version [e.g. 3.7.1]: 3.8.3
  • Package versions or output of jupyter-book --version:
Jupyter Book: 0.9.1
MyST-NB: 0.10.1
Sphinx Book Theme: 0.0.39
MyST-Parser: 0.13.0
Jupyter-Cache: 0.4.1
NbClient: 0.4.1
  • Operating System: macOS 11.1

Additional context

RE: Problem 2, I see the same warnings as seen in issue #1152

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:31 (26 by maintainers)

github_iconTop GitHub Comments

2reactions
chrisjsewellcommented, Jan 5, 2021

You can already pass in directives, the text is parsed before it is substituted in

1reaction
chrisjsewellcommented, Jan 9, 2021

you should actually just be able to replace {{FORUM_LINK | replace('JOIN_LINK', ED_ID)}} with {{FORUM_LINK.replace('JOIN_LINK', ED_ID)}}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Syntax Extensions - MyST-Parser
Adding "replacements" to myst_enable_extensions (in the sphinx conf.py configuration file) will automatically convert some common typographic texts ...
Read more >
SUBSTITUTE function - Microsoft Support
Use SUBSTITUTE when you want to replace specific text in a text string; use REPLACE when you want to replace any text that...
Read more >
Symbolic substitution - MATLAB subs - MathWorks
This MATLAB function returns a copy of s, replacing all occurrences of old with new, and then evaluates s.
Read more >
Substitutions for Store Pickup and Delivery Items - Walmart.com
If the item is out of stock and you selected a substitution, we'll substitute the item with the one you chose. If the...
Read more >
How You Use the End Item Substitution Feature
This topic provides the high-level process you must follow to use the end item substitution feature. Set up your item relationships and substitution...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found