jupyter-book / jupyter-book

Create beautiful, publication-quality books and documents from computational content.
http://jupyterbook.org
BSD 3-Clause "New" or "Revised" License
3.82k stars 654 forks source link

Variable substitution does not work #2067

Open ryanlovett opened 11 months ago

ryanlovett commented 11 months ago

Describe the bug

context In my _config.yml I have:

title: Stat 999
author: Fernando Perez
execute:
  execute_notebooks: force
parse:
  myst_substitutions:
    key: value
    staff_name: "Fernando Pérez"
    staff_role: Instructor
    staff_email: fernando.perez@berkeley.edu
    staff_website: https://jupyter.org
    staff_photo: "http://ds100.org/fa23/resources/assets/staff_pics/Fernando_Perez.jpeg"
    staff_pronouns: "He/Him/His"
    staff_oh: "Tue 11-12pm (Evans 419)"
    staff_team: foo

In my index.md I have:

<div class="staffer">
  <img class="staffer-image" src="{{ staff_photo }}" height=80 width=80 alt="{{ staff_name }}">
  <div>
    <h3 class="staffer-name">
      <a href="{{ staff_website }}" target="_blank">{{ staff_name }}</a>
      <p class="staffer-pronouns"><b>{{ staff_pronouns }}</b></p>
    </h3>
    <p><a href="mailto:{{ staff_email }}">{{ staff_email }}</a></p>
    <p><b>Office Hours:</b> {{ staff_oh }}</p>
  </div>
</div>

In my _toc.yml I have:

format: jb-book
root: index
chapters:
- file: syllabus
- file: calendar

I read https://jupyterbook.org/en/stable/content/content-blocks.html#define-substitutions-for-your-whole-book.

I ran jupyter-book build .

expectation I expected variables to be substituted.

bug No variables were substituted.

$ jupyter-book build mybook
Running Jupyter-Book v0.15.1
Source Folder: /Users/rylo/proj/courses/stat999-jupyter-book
Config Path: /Users/rylo/proj/courses/stat999-jupyter-book/_config.yml
Output Path: /Users/rylo/proj/courses/stat999-jupyter-book/_build/html
Running Sphinx v5.0.2
loading pickled environment... done
myst v0.18.1: MdParserConfig(commonmark_only=False, gfm_only=False, enable_extensions=['colon_fence', 'dollarmath', 'linkify', 'substitution', 'tasklist'], disable_syntax=[], all_links_external=False, url_schemes=['mailto', 'http', 'https'], ref_domains=None, highlight_code_blocks=True, number_code_blocks=[], title_to_header=False, heading_anchors=None, heading_slug_func=None, footnote_transition=True, words_per_minute=200, sub_delimiters=('{', '}'), linkify_fuzzy_links=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area')
myst-nb v0.17.2: NbParserConfig(custom_formats={}, metadata_key='mystnb', cell_metadata_key='mystnb', kernel_rgx_aliases={}, execution_mode='force', execution_cache_path='', execution_excludepatterns=[], execution_timeout=30, execution_in_temp=False, execution_allow_errors=False, execution_raise_on_error=False, execution_show_tb=False, merge_streams=False, render_plugin='default', remove_code_source=False, remove_code_outputs=False, code_prompt_show='Show code cell {type}', code_prompt_hide='Hide code cell {type}', number_source_lines=False, output_stderr='show', render_text_lexer='myst-ansi', render_error_lexer='ipythontb', render_image_options={}, render_figure_options={}, render_markdown_format='commonmark', output_folder='build', append_css=True, metadata_to_fm=False)
Using jupyter-cache at: /Users/rylo/proj/courses/stat999-jupyter-book/_build/.jupyter_cache
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] calendar
looking for now-outdated files... none found
pickling environment... done
checking consistency... /Users/rylo/proj/courses/stat999-jupyter-book/about.md: WARNING: document isn't included in any toctree
done
preparing documents... done
writing output... [100%] index
/Users/rylo/proj/courses/stat999-jupyter-book/index.md:1: WARNING: toctree contains reference to document 'calendar' that doesn't have a title: no link will be generated
/Users/rylo/proj/courses/stat999-jupyter-book/index.md:39: WARNING: 'myst' reference target not found: link
/Users/rylo/proj/courses/stat999-jupyter-book/index.md:39: WARNING: 'myst' reference target not found: link2
/Users/rylo/proj/courses/stat999-jupyter-book/index.md:1: WARNING: toctree contains reference to document 'calendar' that doesn't have a title: no link will be generated
generating indices... genindex /Users/rylo/proj/courses/stat999-jupyter-book/index.md:1: WARNING: toctree contains reference to document 'calendar' that doesn't have a title: no link will be generated
done
writing additional pages... search /Users/rylo/proj/courses/stat999-jupyter-book/index.md:1: WARNING: toctree contains reference to document 'calendar' that doesn't have a title: no link will be generated
done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 7 warnings.

The HTML pages are in _build/html.

===============================================================================

Finished generating HTML for book.
Your book's HTML pages are here:
    _build/html/
You can look at your book by opening this file in a browser:
    _build/html/index.html
Or paste this line directly into your browser bar:
    file:///Users/rylo/proj/courses/stat999-jupyter-book/_build/html/index.html

===============================================================================

problem This is a problem for people who want to substitute variables.

Reproduce the bug

  1. Specify parse.myst_substitutions in _config.yml.
  2. Add jinja substitution templates to markdown.
  3. Build the book.
  4. Examine output.

List your environment

Jupyter Book      : 0.15.1
External ToC      : 0.3.1
MyST-Parser       : 0.18.1
MyST-NB           : 0.17.2
Sphinx Book Theme : 1.0.1
Jupyter-Cache     : 0.6.1
NbClient          : 0.7.2
ryanlovett commented 11 months ago

I tried adding parse.myst_enable_extensions.substitution to _config.yml without success.

ryanlovett commented 11 months ago

I was exploring jupyter-book for a course website project, but I've since pivoted to exploring myst. (which ironically does not support variable substitution yet) So I'll keep this open in case it is impacting others, but it isn't a high priority issue for me.