Repository navigation
Fix GitHub GFM inline math rendering across READMEs & docs and harden CI guard - #30
Conversation
…& docs and harden CI guard
Reviewer's GuideDocumentationUpdate the root README’s inline-math delimiters, escaping, and notation to render reliably in GitHub GFM.
Revise the Beer–Lambert reference protocol’s equations and units to avoid GFM inline-math parsing and escaping pitfalls.
Reformat inline mathematics throughout the physics-corrections scope document to prevent delimiter, emphasis, and escape conflicts.
Correct inline math in the retired-models, contracts, and research-example READMEs so the examples and references render consistently on GitHub.
TestsExtend the Markdown CI contract to check GFM inline-math delimiter and escaping rules across the expanded set of tracked documentation files.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e4e783811
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| violations.append( | ||
| f"{rel}:{lineno}: unescaped '|' inside table math {span.group(0)!r}" | ||
| ) | ||
| if "$$" in line: |
There was a problem hiding this comment.
Ignore inline code before classifying
$$ fences
When a Markdown paragraph documents the literal $$ token inside inline code, this check still sees it and reports a fence violation, even though it is valid code-span content rather than a display-math delimiter. Scrub inline code before classifying $$ so the new CI guard accepts valid documentation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Hey - I've found 8 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/ci/test_markdown_contracts.py" line_range="30" />
<code_context>
MACRO_PATTERN = re.compile(
r"\\(?:" + "|".join(DISALLOWED_MATHJAX_MACROS) + r")\b"
)
+INLINE_CODE_PATTERN = re.compile(r"(`+)([^`]*?)\1")
MD_LINK_PATTERN = re.compile(r"!?\[[^\]]*\]\(([^)]+)\)")
IMG_SRC_PATTERN = re.compile(r'<img\s+[^>]*src="([^"]+)"')
</code_context>
<issue_to_address>
**Code spans trigger false math and link errors**
When a Markdown code span contains backticks or crosses a line and includes dollar- or link-like text, `INLINE_CODE_PATTERN` does not recognize the span, so `_check_inline_gfm_math_line` or the link check scans its literal content and fails CI for valid Markdown.
Use CommonMark-aware code-span masking across lines before the math and link checks.
Also at `tests/ci/test_markdown_contracts.py:73`, `tests/ci/test_markdown_contracts.py:166`.
</issue_to_address>
### Comment 2
<location path="tests/ci/test_markdown_contracts.py" line_range="78" />
<code_context>
+ return errors
+
+ dollar_positions = [
+ m.start() for m in re.finditer(r"(?<!\\)\$", scrubbed)
+ ]
+ if len(dollar_positions) % 2 != 0:
</code_context>
<issue_to_address>
**Backslash runs misclassify math delimiters**
When a dollar, percent, comma, or table pipe follows an even-length run of backslashes, the one-character lookbehind treats the character as escaped, so the math scan misses or mispairs active delimiters and the table check accepts an unescaped separator; valid TeX is also reported as invalid.
Determine whether each character is escaped by counting its immediately preceding backslash run, and use that rule in the math and table checks.
Also at `tests/ci/test_markdown_contracts.py:79`, `tests/ci/test_markdown_contracts.py:107`, `tests/ci/test_markdown_contracts.py:122`.
</issue_to_address>
### Comment 3
<location path="tests/ci/test_markdown_contracts.py" line_range="145-152" />
<code_context>
- violations.append(
- f"{rel}:{lineno}: unescaped '|' inside table math {span.group(0)!r}"
- )
+ if "$$" in line:
+ if line != "$$":
+ violations.append(
+ f"{rel}:{lineno}: '$$' fence must stand alone at column 0"
+ )
+ else:
+ in_display_math = not in_display_math
+ continue
+ if not in_display_math:
+ violations.extend(_check_inline_gfm_math_line(rel, lineno, line))
</code_context>
<issue_to_address>
**Code examples trigger display-fence errors**
When a Markdown line contains `$$` inside inline code, the display-fence check examines the raw line, so it treats literal code as a math fence and fails CI for valid documentation.
Exclude inline code before checking lines for display-math fences.
Also at `tests/ci/test_markdown_contracts.py:30`.
</issue_to_address>
### Comment 4
<location path="tests/ci/test_markdown_contracts.py" line_range="73" />
<code_context>
+def _check_inline_gfm_math_line(rel: str, lineno: int, line: str) -> list[str]:
+ """Validate cmark-gfm inline $...$ delimiter and backslash-escape invariants."""
+ errors: list[str] = []
+ scrubbed = INLINE_CODE_PATTERN.sub("CODE", line)
+ if "$" not in scrubbed:
+ return errors
</code_context>
<issue_to_address>
**Code spans create false Markdown syntax**
When inline code is adjacent to a math delimiter or separates `]` from `(`, the code-span scrubber substitutes `CODE` or deletes the span, changing the surrounding characters; the math or link check then rejects valid Markdown.
Mask code-span contents while preserving the original boundary characters.
Also at `tests/ci/test_markdown_contracts.py:166-169`.
</issue_to_address>
### Comment 5
<location path="tests/ci/test_markdown_contracts.py" line_range="24-25" />
<code_context>
"si",
"pu",
"ce",
+ "colorbox",
+ "fcolorbox",
)
MACRO_PATTERN = re.compile(
</code_context>
<issue_to_address>
**Inline examples trip macro guard**
When a tracked Markdown file uses one of the newly disallowed commands in an inline code example, the macro scan searches each raw Markdown line, including inline code spans, so a valid code example that documents `\colorbox` or `\fcolorbox` is reported as a disallowed MathJax macro and fails CI.
Scrub inline code spans before searching for disallowed macros, while continuing to check actual math content.
</issue_to_address>
### Comment 6
<location path="tests/ci/test_markdown_contracts.py" line_range="154" />
<code_context>
+ in_display_math = not in_display_math
+ continue
+ if not in_display_math:
+ violations.extend(_check_inline_gfm_math_line(rel, lineno, line))
+ if in_display_math:
+ violations.append(f"{rel}: unclosed '$$' display math block")
</code_context>
<issue_to_address>
**Indented code is checked as math**
When a Markdown document uses an indented code block containing a dollar sign, `_iter_non_code_lines` excludes fenced code but not Markdown's indented code blocks, so this call sends their contents to the inline-math validator. A literal dollar in an indented example, such as a shell prompt, is reported as unbalanced math and fails CI.
Exclude indented code blocks from math validation, including their list-container equivalents.
</issue_to_address>
### Comment 7
<location path="tests/ci/test_markdown_contracts.py" line_range="153" />
<code_context>
+ else:
+ in_display_math = not in_display_math
+ continue
+ if not in_display_math:
+ violations.extend(_check_inline_gfm_math_line(rel, lineno, line))
+ if in_display_math:
</code_context>
<issue_to_address>
**Display math bypasses checks**
When a display-math body contains a non-ASCII token or a backslash-escaped `%` or `,` that GFM strips, the loop skips `_check_inline_gfm_math_line` throughout display blocks, so Unicode and backslash-escape errors in a block pass CI and render incorrectly on GitHub.
Validate display-math bodies with the applicable GFM checks while excluding their `$$` delimiters.
</issue_to_address>
### Comment 8
<location path="tests/ci/test_markdown_contracts.py" line_range="122" />
<code_context>
+ )
+ if re.search(r"\}_(?=[{\\])", span):
+ brace_underscore_spans += 1
+ if line.lstrip().startswith("|") and re.search(r"(?<!\\)\|", span):
+ errors.append(
+ f"{rel}:{lineno}: unescaped '|' inside table math ${span}$"
</code_context>
<issue_to_address>
**Some table math escapes checks**
When a GFM table row omits its optional leading pipe and contains an unescaped `|` inside inline math, the pipe check runs only when a row starts with `|`, so an unescaped pipe in math in a valid table row without an optional leading pipe passes CI and breaks the table rendering.
Check math pipes in table rows regardless of whether the row has a leading pipe.
</issue_to_address>| MACRO_PATTERN = re.compile( | ||
| r"\\(?:" + "|".join(DISALLOWED_MATHJAX_MACROS) + r")\b" | ||
| ) | ||
| INLINE_CODE_PATTERN = re.compile(r"(`+)([^`]*?)\1") |
There was a problem hiding this comment.
🟡 Medium · Code spans trigger false math and link errors
When a Markdown code span contains backticks or crosses a line and includes dollar- or link-like text, INLINE_CODE_PATTERN does not recognize the span, so _check_inline_gfm_math_line or the link check scans its literal content and fails CI for valid Markdown.
Use CommonMark-aware code-span masking across lines before the math and link checks.
Also at tests/ci/test_markdown_contracts.py:73, tests/ci/test_markdown_contracts.py:166.
Prompt for AI agents
In `tests/ci/test_markdown_contracts.py` at line 30:
**Code spans trigger false math and link errors**
When a Markdown code span contains backticks or crosses a line and includes dollar- or link-like text, `INLINE_CODE_PATTERN` does not recognize the span, so `_check_inline_gfm_math_line` or the link check scans its literal content and fails CI for valid Markdown.
Use CommonMark-aware code-span masking across lines before the math and link checks.
Also at `tests/ci/test_markdown_contracts.py:73`, `tests/ci/test_markdown_contracts.py:166`.| return errors | ||
|
|
||
| dollar_positions = [ | ||
| m.start() for m in re.finditer(r"(?<!\\)\$", scrubbed) |
There was a problem hiding this comment.
🟡 Medium · Backslash runs misclassify math delimiters
When a dollar, percent, comma, or table pipe follows an even-length run of backslashes, the one-character lookbehind treats the character as escaped, so the math scan misses or mispairs active delimiters and the table check accepts an unescaped separator; valid TeX is also reported as invalid.
Determine whether each character is escaped by counting its immediately preceding backslash run, and use that rule in the math and table checks.
Also at tests/ci/test_markdown_contracts.py:79, tests/ci/test_markdown_contracts.py:107, tests/ci/test_markdown_contracts.py:122.
Prompt for AI agents
In `tests/ci/test_markdown_contracts.py` at line 78:
**Backslash runs misclassify math delimiters**
When a dollar, percent, comma, or table pipe follows an even-length run of backslashes, the one-character lookbehind treats the character as escaped, so the math scan misses or mispairs active delimiters and the table check accepts an unescaped separator; valid TeX is also reported as invalid.
Determine whether each character is escaped by counting its immediately preceding backslash run, and use that rule in the math and table checks.
Also at `tests/ci/test_markdown_contracts.py:79`, `tests/ci/test_markdown_contracts.py:107`, `tests/ci/test_markdown_contracts.py:122`.| if "$$" in line: | ||
| if line != "$$": | ||
| violations.append( | ||
| f"{rel}:{lineno}: '$$' fence must stand alone at column 0" | ||
| ) | ||
| else: | ||
| in_display_math = not in_display_math | ||
| continue |
There was a problem hiding this comment.
🟡 Medium · Code examples trigger display-fence errors
When a Markdown line contains $$ inside inline code, the display-fence check examines the raw line, so it treats literal code as a math fence and fails CI for valid documentation.
Exclude inline code before checking lines for display-math fences.
Also at tests/ci/test_markdown_contracts.py:30.
Prompt for AI agents
In `tests/ci/test_markdown_contracts.py` at lines 145-152:
**Code examples trigger display-fence errors**
When a Markdown line contains `$$` inside inline code, the display-fence check examines the raw line, so it treats literal code as a math fence and fails CI for valid documentation.
Exclude inline code before checking lines for display-math fences.
Also at `tests/ci/test_markdown_contracts.py:30`.| def _check_inline_gfm_math_line(rel: str, lineno: int, line: str) -> list[str]: | ||
| """Validate cmark-gfm inline $...$ delimiter and backslash-escape invariants.""" | ||
| errors: list[str] = [] | ||
| scrubbed = INLINE_CODE_PATTERN.sub("CODE", line) |
There was a problem hiding this comment.
🟡 Medium · Code spans create false Markdown syntax
When inline code is adjacent to a math delimiter or separates ] from (, the code-span scrubber substitutes CODE or deletes the span, changing the surrounding characters; the math or link check then rejects valid Markdown.
Mask code-span contents while preserving the original boundary characters.
Also at tests/ci/test_markdown_contracts.py:166-169.
Prompt for AI agents
In `tests/ci/test_markdown_contracts.py` at line 73:
**Code spans create false Markdown syntax**
When inline code is adjacent to a math delimiter or separates `]` from `(`, the code-span scrubber substitutes `CODE` or deletes the span, changing the surrounding characters; the math or link check then rejects valid Markdown.
Mask code-span contents while preserving the original boundary characters.
Also at `tests/ci/test_markdown_contracts.py:166-169`.| "colorbox", | ||
| "fcolorbox", |
There was a problem hiding this comment.
🟡 Medium · Inline examples trip macro guard
When a tracked Markdown file uses one of the newly disallowed commands in an inline code example, the macro scan searches each raw Markdown line, including inline code spans, so a valid code example that documents \colorbox or \fcolorbox is reported as a disallowed MathJax macro and fails CI.
Scrub inline code spans before searching for disallowed macros, while continuing to check actual math content.
Prompt for AI agents
In `tests/ci/test_markdown_contracts.py` at lines 24-25:
**Inline examples trip macro guard**
When a tracked Markdown file uses one of the newly disallowed commands in an inline code example, the macro scan searches each raw Markdown line, including inline code spans, so a valid code example that documents `\colorbox` or `\fcolorbox` is reported as a disallowed MathJax macro and fails CI.
Scrub inline code spans before searching for disallowed macros, while continuing to check actual math content.| in_display_math = not in_display_math | ||
| continue | ||
| if not in_display_math: | ||
| violations.extend(_check_inline_gfm_math_line(rel, lineno, line)) |
There was a problem hiding this comment.
🟡 Medium · Indented code is checked as math
When a Markdown document uses an indented code block containing a dollar sign, _iter_non_code_lines excludes fenced code but not Markdown's indented code blocks, so this call sends their contents to the inline-math validator. A literal dollar in an indented example, such as a shell prompt, is reported as unbalanced math and fails CI.
Exclude indented code blocks from math validation, including their list-container equivalents.
Prompt for AI agents
In `tests/ci/test_markdown_contracts.py` at line 154:
**Indented code is checked as math**
When a Markdown document uses an indented code block containing a dollar sign, `_iter_non_code_lines` excludes fenced code but not Markdown's indented code blocks, so this call sends their contents to the inline-math validator. A literal dollar in an indented example, such as a shell prompt, is reported as unbalanced math and fails CI.
Exclude indented code blocks from math validation, including their list-container equivalents.
| else: | ||
| in_display_math = not in_display_math | ||
| continue | ||
| if not in_display_math: |
There was a problem hiding this comment.
🟡 Medium · Display math bypasses checks
When a display-math body contains a non-ASCII token or a backslash-escaped % or , that GFM strips, the loop skips _check_inline_gfm_math_line throughout display blocks, so Unicode and backslash-escape errors in a block pass CI and render incorrectly on GitHub.
Validate display-math bodies with the applicable GFM checks while excluding their $$ delimiters.
Prompt for AI agents
In `tests/ci/test_markdown_contracts.py` at line 153:
**Display math bypasses checks**
When a display-math body contains a non-ASCII token or a backslash-escaped `%` or `,` that GFM strips, the loop skips `_check_inline_gfm_math_line` throughout display blocks, so Unicode and backslash-escape errors in a block pass CI and render incorrectly on GitHub.
Validate display-math bodies with the applicable GFM checks while excluding their `$$` delimiters.| ) | ||
| if re.search(r"\}_(?=[{\\])", span): | ||
| brace_underscore_spans += 1 | ||
| if line.lstrip().startswith("|") and re.search(r"(?<!\\)\|", span): |
There was a problem hiding this comment.
🟡 Medium · Some table math escapes checks
When a GFM table row omits its optional leading pipe and contains an unescaped | inside inline math, the pipe check runs only when a row starts with |, so an unescaped pipe in math in a valid table row without an optional leading pipe passes CI and breaks the table rendering.
Check math pipes in table rows regardless of whether the row has a leading pipe.
Prompt for AI agents
In `tests/ci/test_markdown_contracts.py` at line 122:
**Some table math escapes checks**
When a GFM table row omits its optional leading pipe and contains an unescaped `|` inside inline math, the pipe check runs only when a row starts with `|`, so an unescaped pipe in math in a valid table row without an optional leading pipe passes CI and breaks the table rendering.
Check math pipes in table rows regardless of whether the row has a leading pipe.
Summary
Resolves all remaining GitHub
cmark-gfm+ MathJax v3 inline/block math parsing issues across all 45 tracked Markdown files (verified412 / 412<math-renderer>blocks with0issues via GitHub's live/markdownAPI) and upgradestests/ci/test_markdown_contracts.pyto prevent regressions (src/production code untouched).Root Causes Fixed
-/[before opening$(Suns-$V_{\mathrm{oc}}$,pseudo-$J\text{–}V$,pseudo-$\mathrm{FF}$,[$\text{m}^{-1}$],negative-$p$) — converted to clean math-contained forms ($\text{Suns-}V_{\mathrm{oc}}$,$\text{pseudo-}J\text{-}V$,$\text{pseudo-FF}$, parenthesized units).)$)boundary breaks (2D ($(y, x)$),($...)$)) — simplified to avoid adjacent)$).*...*/}_..._emphasis collisions across$...$($\tilde{A}^* = \min(A^*_L, A^*_R)$,($\mathbf{F}_\alpha \cdot \mathbf{n} = 0$)+$\theta = (P_+ + P_-)/P_{\mathrm{lim}}$) — rewritten using\ast,($F_{\alpha,n} = 0$), and$\theta = (P^{+} + P^{-})/P_{\mathrm{lim}}$.$...$(0.031\%/0.009\%turned into unescaped TeX%comments;G\,\mathrm{d}xturned into literal commas,) — moved literal percentages outside$(0.031%,0.009%) and standardized thin spaces to\.\text{–}inside MathJax & nested-list indented$$blocks — normalized to pure ASCII\text{-}and top-level/inline equations; hardenedtests/ci/test_markdown_contracts.pyto guard all rules above.Verification
/markdownGFM render audit across all 45.mdfiles (412<math-renderer>blocks, 86 / 86 in rootREADME.md):0unparsed$,0HTML tag collisions,0%comment truncations,0non-ASCII math tokens.Refactor checksondevel(2e4e783): 9 / 9 jobs passed (https://github.com/ShaneLogic/SolarLab/actions/runs/45156129751).Summary by Sourcery
Make project documentation render consistently on GitHub by correcting incompatible Markdown math patterns and strengthening CI regression guards.
Bug Fixes:
Enhancements:
CI:
Documentation: