Commit dad9ddeb authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

Add html_img() to finally solve #6

parent 34f83fa7
......@@ -80,6 +80,23 @@ def html_links(s):
return soup.prettify(formatter=None) # formatter=None to avoid ">" -> ">" conversion
def html_img(s):
"""Replace html img src by the right Pelican (relative) URL"""
def src_replace(matchobj):
"""Prepend attachment image path with attachment prefix"""
soup = bs4.BeautifulSoup(s, "html.parser")
for img in soup.find_all('img'):
img_src = img.get('src')
if img_src:
new_src = re.sub(r"\ADocuments/.*", src_replace, img_src)
img['src'] = new_src
return soup.prettify()
def nullify_url(message, text, url):
"""Throw WARNING message and return empty URL"""
msg = f" WARNING: nullify link to {message}\n"
......@@ -213,6 +230,7 @@ def horizontal_rule(s):
def spip_to_markdown(s, website):
"""Convert string from Spip format to Pelican markdown format"""
s = html_links(s)
s = html_img(s)
s = italic(s)
s = bold(s)
s = ordered_list(s)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment