Skip to content

Commit 734ee8e

Browse files
committed
Use document’s url_fetcher for attachments
Also force HTML attachments to be detected as URLs so that url_fetcher is always used.
1 parent 4b28713 commit 734ee8e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

weasyprint/html.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ def get_html_metadata(html):
281281
if url is None:
282282
LOGGER.error('Missing href in <link rel="attachment">')
283283
else:
284-
attachment = Attachment(url=url, description=attachment_title)
284+
attachment = Attachment(
285+
url=url, description=attachment_title,
286+
url_fetcher=html.url_fetcher)
285287
attachments.append(attachment)
286288
return {
287289
'title': title,

weasyprint/pdf/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ def generate_pdf(document, target, zoom, **options):
249249
if options['attachments']:
250250
for attachment in options['attachments']:
251251
if not isinstance(attachment, Attachment):
252-
attachment = Attachment(attachment)
252+
attachment = Attachment(
253+
attachment, url_fetcher=document.url_fetcher)
253254
attachments.append(attachment)
254255
pdf_attachments = []
255256
for attachment in attachments:

weasyprint/pdf/anchors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,10 @@ def add_annotations(links, matrix, document, pdf, page, annot_files, compress):
252252
# TODO: Use the title attribute as description. The comment
253253
# above about multiple regions won't always be correct, because
254254
# two links might have the same href, but different titles.
255+
attachment = Attachment(
256+
url=annot_target, url_fetcher=document.url_fetcher)
255257
annot_files[annot_target] = write_pdf_attachment(
256-
pdf, Attachment(annot_target), compress)
258+
pdf, attachment, compress)
257259
annot_file = annot_files[annot_target]
258260
if annot_file is None:
259261
continue

0 commit comments

Comments
 (0)