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

Commit eb39da6

Browse files
authored
Move HTML parsing to a separate file for URL previews. (#11566)
* Splits the logic for parsing HTML from the resource handling code. * Fix a circular import in the oEmbed code (which uses the HTML parsing code). * Renames some of the HTML parsing methods to: * Make it clear which methods are "internal" to the module. * Clarify what the methods do.
1 parent 5305a5e commit eb39da6

File tree

6 files changed

+432
-401
lines changed

6 files changed

+432
-401
lines changed

changelog.d/11566.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Split the HTML parsing code from the URL preview resource code.

synapse/rest/media/v1/oembed.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import attr
1919

20+
from synapse.rest.media.v1.preview_html import parse_html_description
2021
from synapse.types import JsonDict
2122
from synapse.util import json_decoder
2223

@@ -245,8 +246,6 @@ def calc_description_and_urls(open_graph_response: JsonDict, html_body: str) ->
245246
if video_urls:
246247
open_graph_response["og:video"] = video_urls[0]
247248

248-
from synapse.rest.media.v1.preview_url_resource import _calc_description
249-
250-
description = _calc_description(tree)
249+
description = parse_html_description(tree)
251250
if description:
252251
open_graph_response["og:description"] = description

0 commit comments

Comments
 (0)