mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
doc: wikiparser: Handle existing # in links, don't append again
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
d760ee004f
commit
0bb8dc68fe
@ -194,7 +194,11 @@ class Link(Element):
|
|||||||
for element in self.text:
|
for element in self.text:
|
||||||
link_text += element.to_docbook(context)
|
link_text += element.to_docbook(context)
|
||||||
|
|
||||||
xml = f'<ulink url="{target}">{link_text}</ulink>'
|
if target.startswith('#'):
|
||||||
|
xml = f'<link linkend="{target[1:]}">{link_text}</link>'
|
||||||
|
else:
|
||||||
|
xml = f'<ulink url="{target}">{link_text}</ulink>'
|
||||||
|
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
|
|
||||||
@ -514,6 +518,9 @@ def resolve_url(url, context):
|
|||||||
url.startswith('irc://'):
|
url.startswith('irc://'):
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
if url.startswith('#'):
|
||||||
|
return url
|
||||||
|
|
||||||
if url.startswith('attachment:'):
|
if url.startswith('attachment:'):
|
||||||
target = url.lstrip('attachment:')
|
target = url.lstrip('attachment:')
|
||||||
page_title = context.get('title') if context else None
|
page_title = context.get('title') if context else None
|
||||||
@ -540,9 +547,14 @@ def resolve_url(url, context):
|
|||||||
url = url[3:]
|
url = url[3:]
|
||||||
page_title = page_title.rpartition('/')[0]
|
page_title = page_title.rpartition('/')[0]
|
||||||
|
|
||||||
return f'{BASE_URL}{page_title}/{url}#'
|
url = f'{BASE_URL}{page_title}/{url}'
|
||||||
|
else:
|
||||||
|
url = f'{BASE_URL}{url}'
|
||||||
|
|
||||||
return f'{BASE_URL}{url}#'
|
if '#' not in url:
|
||||||
|
url = url + '#'
|
||||||
|
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
def split_formatted(text, delimiter, end_delimiter=None):
|
def split_formatted(text, delimiter, end_delimiter=None):
|
||||||
@ -606,6 +618,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
|
||||||
link = Link(target.strip(), [ItalicText(text.strip())], params)
|
link = Link(target.strip(), [ItalicText(text.strip())], params)
|
||||||
result.append(link)
|
result.append(link)
|
||||||
continue
|
continue
|
||||||
@ -637,7 +650,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 = None
|
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:
|
||||||
@ -649,8 +662,8 @@ def parse_text(line, context=None, parse_links=True):
|
|||||||
else:
|
else:
|
||||||
text, _, remaining = remaining.partition('|')
|
text, _, remaining = remaining.partition('|')
|
||||||
|
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
text = parse_text(text, parse_links=False)
|
text = parse_text(text, parse_links=False)
|
||||||
|
|
||||||
params = None
|
params = None
|
||||||
if remaining:
|
if remaining:
|
||||||
@ -916,6 +929,9 @@ PlainText(' ')])]
|
|||||||
>>> parse_wiki('Back to [[FreedomBox/Manual|manual]] page.')
|
>>> parse_wiki('Back to [[FreedomBox/Manual|manual]] page.')
|
||||||
[Paragraph([PlainText('Back to '), Link('FreedomBox/Manual', \
|
[Paragraph([PlainText('Back to '), Link('FreedomBox/Manual', \
|
||||||
[PlainText('manual')]), PlainText(' page. ')])]
|
[PlainText('manual')]), PlainText(' page. ')])]
|
||||||
|
>>> parse_wiki('[[FreedomBox/Manual]]')
|
||||||
|
[Paragraph([Link('FreedomBox/Manual', [PlainText('FreedomBox/Manual')]), \
|
||||||
|
PlainText(' ')])]
|
||||||
>>> parse_wiki('[[attachment:Searx.webm|Searx installation and first steps\
|
>>> parse_wiki('[[attachment:Searx.webm|Searx installation and first steps\
|
||||||
|&do=get]]')
|
|&do=get]]')
|
||||||
[Paragraph([Link('attachment:Searx.webm', \
|
[Paragraph([Link('attachment:Searx.webm', \
|
||||||
@ -1590,6 +1606,14 @@ Contribute</ulink>'
|
|||||||
'<ulink url="https://lists.alioth.debian.org/mailman/listinfo/freedombox-\
|
'<ulink url="https://lists.alioth.debian.org/mailman/listinfo/freedombox-\
|
||||||
discuss#">Discuss</ulink>'
|
discuss#">Discuss</ulink>'
|
||||||
|
|
||||||
|
>>> generate_inner_docbook([Link('WiFi#USB_Devices', \
|
||||||
|
[PlainText('Devices')])])
|
||||||
|
'<ulink url="https://wiki.debian.org/WiFi#USB_Devices">Devices</ulink>'
|
||||||
|
|
||||||
|
>>> generate_inner_docbook([Link('#internal-link', \
|
||||||
|
[PlainText('Section')])])
|
||||||
|
'<link linkend="internal-link">Section</link>'
|
||||||
|
|
||||||
>>> generate_inner_docbook([Link("attachment:Let's Encrypt.webm", \
|
>>> generate_inner_docbook([Link("attachment:Let's Encrypt.webm", \
|
||||||
[PlainText("Let's Encrypt")], 'do=get')], context={'title': \
|
[PlainText("Let's Encrypt")], 'do=get')], context={'title': \
|
||||||
'FreedomBox/Manual/LetsEncrypt'})
|
'FreedomBox/Manual/LetsEncrypt'})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user