fix: escape bare < in generated MDX to fix Vercel doc builds#1478
fix: escape bare < in generated MDX to fix Vercel doc builds#1478
Conversation
The uv.lock regeneration in #1425 bumped griffe2md from 1.3.4 to 1.5.0, which renders docstring content slightly differently. A `<=` operator at the start of a line in the FullyAsyncConfig docstring was left unescaped in the MDX output, causing the Next.js MDX parser to interpret `<` as the start of a JSX tag and fail with: Unexpected character `=` (U+003D) before name Add a second regex pass in `sanitize_for_mdx()` that escapes any `<` not followed by a valid tag-start character (letter, `/`, `!`), converting patterns like `<=` to `<=`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates the docs/generate-api-docs.py script to escape bare < characters in docstrings, preventing MDX parsing errors for sequences like <= or <2. Feedback was provided to compile the regular expression outside the loop to improve performance and readability.
| part = re.sub( | ||
| r"<(?![a-zA-Z/!])", | ||
| r"<", | ||
| part, | ||
| ) |
There was a problem hiding this comment.
For improved performance and readability, it's a best practice to compile regular expressions that are used inside a loop. This regex is recompiled on every iteration within the loop over parts of a line.
You could define the compiled regex object once, before the for line in lines: loop, and reuse it. For example:
# Before the loop
_bare_lt_re = re.compile(r"<(?![a-zA-Z/!])")
# Inside the loop
...
part = _bare_lt_re.sub(r"<", part)This advice also applies to the other regular expression substitution for invalid tags just above this change.
Summary
uv.lockregeneration in [megatron] support qwen3.5 models for megatron, bump mbridge + megatron-core to latest #1425 bumpedgriffe2mdfrom 1.3.4 to 1.5.0, which renders docstring content slightly differently<=operator at the start of a line in theFullyAsyncConfigdocstring (skyrl/train/config/config.py:394) was left unescaped in the MDX output, causing the Next.js MDX parser to fail with:Unexpected character '=' (U+003D) before namesanitize_for_mdx()that escapes any bare<not followed by a valid HTML tag-start character (letter,/,!)