scrap the is_atom logic in enrich_msg

This commit is contained in:
Eloi Torrents 2025-09-06 08:55:33 +02:00
parent 77499c700d
commit a372df0951

View File

@ -42,7 +42,6 @@ def _is_image_token(token: str, extensions):
# this is similar to the markup function in microblog # this is similar to the markup function in microblog
def enrich_msg( def enrich_msg(
lines, lines,
is_atom=True,
accepted_images=[], accepted_images=[],
base_url="", base_url="",
trailing_punctuation="", trailing_punctuation="",
@ -57,6 +56,7 @@ def enrich_msg(
words = line.split() words = line.split()
for i in range(len(words)): for i in range(len(words)):
word = words[i] word = words[i]
core = word.rstrip(trailing_punctuation)
if word.find("src=") == 0 \ if word.find("src=") == 0 \
or word.find("href=") == 0: or word.find("href=") == 0:
continue continue
@ -64,14 +64,12 @@ def enrich_msg(
w = escape(word) w = escape(word)
new_word = ("<a href=\"%s\">%s</a>") % (w, w) new_word = ("<a href=\"%s\">%s</a>") % (w, w)
words[i] = new_word words[i] = new_word
elif not is_atom: elif _is_image_token(core, accepted_images):
core = word.rstrip(trailing_punctuation) suffix = word[len(core):]
if _is_image_token(core, accepted_images): abs_url = urljoin(base_url, core)
suffix = word[len(core):] anchor = f"<a href=\"{escape(abs_url)}\">{escape(abs_url)}</a>"
abs_url = urljoin(base_url, core) new_word = anchor + suffix
anchor = f"<a href=\"{escape(abs_url)}\">{escape(abs_url)}</a>" words[i] = new_word
new_word = anchor + suffix
words[i] = new_word
words.insert(0,"<p>") words.insert(0,"<p>")
words.append("</p>") words.append("</p>")
content.append(" ".join(words)) content.append(" ".join(words))
@ -117,7 +115,6 @@ def write_feed(posts, filename, params, tagname=None):
de = " ".join( de = " ".join(
enrich_msg( enrich_msg(
msg, msg,
is_atom=params["use_atom"],
base_url=params["url"], base_url=params["url"],
accepted_images=params["accepted_images"], accepted_images=params["accepted_images"],
trailing_punctuation=params["trailing_punctuation"], trailing_punctuation=params["trailing_punctuation"],