Files
md_to_gost/tests/test_biblio_links.py
Igor20264 1a5b35eb54
Python application / build (push) Has been cancelled
BigUpdate 0.5.0
- add Local Render Mermaid
- add page-starе для указания смещения страниц
- add Гиперссылки в документе на списки литературы
2026-09-07 09:54:33 +03:00

47 lines
1.4 KiB
Python

"""Bibliography citation hyperlinks."""
from docx import Document
from docx.oxml.ns import qn
from md2gost.bibliography import biblio_bookmark_name
from md2gost.bibliography_renderable import Bibliography
from md2gost.bibliography import BiblioEntry
from md2gost.renderable.paragraph import Paragraph
def test_biblio_bookmark_name():
assert biblio_bookmark_name("1") == "biblio_1"
assert biblio_bookmark_name("1.5") == "biblio_1_5"
def test_entry_has_bookmark():
doc = Document()
e = BiblioEntry(key="1", text="Иванов И. И. Книга.")
p = Bibliography._make_entry(doc._body, e)
xml = p._docx_paragraph._p.xml
assert 'w:name="biblio_1"' in xml
assert "bookmarkStart" in xml
assert "bookmarkEnd" in xml
def test_cite_becomes_internal_hyperlink():
doc = Document()
p = Paragraph(doc._body)
p.add_run_with_citations("See [1] and [2, 3].")
xml = p._docx_paragraph._p.xml
assert 'w:anchor="biblio_1"' in xml
assert 'w:anchor="biblio_2"' in xml
assert 'w:anchor="biblio_3"' in xml
assert ">1</w:t>" in xml
assert ">2</w:t>" in xml
assert ">3</w:t>" in xml
def test_plain_text_without_cites_unchanged():
doc = Document()
p = Paragraph(doc._body)
p.add_run_with_citations("Просто текст без ссылок.")
xml = p._docx_paragraph._p.xml
assert "w:hyperlink" not in xml
assert "Просто текст без ссылок." in p._docx_paragraph.text