Unstructured-IO / Unstructured-IO/unstructured

bug/<partition_md> does not properly handled title hireachy

Open
#3,952 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
HTML
Stars
15.5k
Forks
1.3k
Avg merge
4d 2h
Merged PRs (30d)
13

Description

Describe the bug
When processing markdown using partition_md.The title 'section' should be under 'Chapter 1' as its parent, but in this case, it is NaN. Or could you please suggest if there is any other parameter I might have missed that could be causing this problem? Thanks.

To Reproduce
Provide a code snippet that reproduces the issue.

markdown_document = """# Title\n\n \
## Chapter 1\n\n \
Hi this is Jim\n\n Hi this is Joe\n\n \
### Section \n\n \
Hi this is Lance \n\n
## Chapter 2\n\n \
Hi this is Molly"""

from unstructured.partition.md import partition_md
from unstructured.staging.base import convert_to_dataframe

# file = r"C:\Users\Cjy\Desktop\fix\out.md"
raw_md_elements = partition_md(text=markdown_document)
df = convert_to_dataframe(raw_md_elements)
df

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
Image

Environment Info
Please run python scripts/collect_env.py and paste the output here.
This will help us understand more about the environment in which the bug occurred.

Additional context
version: 0.12.5

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 partition_md(text=...) entry point and inspect how the markdown headings in the provided reproduction are converted into elements and then into a dataframe by convert_to_dataframe. Confirm the observed NaN parent for “Section” and define the expected heading hierarchy before changing behavior; add or update a focused regression test for the sample markdown.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.