mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
doc: wikiparser: Assign text to URLs that don't provide them
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
0bb8dc68fe
commit
c7afe8c688
@ -512,6 +512,17 @@ class Anchor(Element):
|
|||||||
return f'<anchor id="{self.name}"/>'
|
return f'<anchor id="{self.name}"/>'
|
||||||
|
|
||||||
|
|
||||||
|
def get_url_text(url):
|
||||||
|
"""Return text to assign to URLs if not provided."""
|
||||||
|
if re.match(r'[A-Za-z]+://', url) or url.startswith('#'):
|
||||||
|
return None
|
||||||
|
|
||||||
|
if re.match(r'[A-Za-z]+:', url):
|
||||||
|
return url.partition(':')[2]
|
||||||
|
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
def resolve_url(url, context):
|
def resolve_url(url, context):
|
||||||
"""Expand a URL into a full path."""
|
"""Expand a URL into a full path."""
|
||||||
if re.match(r'https?://', url) or url.startswith('mailto:') or \
|
if re.match(r'https?://', url) or url.startswith('mailto:') or \
|
||||||
@ -618,7 +629,7 @@ def parse_text(line, context=None, parse_links=True):
|
|||||||
if remaining:
|
if remaining:
|
||||||
params, _, remaining = remaining.partition('|')
|
params, _, remaining = remaining.partition('|')
|
||||||
|
|
||||||
text = text or target
|
text = text or get_url_text(target)
|
||||||
link = Link(target.strip(), [ItalicText(text.strip())], params)
|
link = Link(target.strip(), [ItalicText(text.strip())], params)
|
||||||
result.append(link)
|
result.append(link)
|
||||||
continue
|
continue
|
||||||
@ -650,7 +661,7 @@ def parse_text(line, context=None, parse_links=True):
|
|||||||
if content:
|
if content:
|
||||||
target, _, remaining = content.partition('|')
|
target, _, remaining = content.partition('|')
|
||||||
target = target.strip()
|
target = target.strip()
|
||||||
text = target
|
text = get_url_text(target)
|
||||||
if remaining:
|
if remaining:
|
||||||
# Handle embedded attachments inside links
|
# Handle embedded attachments inside links
|
||||||
if '{{' in remaining and '}}' in remaining:
|
if '{{' in remaining and '}}' in remaining:
|
||||||
@ -662,8 +673,9 @@ def parse_text(line, context=None, parse_links=True):
|
|||||||
else:
|
else:
|
||||||
text, _, remaining = remaining.partition('|')
|
text, _, remaining = remaining.partition('|')
|
||||||
|
|
||||||
text = text.strip()
|
if text:
|
||||||
text = parse_text(text, parse_links=False)
|
text = text.strip()
|
||||||
|
text = parse_text(text, parse_links=False)
|
||||||
|
|
||||||
params = None
|
params = None
|
||||||
if remaining:
|
if remaining:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user