Skip to content

Commit b6cda43

Browse files
Help: Fix function return to avoid error when clicking URL on built-in browser (FreeCAD#17498)
* Help: Fix function return to avoid error when clicking URL on built-in browser * fixup! Help: Fix function return to avoid error when clicking URL on built-in browser Co-authored-by: Yorik van Havre <[email protected]> --------- Co-authored-by: Yorik van Havre <[email protected]>
1 parent 4f323f9 commit b6cda43

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Mod/Help/Help.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,20 @@ def location_url(url_localized: str, url_english: str) -> tuple:
160160
"""
161161
Returns localized documentation url and page name, if they exist,
162162
otherwise defaults to english version.
163+
Page name is gotten from:
164+
a) Name/* metadata tag on raw markdown files from github,
165+
Wiki translators should make sure to add it.
166+
b) <title> HTML tag
163167
"""
164168
try:
165169
req = urllib.request.Request(url_localized)
166170
with urllib.request.urlopen(req) as response:
167171
html = response.read().decode("utf-8")
168-
if re.search(r"https://wiki.freecad.org", url_localized):
169-
pagename_match = re.search(r"<title>(.*?) - .*?</title>", html)
170-
else:
172+
if re.search(MD_RAW_URL, url_localized):
171173
pagename_match = re.search(r"Name/.*?:\s*(.+)", html)
174+
else:
175+
# Pages from FreeCAD Wiki fall here
176+
pagename_match = re.search(r"<title>(.*?) - .*?</title>", html)
172177
if pagename_match is not None:
173178
return (url_localized, pagename_match.group(1))
174179
else:
@@ -177,17 +182,19 @@ def location_url(url_localized: str, url_english: str) -> tuple:
177182
return (url_english, "")
178183

179184

180-
def get_location(page):
181-
"""retrieves the location (online or offline) of a given page"""
185+
def get_location(page) -> tuple:
186+
"""retrieves the location (online or offline) of a given page. Returns the location and the page name"""
182187

183188
location = ""
184189
if page.startswith("http"):
185-
return page
190+
# NOTE: This gets activated when you open a link on the built-in browser, since
191+
# we don't know the URL, using location_url() fallback to the HTML <title> tag
192+
return location_url(page, page)
186193
if page.startswith("file://"):
187-
return page[7:]
194+
return (page[7:], "")
188195
# offline location
189196
if os.path.exists(page):
190-
return page
197+
return (page, "")
191198
page = page.replace(".md", "")
192199
page = page.replace(" ", "_")
193200
page = page.replace("wiki/", "")

0 commit comments

Comments
 (0)