rust-lang / rust-lang/mdBook

How does `MDBOOK_XXX` env deal with configuration strings with an undersore (`_`)?

Open
#2,739 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-question
Dominant language
Rust
Stars
22.2k
Forks
1.9k
Avg merge
2d 21h
Merged PRs (30d)
12

Description

Question

Recently, I tried to build Zed docs without using its custom preprocessor, [preprocessor.zed_docs_preprocessor].

Originally, I thought I could use MDBOOK_XXX env to disable it by assigning it with an empty object, {}, like this:

MDBOOK_PREPROCCESSOR__ZED_DOCS_PREPROCESSOR={} mdbook build docs

However, it failed because mdbook will recognize:

MDBOOK_PREPROCCESSOR__ZED_DOCS_PREPROCESSOR -> [preprocessor.zed-docs-preprocessor]

Based on the Environment Variables section:

Variables starting with MDBOOK_ are used for configuration. The key is created by removing the MDBOOK_ prefix and turning the resulting string into kebab-case. Double underscores (__) separate nested keys, while a single underscore (_) is replaced with a dash (-).

For example:

  • MDBOOK_foo -> foo
  • MDBOOK_FOO -> foo
  • MDBOOK_FOO__BAR -> foo.bar
  • MDBOOK_FOO_BAR -> foo-bar
  • MDBOOK_FOO_bar__baz -> foo-bar.baz

It seems that mdbook's MDBOOK_XXX env can deal with configuration strings with a dash (-) and a dot (.), but it cannot deal with an underscore (_).

My questions are:

  1. If so, does it mean that it's not recommended to use _ in configuration strings?
  2. If not, then how does MDBOOK_XXX env deal with configuration strings with _?
Version
mdbook v0.4.40

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Environment Variables section linked in the issue and reproduce the command using MDBOOK_PREPROCCESSOR__ZED_DOCS_PREPROCESSOR with an empty object against mdBook v0.4.40. Trace how nested environment keys are converted to configuration keys, then document or correct the handling of underscores so the behavior and supported configuration names are clear.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.