fix(md): recognize ATX headings indented by up to three spaces #4755
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.39) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 269 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.335
Real PR Conversation Timeline
1 comments
"Review active on #4755"
general
weight: 0.35
chrikrah
Summary
partition_mdleft a heading as plain text when it was indented by one to three spaces, for example" ## Chapter 1". CommonMark allows this indentation. The heading came out asUncategorizedTextwith the literal##in it, so noTitleelement was created and the following elements got the wrongparent_id(and nocategory_depth). This is the case reported in #3952, where the sample string is built with\line continuations that add a leading space to each line.Root cause: Python-Markdown's
HashHeaderProcessoronly matches#in the first column. The fix adds a small internal extension that registers a subclass of that processor. Its regex allows[ ]{0,3}before the#. Four or more spaces still give an indented code block. Fenced code is stashed by the preprocessor before block parsing, so it is not affected. The extension is always added after the user'sextensionslist.Fixes #3952
Validation
test_unstructured/partition/test_md.py:- indented headings (1 and 3 spaces) become
Titleelements with the rightcategory_depthandparent_idchain (fails onmain, passes now);- a 4-space-indented
# ...line is still code, not a heading..venv/bin/python -m pytest test_unstructured/partition/test_md.py-> 43 passedruff checkandruff format --checkon the changed files: clean.Repro from the issue now gives
Title(Chapter 1)->Title(Section)-> body text, each with the expected parent.<!-- This is an auto-generated description by cubic. -->
<a href="https://cubic.dev/pr/Unstructured-IO/unstructured/pull/4755?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->