Skip to content

Commit

Permalink
Fix bug when image source paths are absolute, see #32
Browse files Browse the repository at this point in the history
  • Loading branch information
timvink committed Dec 18, 2020
1 parent 04a2646 commit 5e8683b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mkdocs_print_site_plugin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def fix_image_src(page_html, page_url, directory_urls):
new_url = os.path.normpath(os.path.join(os.path.dirname(page_url), img_src))

if directory_urls:
new_url = '..' + os.sep + new_url
new_url = os.path.join('..',new_url)

new_text = img_text.replace(img_src, new_url)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def test_fix_image_src():
html = "<td>Wraps the hero teaser (if available)</td>\n</tr>\n<tr>\n<td><code>htmltitle</code></td>\n<td>Wraps the <code><title></code> tag</td>\n</tr>\n<tr>\n<td><code>libs</code></td>\n<td>Wraps"
assert fix_image_src(html, "this_page", True) == html

# Make sure absolute urls stay intct
html = '<img src="/img.png">'
assert fix_image_src(html, "this_page", False) == html

# Make sure changes are made
html = '<img src="../appendix/table.png">'
result = '<img src="..%sappendix%stable.png">' % (os.sep, os.sep)
Expand Down

0 comments on commit 5e8683b

Please sign in to comment.