mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
doc: wikiparser: Incorporate post processing fixes
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
09dd1e89e4
commit
7c7f71224f
@ -113,15 +113,15 @@ $(manual-pages-part-html): %.part.html: %.html
|
|||||||
$(manual-raw-xmls): %.raw.xml: %.raw.wiki $(SCRIPTS_DIR)/wikiparser.py
|
$(manual-raw-xmls): %.raw.xml: %.raw.wiki $(SCRIPTS_DIR)/wikiparser.py
|
||||||
python3 $(SCRIPTS_DIR)/wikiparser.py $< > $@
|
python3 $(SCRIPTS_DIR)/wikiparser.py $< > $@
|
||||||
|
|
||||||
$(manual-xmls): %.xml: %.raw.xml $(SCRIPTS_DIR)/fixes.xslt
|
$(manual-xmls): %.xml: %.raw.xml
|
||||||
xsltproc --output $@ $(SCRIPTS_DIR)/fixes.xslt $<
|
xmllint --format $< > $@
|
||||||
|
|
||||||
$(manual-pages-raw-xml): %.raw.xml: %.raw.wiki $(SCRIPTS_DIR)/wikiparser.py
|
$(manual-pages-raw-xml): %.raw.xml: %.raw.wiki $(SCRIPTS_DIR)/wikiparser.py
|
||||||
python3 $(SCRIPTS_DIR)/wikiparser.py --begin-marker="## BEGIN_INCLUDE" \
|
python3 $(SCRIPTS_DIR)/wikiparser.py --begin-marker="## BEGIN_INCLUDE" \
|
||||||
--end-marker='## END_INCLUDE' $< > $@
|
--end-marker='## END_INCLUDE' $< > $@
|
||||||
|
|
||||||
$(manual-pages-xml): %.xml: %.raw.xml $(SCRIPTS_DIR)/manual-page-fixes.xslt
|
$(manual-pages-xml): %.xml: %.raw.xml
|
||||||
xsltproc --output $@ $(SCRIPTS_DIR)/manual-page-fixes.xslt $<
|
xmllint --format $< > $@
|
||||||
|
|
||||||
$(manual-pages-html): %.html: %.xml
|
$(manual-pages-html): %.html: %.xml
|
||||||
xsltproc --output $@ /usr/share/xml/docbook/stylesheet/docbook-xsl/xhtml5/docbook.xsl $<
|
xsltproc --output $@ /usr/share/xml/docbook/stylesheet/docbook-xsl/xhtml5/docbook.xsl $<
|
||||||
|
|||||||
@ -1,92 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
-->
|
|
||||||
<xsl:stylesheet version="1.0"
|
|
||||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
||||||
|
|
||||||
<!-- Set output format to Docbook -->
|
|
||||||
<xsl:output
|
|
||||||
method="xml"
|
|
||||||
encoding="utf-8"
|
|
||||||
indent="yes"
|
|
||||||
doctype-public="-//OASIS//DTD DocBook XML V4.4//EN"
|
|
||||||
doctype-system="http://www.docbook.org/xml/4.4/docbookx.dtd"/>
|
|
||||||
|
|
||||||
<!-- Copy all nodes and attributes by default -->
|
|
||||||
<xsl:template match="@*|node()">
|
|
||||||
<xsl:copy>
|
|
||||||
<xsl:apply-templates select="@*|node()"/>
|
|
||||||
</xsl:copy>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- Replace / in title with a space -->
|
|
||||||
<xsl:template match="articleinfo/title/text()">
|
|
||||||
<xsl:call-template name="clean-title">
|
|
||||||
<xsl:with-param name="title" select="."/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<xsl:template name="clean-title">
|
|
||||||
<xsl:param name="title"/>
|
|
||||||
<xsl:choose>
|
|
||||||
<xsl:when test="contains($title, '/')">
|
|
||||||
<!-- Skip copying the language code -->
|
|
||||||
<xsl:choose>
|
|
||||||
<xsl:when test="not(string-length(substring-before($title, '/'))=2)
|
|
||||||
and
|
|
||||||
not(string-length(substring-before($title, '/'))=5 and contains(substring-before($title, '/'), '-'))">
|
|
||||||
<xsl:value-of select="substring-before($title, '/')"/>
|
|
||||||
<xsl:text> </xsl:text>
|
|
||||||
</xsl:when>
|
|
||||||
</xsl:choose>
|
|
||||||
<xsl:call-template name="clean-title">
|
|
||||||
<xsl:with-param name="title" select="substring-after($title, '/')"/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:otherwise>
|
|
||||||
<xsl:value-of select="$title"/>
|
|
||||||
</xsl:otherwise>
|
|
||||||
</xsl:choose>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- Remove revision history -->
|
|
||||||
<xsl:template match="revhistory"/>
|
|
||||||
|
|
||||||
<!-- Convert all image dimensions from pixels to points -->
|
|
||||||
<xsl:template match="@width[parent::imagedata]|@depth[parent::imagedata]">
|
|
||||||
<xsl:attribute name="{name()}">
|
|
||||||
<xsl:value-of select=". div 2"/>
|
|
||||||
<xsl:text>pt</xsl:text>
|
|
||||||
</xsl:attribute>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- Convert all image source URLs to relative paths -->
|
|
||||||
<xsl:template match="@fileref[parent::imagedata]">
|
|
||||||
<xsl:attribute name="fileref">
|
|
||||||
<xsl:text>images/</xsl:text>
|
|
||||||
<xsl:call-template name="filename">
|
|
||||||
<xsl:with-param name="path" select="."/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:attribute>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- Output just the filename from a URL -->
|
|
||||||
<xsl:template name="filename">
|
|
||||||
<xsl:param name="path"/>
|
|
||||||
<xsl:choose>
|
|
||||||
<xsl:when test="contains($path, 'target=')">
|
|
||||||
<xsl:value-of select="substring-after($path, 'target=')"/>
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:when test="not(contains($path, '/'))">
|
|
||||||
<xsl:value-of select="$path"/>
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:otherwise>
|
|
||||||
<xsl:call-template name="filename">
|
|
||||||
<xsl:with-param name="path" select="substring-after($path, '/')"/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:otherwise>
|
|
||||||
</xsl:choose>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
</xsl:stylesheet>
|
|
||||||
@ -1,84 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
-->
|
|
||||||
<xsl:stylesheet version="1.0"
|
|
||||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
||||||
|
|
||||||
<!-- Set output format to Docbook -->
|
|
||||||
<xsl:output
|
|
||||||
method="xml"
|
|
||||||
encoding="utf-8"
|
|
||||||
indent="yes"
|
|
||||||
doctype-public="-//OASIS//DTD DocBook XML V4.4//EN"
|
|
||||||
doctype-system="http://www.docbook.org/xml/4.4/docbookx.dtd"/>
|
|
||||||
|
|
||||||
<!-- Copy all nodes and attributes by default -->
|
|
||||||
<xsl:template match="@*|node()">
|
|
||||||
<xsl:copy>
|
|
||||||
<xsl:apply-templates select="@*|node()"/>
|
|
||||||
</xsl:copy>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- Split and get the last word in the title -->
|
|
||||||
<xsl:template match="articleinfo/title/text()">
|
|
||||||
<xsl:call-template name="clean-title">
|
|
||||||
<xsl:with-param name="title" select="."/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<xsl:template name="clean-title">
|
|
||||||
<xsl:param name="title"/>
|
|
||||||
<xsl:choose>
|
|
||||||
<xsl:when test="contains($title, '/')">
|
|
||||||
<xsl:text></xsl:text>
|
|
||||||
<xsl:call-template name="clean-title">
|
|
||||||
<xsl:with-param name="title" select="substring-after($title, '/')"/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:otherwise>
|
|
||||||
<xsl:value-of select="$title"/>
|
|
||||||
</xsl:otherwise>
|
|
||||||
</xsl:choose>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- Remove revision history -->
|
|
||||||
<xsl:template match="revhistory"/>
|
|
||||||
|
|
||||||
<!-- Convert all image dimensions from pixels to points -->
|
|
||||||
<xsl:template match="@width[parent::imagedata]|@depth[parent::imagedata]">
|
|
||||||
<xsl:attribute name="{name()}">
|
|
||||||
<xsl:value-of select=". div 2"/>
|
|
||||||
<xsl:text>pt</xsl:text>
|
|
||||||
</xsl:attribute>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- Convert all image source URLs to relative paths -->
|
|
||||||
<xsl:template match="@fileref[parent::imagedata]">
|
|
||||||
<xsl:attribute name="fileref">
|
|
||||||
<xsl:text>images/</xsl:text>
|
|
||||||
<xsl:call-template name="filename">
|
|
||||||
<xsl:with-param name="path" select="."/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:attribute>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
<!-- Output just the filename from a URL -->
|
|
||||||
<xsl:template name="filename">
|
|
||||||
<xsl:param name="path"/>
|
|
||||||
<xsl:choose>
|
|
||||||
<xsl:when test="contains($path, 'target=')">
|
|
||||||
<xsl:value-of select="substring-after($path, 'target=')"/>
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:when test="not(contains($path, '/'))">
|
|
||||||
<xsl:value-of select="$path"/>
|
|
||||||
</xsl:when>
|
|
||||||
<xsl:otherwise>
|
|
||||||
<xsl:call-template name="filename">
|
|
||||||
<xsl:with-param name="path" select="substring-after($path, '/')"/>
|
|
||||||
</xsl:call-template>
|
|
||||||
</xsl:otherwise>
|
|
||||||
</xsl:choose>
|
|
||||||
</xsl:template>
|
|
||||||
|
|
||||||
</xsl:stylesheet>
|
|
||||||
@ -227,7 +227,7 @@ class EmbeddedAttachment(EmbeddedLink):
|
|||||||
|
|
||||||
xml = '<inlinemediaobject><imageobject>'
|
xml = '<inlinemediaobject><imageobject>'
|
||||||
xml += '<imagedata '
|
xml += '<imagedata '
|
||||||
props = {'fileref': target}
|
props = {'fileref': map_local_files(target)}
|
||||||
if self.params:
|
if self.params:
|
||||||
params = self.params.split(',')
|
params = self.params.split(',')
|
||||||
for param in params:
|
for param in params:
|
||||||
@ -235,7 +235,7 @@ class EmbeddedAttachment(EmbeddedLink):
|
|||||||
if prop == 'height':
|
if prop == 'height':
|
||||||
prop = 'depth'
|
prop = 'depth'
|
||||||
|
|
||||||
props[prop] = value
|
props[prop] = convert_image_units(value)
|
||||||
|
|
||||||
props = [f'{prop}="{value}"' for prop, value in sorted(props.items())]
|
props = [f'{prop}="{value}"' for prop, value in sorted(props.items())]
|
||||||
xml += ' '.join(props)
|
xml += ' '.join(props)
|
||||||
@ -538,6 +538,24 @@ def get_url_text(url):
|
|||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
def convert_image_units(value):
|
||||||
|
"""Covert wiki image units to docbook image units."""
|
||||||
|
value = int(value)
|
||||||
|
value = value / 2.0 if value % 2 else int(value / 2)
|
||||||
|
return str(value) + 'pt'
|
||||||
|
|
||||||
|
|
||||||
|
def map_local_files(path):
|
||||||
|
"""Map files to locally existing paths."""
|
||||||
|
if 'target=' in path:
|
||||||
|
path = path.partition('target=')[2]
|
||||||
|
|
||||||
|
if '/' in path:
|
||||||
|
path = path.rsplit('/', maxsplit=1)[1]
|
||||||
|
|
||||||
|
return f'images/{path}'
|
||||||
|
|
||||||
|
|
||||||
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 \
|
||||||
@ -1673,13 +1691,13 @@ Let\\'s Encrypt</ulink>'
|
|||||||
|
|
||||||
>>> generate_inner_docbook([EmbeddedAttachment('cockpit-enable.png')])
|
>>> generate_inner_docbook([EmbeddedAttachment('cockpit-enable.png')])
|
||||||
'<inlinemediaobject><imageobject>\
|
'<inlinemediaobject><imageobject>\
|
||||||
<imagedata fileref="cockpit-enable.png"/></imageobject>\
|
<imagedata fileref="images/cockpit-enable.png"/></imageobject>\
|
||||||
<textobject><phrase>cockpit-enable.png</phrase></textobject>\
|
<textobject><phrase>cockpit-enable.png</phrase></textobject>\
|
||||||
</inlinemediaobject>'
|
</inlinemediaobject>'
|
||||||
>>> generate_inner_docbook([EmbeddedAttachment('Backups_Step1_v49.png', \
|
>>> generate_inner_docbook([EmbeddedAttachment('Backups_Step1_v49.png', \
|
||||||
[PlainText('Backups: Step 1')], 'width=800')])
|
[PlainText('Backups: Step 1')], 'width=800')])
|
||||||
'<inlinemediaobject><imageobject>\
|
'<inlinemediaobject><imageobject>\
|
||||||
<imagedata fileref="Backups_Step1_v49.png" width="800"/></imageobject>\
|
<imagedata fileref="images/Backups_Step1_v49.png" width="400pt"/></imageobject>\
|
||||||
<textobject><phrase>Backups: Step 1</phrase></textobject>\
|
<textobject><phrase>Backups: Step 1</phrase></textobject>\
|
||||||
</inlinemediaobject>'
|
</inlinemediaobject>'
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user