Skip to content

fix(asciidoc): replace attribute references with their values - #5117

Open
sarankumar1325 wants to merge 8 commits into
docling-project:mainfrom
sarankumar1325:fix/asciidoc-attribute-references
Open

sarankumar1325 wants to merge 8 commits into
docling-project:mainfrom
sarankumar1325:fix/asciidoc-attribute-references

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

AsciiDoc attribute references such as {product} stayed literal in the converted output, and attribute entries were only partly handled (:name!: / :!name: unset entries leaked into the next paragraph as text).

This change makes the AsciiDoc backend:

  • collect header attribute entries before parsing, so they also apply to the document title;
  • apply attribute entries in document order (set, redefine, unset with :name!: or :!name:), substituting references in values;
  • replace {name} references in titles, section headings, paragraphs, list items, table cells and block titles (.Caption);
  • keep \{name} as a literal {name}, and leave references to unset attributes as written (Asciidoctor's default attribute-missing: skip);
  • support Asciidoctor's predefined character attributes ({nbsp}, {sp}, {empty}, {plus}, ...);
  • leave listing and literal blocks verbatim.

Attribute names are matched case-insensitively, as in Asciidoctor.

Issue resolved by this Pull Request:
Resolves #5116

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

Before: the example from the issue converted to # Widget Guide / Welcome to {product} {version}. / :version!: / The version is {version} now.
After: # Widget Guide / Welcome to Widget 2.4. / The version is unset now.

  • uv run pytest tests/test_backend_asciidoc.py: 67 passed. 4 of the 5 new tests fail on main; the listing test is there to make sure code blocks are not substituted.
  • ruff format / ruff check (v0.17.2): clean.
  • ty check docling/backend/asciidoc_backend.py (ty 0.0.33): same diagnostics as on main, nothing new.
  • scripts/check_max_lines.py --max-lines=1500 on the touched files: passes.
  • No reference data changed. Not run: full make test / make validate.

I used AI help to write this change. I reviewed and tested it myself.

Attribute references such as {product} stayed literal in titles,
paragraphs, list items, table cells and block titles. Attribute entries
now set document attributes in order (header attributes also apply to
the document title), :name!: and :!name: unset them instead of leaking
into the next paragraph, \{name} keeps a literal reference, and a
reference to an unset attribute stays as written, as in Asciidoctor.
Asciidoctor's predefined character attributes ({nbsp}, {sp}, {empty},
...) are supported too. Listing and literal blocks stay verbatim.

Resolves docling-project#5116

Signed-off-by: sarankumar1325 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @sarankumar1325, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) asciidoc issue related to asciidoc backend bug Something isn't working labels Oct 31, 2026
@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 6ff3d9ebcb. The analysis read the diff only. It did not run code from this pull request.

The PR makes the AsciiDoc backend read attribute entries (set, redefine, unset). It replaces {name} references with their values in titles, headings, paragraphs, list items, table cells and captions. It leaves listing blocks unchanged. The PR adds docling/backend/asciidoc_attributes.py and new tests.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#5640 open changes the same code related: This PR reads description lists (term:: definition). It edits the same _parse method and the same table helpers as this PR, so the two can conflict when merged. The two PRs fix different problems, and both can be merged.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): blocker found

This review covers the full diff at e06f5dc30d. It read the code and did not run it.

The main risk is table corruption when table cells contain attribute references with pipe characters, such as {vbar}. The reviewer must verify that attribute substitution for tables runs on individual cell contents after splitting delimiters instead of on the full line.

A maintainer makes the merge decision. This review never approves the pull request.

Comment thread docling/backend/asciidoc_backend.py Outdated
elif self._is_table_line(line): # within a table
in_table = True
table_data.append(self._parse_table_line(line))
table_data.append(self._parse_table_line(text_line))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocker: Attribute substitution before table parsing splits {vbar} into extra cells

The parser substitutes attribute references on the whole line before _parse_table_line splits the line into cells. When a cell contains {vbar} (defined as | in _INTRINSIC_ATTRIBUTES) or an attribute that contains |, _substitute_attributes inserts an unescaped pipe character into the line. _parse_table_line then splits on that pipe character as a column delimiter. This splits one cell into multiple cells and corrupts the table structure.

Substitute attribute references on each cell text after _parse_table_line splits the row into cells.

@github-actions github-actions Bot added the ai:review-changes AI first review suggests changes label Oct 31, 2026
…tting

A value containing "|", such as {vbar}, was inserted before the row was
split into cells, so it became a column delimiter. Rows are now split
first and each cell (and each continuation line) is substituted.

Signed-off-by: sarankumar1325 <[email protected]>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-changes AI first review suggests changes labels Oct 31, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the changes since e06f5dc30d at f942260546. It read the code and did not run it.

The earlier blocker (table corruption when an attribute value contains |) is fixed. The incremental diff splits table rows on the raw line before applying attribute substitution, and the new test covers both {vbar} and a multi-pipe attribute value. No new issues found.

Earlier findings

  • fixed (blocker): Attribute substitution before table parsing splits {vbar} into extra cells

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 31, 2026
Comment thread docling/backend/asciidoc_backend.py Outdated
# references replaced before its text is used.
if self._apply_attribute_entry(stripped_line, attributes):
continue
text_line = self._substitute_attributes(line, attributes)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use {asterisk}not bold{asterisk} here. comes out bold and {backtick}ls{backtick} turns into code, since the refs get replaced before inline parsing. Asciidoctor swaps attributes in after quotes, so these should stay literal. Maybe worth a test?

Asciidoctor replaces attribute references after inline formatting, so
{asterisk}not bold{asterisk} and {backtick}ls{backtick} are plain text.
The backend replaced references before parsing inline marks, which made
them bold and code. Marks in paragraph values are now held as stand-ins
until the paragraph is formatted. Marks around a reference still format
its value.

Signed-off-by: sarankumar1325 <[email protected]>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Oct 31, 2026
@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.61111% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/asciidoc_backend.py 97.61% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@PeterStaar-IBM

Copy link
Copy Markdown
Member

Hi @sarankumar1325, thank you for this pull request.

It has a merge conflict with main. Please rebase your branch on the latest main and resolve the conflict:

git fetch upstream
git rebase upstream/main
# resolve the conflicts, then:
git push --force-with-lease

We can continue with the review and CI after that.

Resolve conflict in asciidoc_backend.py by keeping attribute-reference
substitution and mark protection from this branch alongside hyperlink
parsing, _join_lines, and bold captions from main.

Signed-off-by: sarankumar1325 <[email protected]>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Nov 6, 2026
…ute-references

Signed-off-by: sarankumar1325 <[email protected]>

# Conflicts:
#	docling/backend/asciidoc_backend.py
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Nov 9, 2026
asciidoc_backend.py went over the 1500-line limit of the max-lines check.
Move the attribute entry and reference helpers into asciidoc_attributes.py.

Signed-off-by: sarankumar1325 <[email protected]>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Nov 10, 2026
@github-actions github-actions Bot mentioned this pull request Nov 10, 2026
1 of 3 tasks
Signed-off-by: sarankumar1325 <[email protected]>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) asciidoc issue related to asciidoc backend bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsciiDoc: attribute references are not replaced by their values

3 participants