DOCX: footnote references and back-links point to anchors that don't exist in the Markdown
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- markdown, python
- Área
- documentation
Línea de trabajo
Lee packages/markitdown/src/markitdown/converters/_docx_converter.py y _markdownify.py, especialmente _CustomMarkdownify.convert_a, y luego reproduce el problema con los comandos proporcionados footnote.py y markitdown footnote.docx. Rastrea cómo se gestionan la referencia a la nota al pie de página y los identificadores de los elementos de lista de mammoth durante la conversión de HTML a Markdown. El trabajo estará terminado cuando la salida no contenga enlaces a anclas inexistentes e, idealmente, conserve la referencia y la nota como sintaxis de nota al pie enlazada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Converting a DOCX that has footnotes gives links such as [[1]](#footnote-1) and [↑](#footnote-ref-1), but no element in the Markdown has those ids, so every link is dead. mammoth's HTML has the ids (<a id="footnote-ref-1">, <li id="footnote-1">). They are lost in MarkItDown's HTML-to-Markdown step.
Reproduction
footnote.py writes a one-paragraph document with one footnote:
import zipfile
W = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"'
REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
with zipfile.ZipFile("footnote.docx", "w") as z:
z.writestr(
"[Content_Types].xml",
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">'
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>'
'<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>'
'<Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"/>'
"</Types>",
)
z.writestr(
"_rels/.rels",
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
f'<Relationship Id="rId1" Type="{REL}/officeDocument" Target="word/document.xml"/>'
"</Relationships>",
)
z.writestr(
"word/_rels/document.xml.rels",
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">'
f'<Relationship Id="rId1" Type="{REL}/footnotes" Target="footnotes.xml"/>'
"</Relationships>",
)
z.writestr(
"word/document.xml",
f'<w:document {W}><w:body><w:p><w:r><w:t>Text</w:t></w:r>'
'<w:r><w:footnoteReference w:id="1"/></w:r></w:p></w:body></w:document>',
)
z.writestr(
"word/footnotes.xml",
f'<w:footnotes {W}><w:footnote w:id="1"><w:p><w:r><w:t>A note.</w:t></w:r></w:p></w:footnote></w:footnotes>',
)
python footnote.py
markitdown footnote.docx
Actual output
Text[[1]](#footnote-1)
1. A note. [↑](#footnote-ref-1)
mammoth's HTML for the same file (mammoth.convert_to_html) has both targets:
<p>Text<sup><a href="#footnote-1" id="footnote-ref-1">[1]</a></sup></p><ol><li id="footnote-1"><p>A note. <a href="#footnote-ref-1">↑</a></p></li></ol>
Expected output
No links to missing anchors. Ideally the footnote is kept as a footnote, for example in GFM footnote syntax:
Text[^1]
[^1]: A note.
Versions
markitdown 0.1.9 (markitdown[docx]), mammoth 1.13.0, markdownify 1.2.3, Python 3.14, Linux x86_64. main (7482c09) has no changes to the DOCX or HTML-to-Markdown code since 0.1.9.
Cause
DocxConverter passes mammoth's HTML to HtmlConverter. _CustomMarkdownify.convert_a writes [text](href) and drops the <a> element's id. markdownify's li conversion drops the <li> element's id. So the href="#footnote-…" links survive, but their targets don't.
Related
- #2125 (open) and #314 (open): dead
#_Toc…links from internal hyperlinks (TOC entries and cross-references,w:hyperlink w:anchor). Footnote references are a different construct, generated by mammoth. - PR #2131 (open, for #2125): unwraps
w:hyperlink w:anchorin pre-processing. It would not change footnote links, which mammoth generates. - PR #2265 (open): renders every fragment-only link as plain text. That would remove these dead links too, but the reference and the note would no longer be connected.
Drafted with the help of an AI assistant; every reproduction was run and its output checked.
- Lenguaje dominante
- Python
- Estrellas
- 194k
- Forks
- 14.5k
- Merge medio
- 24 min
- PR fusionados (30 d)
- 7
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/markitdown
-
URL fetch sends default python-requests User-Agent, Wikipedia returns 403Posiblemente ocupada @sushan5140 la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
microsoft/markitdown#2820 ·
Los mantenedores suelen responder en 1 día
-
Valid Atom feeds with zero entries are rejected as an unknown feed typePosiblemente ocupada @pujitha24 la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
microsoft/markitdown#2781 ·
Los mantenedores suelen responder en 1 día
-
DOCX math: a delimiter with several arguments keeps only the last onePosiblemente ocupada @drakeo338 la tomó hace 34 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
microsoft/markitdown#2573 ·
Los mantenedores suelen responder en 1 día
-
DOCX: Heading 7-9 styles lose heading structure entirely (render as plain paragraphs)Posiblemente ocupada @stanleys12 la tomó hace 39 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
microsoft/markitdown#2530 ·
Los mantenedores suelen responder en 1 día
-
PPTX chart conversion drops parent category labelsPosiblemente ocupada @pentaoa la tomó hace 50 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
microsoft/markitdown#2502 ·
Los mantenedores suelen responder en 1 día
Todos los issues de microsoft/markitdown
Issues similares
-
area:docs documentation effort:M ready-for-agent
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
mczielinski/ob-analytics#423 ·
Los mantenedores suelen responder en 1 día
-
flaky: test_ci_eval_scope_exclude never-matches case spends its 1s budget on the rollout waitAbiertoneeds-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
gke-labs/kube-agents#4838 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
danyuchn/asd-ste100-skill#60 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 64/100
Gathin23/cleanyourtv#3299 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
autowarefoundation/autoware_carla_scenario#1485 ·
Los mantenedores suelen responder en 1 día