Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Improve URL previews by not including the content of media tags in th…
Browse files Browse the repository at this point in the history
…e generated description. (#12887)
  • Loading branch information
reivilibre committed May 26, 2022
1 parent 9385cd0 commit 317248d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/12887.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve URL previews by not including the content of media tags in the generated description.
10 changes: 9 additions & 1 deletion synapse/rest/media/v1/preview_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def parse_html_description(tree: "etree.Element") -> Optional[str]:
Grabs any text nodes which are inside the <body/> tag, unless they are within
an HTML5 semantic markup tag (<header/>, <nav/>, <aside/>, <footer/>), or
if they are within a <script/> or <style/> tag.
if they are within a <script/>, <svg/> or <style/> tag, or if they are within
a tag whose content is usually only shown to old browsers
(<iframe/>, <video/>, <canvas/>, <picture/>).
This is a very very very coarse approximation to a plain text render of the page.
Expand All @@ -268,6 +270,12 @@ def parse_html_description(tree: "etree.Element") -> Optional[str]:
"script",
"noscript",
"style",
"svg",
"iframe",
"video",
"canvas",
"img",
"picture",
etree.Comment,
)

Expand Down

0 comments on commit 317248d

Please sign in to comment.