docling-project / docling-project/docling
md: inline markup inside table cells shreds tables (code spans) and deletes intra-cell spaces
- Dominant language
- Python
- Stars
- 66.4k
- Forks
- 4.8k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 98
Description
### Bug
Two related defects in `md_backend.py`'s hand-rolled GFM table handling (marko has no table extension, so table lines are accumulated in `md_table_buffer`). Both are silent output corruption. Verified on main @ 127debc.
**1. A code span in a cell closes the table mid-row** (`md_backend.py:524`)
```python
elif isinstance(element, marko.inline.CodeSpan):
self._close_table(doc)
```
Every other inline node that can appear in a cell is table-transparent (`Emphasis`, `StrongEmphasis`, `Link` all fall through), but `CodeSpan` unconditionally flushes the half-built buffer. For
```markdown
| Command | Description |
| --- | --- |
| run `build` now | builds it |
| clean | removes it |
```
the output is **two** tables (2×2 and 1×2), the word "run" is dropped entirely (partial row `"| run"` splits to `[]` via `[1:-1]`), and ` now | builds it |` leaks into the body as a plain TEXT item containing raw pipe syntax. Expected: one 3×2 table.
**2. Any inline markup deletes the whitespace around it** (`md_backend.py:494`)
Inside a table, each inline fragment is `.strip()`ed *before* being concatenated onto the buffer (`md_table_buffer[-1] += snippet_text`), so the intra-cell spaces at fragment boundaries are destroyed:
| input cell | output cell |
|---|---|
| `very **important** thing` | `veryimportantthing` |
| `a *b* c` | `abc` |
| `see [the docs](http://x) now` | `seethe docsnow` |
The existing fixture `inline_and_formatting.md` doesn't catch this because its markup spans entire cells, so only delimiter-adjacent whitespace is stripped.
### Relationship to #3891
#3891 reworks inline whitespace via the InlineGroup contract, but the table path here is the separate `md_table_buffer` accumulation, which builds plain strings rather than InlineGroups — as far as I can tell it isn't covered by that PR. Flagging it so the fix can be sequenced with #3891 if the maintainers prefer.
### Docling version
main @ 127debc · Python 3.12
Happy to send a patch with parametrized tests for both once the #3891 interaction is confirmed.
### Blocked By
- [ ] #3891
- [ ] docling-project/docling-core#693
- [ ] #3817
Contributor guide
Research direction
Start in md_backend.py around lines 494 and 524, then inspect the inline_and_formatting.md fixture and the table accumulation through md_table_buffer. Add coverage for code spans and markup with intra-cell spaces, and confirm the result is one intact 3×2 table with the original spacing preserved; check the interaction with #3891 before finalizing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- markdown, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 67/100