Commit e86de962 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Cédric Le Ninivin

wkhtmltopdf: add table of content test

parent 237907b1
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:outline="http://wkhtmltopdf.org/outline"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="html" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat"/>
<xsl:template match="outline:outline">
<xsl:param name="count" select="0" />
<html>
<head>
<title>Table of Contents</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
html, body {
overflow-x: initial !important;
}
</style>
</head>
<body>
<p class="ci-document-faux-h1">Table of Contents</p>
<div class="ci-document-table-of-content">
<p class="ci-document-helper"></p>
<ol>
<xsl:apply-templates select="outline:item/outline:item">
<xsl:with-param name="count" select="$count" />
</xsl:apply-templates>
</ol>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="outline:item">
<xsl:param name="count" />
<xsl:choose>
<xsl:when test="number($count)=0">
<li class="ci-document-table-of-content-lead-item">
<xsl:if test="@title!=''">
<div>
<a>
<xsl:if test="@link">
<xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
</xsl:if>
<xsl:if test="@backLink">
<xsl:attribute name="name"><xsl:value-of select="@backLink"/></xsl:attribute>
</xsl:if>
<xsl:value-of select="@title" />
</a>
<span><xsl:value-of select="@page" /> </span>
</div>
</xsl:if>
<ol>
<xsl:comment>added to prevent self-closing tags in QtXmlPatterns</xsl:comment>
<xsl:apply-templates select="outline:item"></xsl:apply-templates>
</ol>
</li>
</xsl:when>
<xsl:otherwise>
<li>
<xsl:if test="@title!=''">
<div>
<a>
<xsl:if test="@link">
<xsl:attribute name="href"><xsl:value-of select="@link"/></xsl:attribute>
</xsl:if>
<xsl:if test="@backLink">
<xsl:attribute name="name"><xsl:value-of select="@backLink"/></xsl:attribute>
</xsl:if>
<xsl:value-of select="@title" />
</a>
<span><xsl:value-of select="@page" /> </span>
</div>
</xsl:if>
<ol>
<xsl:comment>added to prevent self-closing tags in QtXmlPatterns</xsl:comment>
<xsl:apply-templates select="outline:item"></xsl:apply-templates>
</ol>
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Test Title With Table of Content</title>
</head>
<body>
<h1>Title</h1>
<p>Description paragraph</p>
<h2>Sub Title</h2>
<p>Subject paragraph</p>
<h2>Sub Title number 2</h2>
<p>Again subject paragraph</p>
</body>
</html>
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
############################################################################## ##############################################################################
from base64 import b64encode
import magic import magic
from cloudooo.handler.wkhtmltopdf.handler import Handler from cloudooo.handler.wkhtmltopdf.handler import Handler
...@@ -56,6 +57,20 @@ class TestHandler(HandlerTestCase): ...@@ -56,6 +57,20 @@ class TestHandler(HandlerTestCase):
# TODO: def testConvertHtmlWithHeaderAndFooter(self): # TODO: def testConvertHtmlWithHeaderAndFooter(self):
def testConvertHtmlWithTableOfContent(self):
"""Test conversion of html with an additional table of content"""
html_file = open("data/test_with_toc.html").read()
handler = Handler(self.tmp_url, html_file, "html", **self.kw)
pdf_file = handler.convert(
"pdf",
toc=True,
xsl_style_sheet_data=b64encode(open("data/test_toc.xsl").read()),
)
mime = magic.Magic(mime=True)
pdf_mimetype = mime.from_buffer(pdf_file)
self.assertEquals("application/pdf", pdf_mimetype)
# XXX how to check for table of content presence ?
def testsetMetadata(self): def testsetMetadata(self):
""" Test if metadata are inserted correclty """ """ Test if metadata are inserted correclty """
handler = Handler(self.tmp_url, "", "png", **self.kw) handler = Handler(self.tmp_url, "", "png", **self.kw)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment