-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(staging): render list bullets and title heading depth in markdown element_to_md() function
#4384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(staging): render list bullets and title heading depth in markdown element_to_md() function
#4384
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| ElementMetadata, | ||
| Formula, | ||
| Image, | ||
| ListItem, | ||
| Table, | ||
| Title, | ||
| ) | ||
|
|
@@ -278,8 +279,16 @@ def element_to_md( | |
| formula_markdown_style: str = FORMULA_MARKDOWN_AUTO, | ||
| ) -> str: | ||
| match element: | ||
| case Title(text=text): | ||
| return f"# {text}" | ||
| case Title(text=text, metadata=metadata): | ||
| depth = metadata.category_depth if metadata.category_depth else 1 | ||
| if not isinstance(depth, int): | ||
| try: | ||
| depth = int(depth) if isinstance(depth, (str, float)) else 1 | ||
| except (TypeError, ValueError): | ||
| depth = 1 | ||
| return f"{'#' * depth} {text}" | ||
| case ListItem(text=text): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The new Prompt for AI agents |
||
| return f"- {text}" | ||
| case Formula(text=text): | ||
| return _emit_formula_markdown( | ||
| text, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: The new Markdown heading logic is off-by-one because
metadata.category_depthis zero-indexed in this codebase, but the code treats it as the literal Markdown heading level. For example, an h2 (category_depth=1) renders as#instead of##, and an h3 (category_depth=2) renders as##instead of###. This undermines the PR's goal of adding L2/L3 header support.Also, the converted depth is not clamped to Markdown's valid 1-6 ATX heading range, so edge-case values like
0, negatives, or values greater than 5 can produce invalid or oversized heading markers. Consider computing the Markdown depth asmax(1, min(category_depth + 1, 6))and treatingNoneas the top-level default (0).Prompt for AI agents