Skip to content

Commit

Permalink
Use document’s url_fetcher for attachments
Browse files Browse the repository at this point in the history
Also force HTML attachments to be detected as URLs so that url_fetcher is
always used.
  • Loading branch information
liZe committed Mar 7, 2024
1 parent 4b28713 commit 734ee8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion weasyprint/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ def get_html_metadata(html):
if url is None:
LOGGER.error('Missing href in <link rel="attachment">')
else:
attachment = Attachment(url=url, description=attachment_title)
attachment = Attachment(
url=url, description=attachment_title,
url_fetcher=html.url_fetcher)
attachments.append(attachment)
return {
'title': title,
Expand Down
3 changes: 2 additions & 1 deletion weasyprint/pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def generate_pdf(document, target, zoom, **options):
if options['attachments']:
for attachment in options['attachments']:
if not isinstance(attachment, Attachment):
attachment = Attachment(attachment)
attachment = Attachment(
attachment, url_fetcher=document.url_fetcher)
attachments.append(attachment)
pdf_attachments = []
for attachment in attachments:
Expand Down
4 changes: 3 additions & 1 deletion weasyprint/pdf/anchors.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ def add_annotations(links, matrix, document, pdf, page, annot_files, compress):
# TODO: Use the title attribute as description. The comment
# above about multiple regions won't always be correct, because
# two links might have the same href, but different titles.
attachment = Attachment(
url=annot_target, url_fetcher=document.url_fetcher)
annot_files[annot_target] = write_pdf_attachment(
pdf, Attachment(annot_target), compress)
pdf, attachment, compress)
annot_file = annot_files[annot_target]
if annot_file is None:
continue
Expand Down

0 comments on commit 734ee8e

Please sign in to comment.