Skip to content

fix(docx): render arabicAbjad, arabicAlpha and hindiNumbers list markers - #5657

Open
asadsehto wants to merge 1 commit into
docling-project:mainfrom
asadsehto:fix/docx-arabic-hindi-numfmt
Open

asadsehto wants to merge 1 commit into
docling-project:mainfrom
asadsehto:fix/docx-arabic-hindi-numfmt

Conversation

@asadsehto

@asadsehto asadsehto commented Nov 28, 2026 •

Copy link
Copy Markdown

List levels with w:numFmt set to arabicAbjad, arabicAlpha or hindiNumbers were not in _VISIBLE_NUMBERING_FORMATS, so they were converted as bullets: every ListItem got marker='' and the numbers Word shows were lost.

This adds the three formats to the visible set and renders their counters in _format_enum_counter, next to the East Asian formats from #4336.

ECMA-376 names these formats ("Arabic Abjad Numerals", "Arabic Alphabet", "Hindi Numbers") but does not list their characters, so the output follows what Microsoft Word 16.112 (macOS) renders. I read Word's markers back with "Convert numbers to text" for every counter from 0 to 112 in each format, and the new code matches all 339:

numFmt 1 2 28 29 57 100
arabicAbjad أ ب غ أأ أأأ عععع
arabicAlpha أ ب ي أأ أأأ طططط
hindiNumbers १ २ २८ २९ ५७ १००
  • arabicAbjad uses the abjad order (أ ب ج د ه و ز ح ط ي ك ل م ن س ع ف ص ق ر ش ت ث خ ذ ض ظ غ) and arabicAlpha the alphabetical order (أ ب ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي). After the 28th letter both repeat it: 29 is two copies of the first letter, 57 three.
  • Word writes a zero-width non-joiner (U+200C) next to each letter, before it for arabicAbjad and after it for arabicAlpha, so repeated letters do not join. The markers keep it, so they match Word's text exactly.
  • hindiNumbers uses Devanagari digits (U+0966 to U+096F), not Arabic-Indic digits.
  • Word shows no marker for 0 in the two letter formats, and these markers are empty too; hindiNumbers gives ०. Negative counters stay decimal, as in the other helpers.

Resolves #5653

Checklist:

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

Review evidence:

Before, the reproducer in #5653 gives ListItem '' and - پهريون نقطو for all three formats. After:

--- arabicAbjad
ListItem '‌أ.' پهريون نقطو
ListItem '‌ب.' ٻيو نقطو
ListItem '‌ج.' ٽيون نقطو
--- arabicAlpha
ListItem 'أ‌.' پهريون نقطو
ListItem 'ب‌.' ٻيو نقطو
ListItem 'ت‌.' ٽيون نقطو
--- hindiNumbers
ListItem '१.' پهريون نقطو
ListItem '२.' ٻيو نقطو
ListItem '३.' ٽيون نقطو

Tests (macOS, Python 3.12):

  • New in tests/test_backend_msword_lists.py: test_format_enum_counter_arabic_and_hindi_num_fmt (16 counters per format, expected strings taken from Word), test_arabic_and_hindi_formatters_keep_negative_values_decimal, and test_list_markers_follow_arabic_and_hindi_num_fmt_end_to_end (a generated DOCX whose letter lists start at 28 so they cross the end of the alphabet, asserting the markers after convert()). 52 tests; 49 of them fail on main.
  • pytest tests/test_backend_msword.py tests/test_backend_msword_lists.py: 372 passed, 1 skipped (main: 320 passed; the difference is the 52 new tests). 13 tests fail and 13 error the same way on main and on this branch, because my environment lacks the optional LaTeX dependency (NameError: UnicodeToLatexEncoder).
  • ruff check and ruff format --check (0.17.2) on the changed files: pass. ty check docling/backend/msword_backend.py (0.0.33): 22 diagnostics, the same 22 as on main. check_max_lines.py: pass.

Not run: the full test suite and make validate (tach, dprint).

Signed-off-by: asad saleem <156583018+asadsehto@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Nov 28, 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) ai:possible-duplicate AI triage: another PR may fix the same problem bug Something isn't working docx issue related to docx backend priority:medium labels Nov 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

The PR makes arabicAbjad, arabicAlpha and hindiNumbers list levels in DOCX files produce visible numbered markers. Before, these levels became bullets with an empty marker. The PR adds counter renderers for the three formats and tests for them.

Topic labels added: bug, docx, priority:medium.

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

Possible duplicates

PR State Signal Assessment
#5656 open also references issue #5653; changes the same code duplicate: Both open PRs fix the same problem (issue #5653) in _format_enum_counter and _VISIBLE_NUMBERING_FORMATS. They differ on the U+200C joiner and on the output for counter 0. Only one of them can be merged.
1 related pull request(s) in the same code
PR State Signal Assessment
#4336 merged referenced as #4336 related: This merged PR added the East Asian w:numFmt renderers and the helpers _int_to_positional_marker and _CJK_ENUM_FORMATTERS. This PR reuses its pattern and helper for different formats.

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

@chrikrah chrikrah 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.

@asadsehto This looks good to merge. At d059c2a the issue's reproducer gives ‌أ., أ‌. and १., and base msword_backend.py fails 49 of the 52 new cases.

$ pytest -q -n 4 tests/test_backend_msword.py tests/test_backend_msword_lists.py   # git archive d059c2a, Python 3.12, docling.__file__ from the export
399 passed
$ (same command, msword_backend.py from base 40e490c)
49 failed, 350 passed
$ ruff check && ruff format --check   # ruff 0.17.2, docling tests docs/examples scripts
979 files already formatted
$ ty check docling/backend/msword_backend.py   # ty 0.0.33: 22 diagnostics, base 22
# not run: the full tests/ tree, tach, dprint

non-blocking: base exported a hindiNumbers list as a - list; its markdown is now one paragraph. docling-core keeps any marker matching \d+\. (markdown.py:425 on main), and \d matches Devanagari digits, which CommonMark rejects:

$ python -c 'from markdown_it import MarkdownIt; print(MarkdownIt("commonmark").render("१. a\n२. b\n"))'
<p>१. a
२. b</p>

decimalFullWidth has done the same since #4336, so I wouldn't hold this PR for it. The fix is [0-9]+\. in docling-core. Can you raise it there?

@asadsehto

asadsehto commented Nov 28, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review @chrikrah! Raised it in docling-core as docling-project/docling-core#1098 and opened a fix: docling-project/docling-core#1099

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) ai:possible-duplicate AI triage: another PR may fix the same problem bug Something isn't working docx issue related to docx backend priority:medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX backend drops arabicAbjad, arabicAlpha and hindiNumbers list numbering

2 participants