Skip to content

Commit 4be7f53

Browse files
committed
Improve performance of get_title()
1 parent 07ae701 commit 4be7f53

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

sphinxext/opengraph/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def get_tags(
7474
desc_len = DEFAULT_DESCRIPTION_LENGTH
7575

7676
# Get the title and parse any html in it
77-
title = get_title(context["title"], skip_html_tags=False)
78-
title_excluding_html = get_title(context["title"], skip_html_tags=True)
77+
title, title_excluding_html = get_title(context["title"])
7978

8079
# Parse/walk doctree for metadata (tag/description)
8180
description = get_description(doctree, desc_len, [title, title_excluding_html])

sphinxext/opengraph/titleparser.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ def handle_data(self, data) -> None:
2626
self.text_outside_tags += data
2727

2828

29-
def get_title(title: str, skip_html_tags: bool = False):
29+
def get_title(title: str):
3030
htp = HTMLTextParser()
3131
htp.feed(title)
3232
htp.close()
3333

34-
if skip_html_tags:
35-
return htp.text_outside_tags
36-
else:
37-
return htp.text
34+
return htp.text, htp.text_outside_tags

0 commit comments

Comments
 (0)