mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
doc: wikiparser: Fix attachment URLs in regular links
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
40f853278b
commit
4ef2244af4
@ -89,19 +89,4 @@
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Fix incorrectly output wiki links -->
|
||||
<xsl:template match="@url[parent::ulink]">
|
||||
<xsl:attribute name="url">
|
||||
<xsl:choose>
|
||||
<xsl:when test="contains(., 'FreedomBox/Manual/')">
|
||||
<xsl:value-of select="substring-before(., 'FreedomBox/Manual/')"/>
|
||||
<xsl:value-of select="substring-after(., 'FreedomBox/Manual/')"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="."/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:attribute>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
||||
|
||||
@ -5,6 +5,7 @@ MoinMoin wiki parser
|
||||
|
||||
import logging
|
||||
import re
|
||||
import urllib
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from xml.sax.saxutils import escape
|
||||
@ -189,6 +190,14 @@ class Link(Element):
|
||||
|
||||
def to_docbook(self, context=None):
|
||||
target = escape(self.target)
|
||||
if target.startswith('attachment:'):
|
||||
target = target.lstrip('attachment:')
|
||||
page_title = context.get('title', None) if context else None
|
||||
if page_title:
|
||||
target = f'https://wiki.debian.org/{page_title}' \
|
||||
+ '?action=AttachFile&do=get&' + \
|
||||
urllib.parse.urlencode({'target': target})
|
||||
|
||||
if target.startswith('FreedomBox/') or \
|
||||
target.startswith('InstallingDebianOn/'):
|
||||
target = 'https://wiki.debian.org/' + target + '#'
|
||||
@ -1464,6 +1473,13 @@ PlainText('normal text followed by'), BoldText('bold text')])])
|
||||
'<ulink url="https://wiki.debian.org/FreedomBox/Features#">\
|
||||
Features introduction</ulink>'
|
||||
|
||||
>>> generate_inner_docbook([Link("attachment:Let's Encrypt.webm", \
|
||||
[PlainText("Let's Encrypt")], 'do=get')], context={'title': \
|
||||
'FreedomBox/Manual/LetsEncrypt'})
|
||||
'<ulink url="https://wiki.debian.org/FreedomBox/Manual/LetsEncrypt\
|
||||
?action=AttachFile&do=get&target=Let%27s+Encrypt.webm">\
|
||||
Let\\'s Encrypt</ulink>'
|
||||
|
||||
>>> generate_inner_docbook([EmbeddedAttachment('cockpit-enable.png')])
|
||||
'<inlinemediaobject><imageobject>\
|
||||
<imagedata fileref="cockpit-enable.png"/></imageobject>\
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user