Link to images in RSS output
This commit is contained in:
parent
c0ec365561
commit
454643e5e1
18
src/rss.py
18
src/rss.py
@ -42,12 +42,24 @@ def enrich_msg(
|
|||||||
lines,
|
lines,
|
||||||
is_atom=True,
|
is_atom=True,
|
||||||
accepted_images=[],
|
accepted_images=[],
|
||||||
base_url=None,
|
base_url="",
|
||||||
trailing_punctuation=None,
|
trailing_punctuation="",
|
||||||
desc_len_limit=-1,
|
desc_len_limit=-1,
|
||||||
):
|
):
|
||||||
if not is_atom:
|
if not is_atom:
|
||||||
return line2words(lines, desc_len_limit, trailing_punctuation)
|
from urllib.parse import urljoin
|
||||||
|
words = line2words(lines, desc_len_limit, trailing_punctuation)
|
||||||
|
for i in range(len(words)):
|
||||||
|
token = words[i]
|
||||||
|
core = token.rstrip(trailing_punctuation)
|
||||||
|
suffix = token[len(core):]
|
||||||
|
if len(core) == 0 or "<" in core or ">" in core:
|
||||||
|
continue
|
||||||
|
if _is_image_token(core, accepted_images):
|
||||||
|
abs_url = urljoin(base_url, core)
|
||||||
|
anchor = f"<a href=\"{escape(abs_url)}\">{escape(abs_url)}</a>"
|
||||||
|
words[i] = anchor + suffix
|
||||||
|
return words
|
||||||
content = []
|
content = []
|
||||||
parser = My_Html_Parser([])
|
parser = My_Html_Parser([])
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user