Skip to content

Commit 04c64fe

Browse files
committed
Testing markdown support
Tests: * Support of Archive in Document creation * Support of external / internal links
1 parent 64104e2 commit 04c64fe

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/test_markdown_support.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pymupdf
2+
import pathlib
3+
4+
5+
def test_archive_markdown():
6+
"""Test Archive support."""
7+
path = pathlib.Path().absolute() / "resources"
8+
md = b"![](nur-ruhig.jpg)\n\n**A referenced image.**"
9+
md_doc = pymupdf.open(stream=md, filetype="md", archive=path.name)
10+
pdfdata = md_doc.convert_to_pdf()
11+
doc = pymupdf.open(stream=pdfdata)
12+
page = doc[0]
13+
images = page.get_image_info()
14+
assert len(images) == 1
15+
16+
def test_archive_links():
17+
"""Create an internal and an external link and confirm
18+
that they are correctly converted to PDF links."""
19+
md = """Some text containing an external [link](http://www.google.com) to Google.
20+
Now an internal link to a header in this document: [Some Header](#some-header). The header is here:
21+
22+
<h2 id="some-header">Some Header</h2>
23+
24+
Some text following the header.
25+
"""
26+
md_doc = pymupdf.open(stream=md.encode(), filetype="md")
27+
pdfdata = md_doc.convert_to_pdf()
28+
doc = pymupdf.open(stream=pdfdata)
29+
page = doc[0]
30+
links=page.get_links()
31+
assert len(links) == 2
32+
assert links[0]["uri"] == "http://www.google.com"
33+
assert links[0]["kind"] == pymupdf.LINK_URI
34+
assert links[1]["kind"] == pymupdf.LINK_GOTO

0 commit comments

Comments
 (0)