Skip to content

Commit

Permalink
Use full path for images to avoid rst2pdf 'Missing image file' error (#7
Browse files Browse the repository at this point in the history
)
  • Loading branch information
wombelix committed Apr 4, 2023
1 parent e9f44d4 commit cbf5b23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: patch

Use full path for images to avoid rst2pdf “Missing image file” error ([#7](https://github.com/pelican-plugins/pdf/pull/7))
10 changes: 10 additions & 0 deletions pelican/plugins/pdf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def _create_pdf(self, obj, output_path):
text = f.read()

header = ""

# Use full path for images to avoid rst2pdf 'Missing image file' error
# Match reStructuredText Syntax: ..image:: {static}/images/picture.jpg
text = re.sub(r"(\.\. image:: )({.*})", r"\1" + self.path, text)

elif ext[1:] in mdreader.file_extensions and mdreader.enabled:
text, meta = mdreader.read(obj.source_path)
header = ""
Expand All @@ -81,6 +86,11 @@ def _create_pdf(self, obj, output_path):
# non-escaped characters. Here we nicely escape them to XML/HTML
# entities before proceeding
text = text.encode("ascii", "xmlcharrefreplace").decode()

# Use full path for images to avoid rst2pdf 'Missing image file' error
# Match Markdown Syntax: ![alt]({static}/images/picture.jpg)
text = re.sub(r"(!\[.*\]\()({.*})", r"\1" + self.path, text)

else:
# We don't support this format
logger.warn("Ignoring unsupported file " + obj.source_path)
Expand Down

0 comments on commit cbf5b23

Please sign in to comment.