Repository navigation
Description
Summary
The validation documentation code blocks (e.g., $ dandi validate ... examples) currently (PR yet to be sent for extended docs on validate, TODO) show plain uncolored text. dandi validate uses Click's secho to color output by severity (red=ERROR, yellow=WARNING, blue=HINT), but the generation script strips ANSI codes since standard markdown code blocks can't render them.
Proposed Solution
Use pygments-ansi-color — a Pygments lexer plugin that parses ANSI escape sequences and renders them as colored HTML. It registers an ansi-color language identifier that works with pymdownx.highlight.
Implementation Steps
-
Add dependency:
pygments-ansi-colortorequirements.txt(requires Python >= 3.10) -
Add CSS: Either:
- Use
markdown-exec[ansi]which bundlespygments-ansi-color+ ready-made CSS with light/dark theme support - Or manually add an
ansi.cssfile (e.g., from markdown-exec's assets) todocs/css/and reference it inextra_css
- Use
-
Update generation script (
scripts/generate-validation-examples.sh):- Force color output: set
FORCE_COLOR=1or equivalent env var for dandi-cli/Click - Do not strip ANSI codes from the output files that will use
ansi-colorblocks - Keep sanitizing absolute paths
- Force color output: set
-
Update code blocks in
docs/user-guide-sharing/validating-files.md:- Change
```consoleto```ansi-colorfor blocks that showdandi validateoutput - The ANSI escape sequences in the example files will be rendered as colored HTML
- Change
Example
A code block like:
```ansi-color
[31m[ERROR][0m [pynwb.GENERIC] sub-RAT123/sub-RAT123.nwb — nwb_version '2.0b' is not a proper semantic version.
[33m[WARNING][0m [NWBI.check_subject_age] sub-RAT123/sub-RAT123.nwb — Subject age, '12 mo', does not follow ISO 8601...
[34m[HINT][0m [BIDS.README_FILE_MISSING] dataset_description.json — The recommended file /README is missing.
```Would render with red/yellow/blue colors matching what users see in their terminal.
Caveats
- The example files must contain literal ANSI escape bytes, not the text representation
\033[31m pygments-ansi-colorsupports standard 8 colors + bright variants + bold — sufficient for Click'ssechooutput- Need to verify colors render well against both mkdocs-material default and slate (dark) themes
- Also consider
click-extrawhich extendspygments-ansi-colorwith ANSI-aware shell session lexers (could allow```consoleblocks with colored output)
Related
- https://github.com/chriskuehl/pygments-ansi-color
- https://github.com/pawamoy/markdown-exec (bundles ansi support)
- https://kdeldycke.github.io/click-extra/pygments.html (ANSI-aware console lexer)
Activity