docling-project / docling-project/docling

HTML anchors and links stripped in Markdown

Open
#2,929 2 comments 1 reaction 1 assignee Claimed by @aatrey56 View on GitHub
bug html triage/close-fixed
Dominant language
Python
Stars
66.4k
Forks
4.8k
Avg merge
2d 21h
Merged PRs (30d)
84

Description

### Bug

When converting HTML to Markdown, Docling doesn't preserve anchor links and heading IDs. This means any table of contents or internal cross-references in the original HTML get lost in the conversion. It would be great if anchor links could be converted to Markdown link syntax and heading IDs could be preserved so navigation within the document still works!

Specifically, links like `Section 1` should convert to `[Section 1](#section1)`, and headings with IDs like `

` should convert to `## Section 1 {#section1}` using Markdown's extended syntax. This would maintain the document structure and allow readers to jump between sections just like in the original HTML.

#### Input (`anchors.html`)

```html



Anchors Example



TOC:
Section 1 |
Section 2 |
Section 3

Section 1


Content for section 1.

Section 2


Content for section 2.

Section 3


Content for section 3.


```

#### Actual output

```markdown
## Section 1

Content for section 1.

## Section 2

Content for section 2.

## Section 3

Content for section 3.
```

#### Expected output

```markdown
TOC:
[Section 1](#section1) |
[Section 2](#section2) |
[Section 3](#section3)

## Section 1 {#section1}

Content for section 1.

## Section 2 {#section2}

Content for section 2.

## Section 3 {#section3}

Content for section 3.
```

### Steps to reproduce

```shell
$ docling anchors.html --to md
```

### Docling version

Docling version: 2.70.0
Docling Core version: 2.61.0
Docling IBM Models version: 3.11.0
Docling Parse version: 4.7.3
Python: cpython-314 (3.14.2)
Platform: Windows-11-10.0.26200-SP0

### Python version

Python 3.14.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.