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:
Sunil Mohan Adapa 2020-08-24 10:10:58 -07:00 committed by James Valleroy
parent 40f853278b
commit 4ef2244af4
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 16 additions and 15 deletions

View File

@ -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>

View File

@ -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&amp;do=get&amp;' + \
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&amp;do=get&amp;target=Let%27s+Encrypt.webm">\
Let\\'s Encrypt</ulink>'
>>> generate_inner_docbook([EmbeddedAttachment('cockpit-enable.png')])
'<inlinemediaobject><imageobject>\
<imagedata fileref="cockpit-enable.png"/></imageobject>\