Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
cloudooo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
cloudooo
Commits
e86de962
Commit
e86de962
authored
Jun 10, 2016
by
Tristan Cavelier
Committed by
Cédric Le Ninivin
Jun 27, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wkhtmltopdf: add table of content test
parent
237907b1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
0 deletions
+112
-0
cloudooo/handler/wkhtmltopdf/tests/data/test_toc.xsl
cloudooo/handler/wkhtmltopdf/tests/data/test_toc.xsl
+82
-0
cloudooo/handler/wkhtmltopdf/tests/data/test_with_toc.html
cloudooo/handler/wkhtmltopdf/tests/data/test_with_toc.html
+15
-0
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
+15
-0
No files found.
cloudooo/handler/wkhtmltopdf/tests/data/test_toc.xsl
0 → 100644
View file @
e86de962
<?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>
cloudooo/handler/wkhtmltopdf/tests/data/test_with_toc.html
0 → 100644
View file @
e86de962
<!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>
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
View file @
e86de962
...
...
@@ -25,6 +25,7 @@
#
##############################################################################
from
base64
import
b64encode
import
magic
from
cloudooo.handler.wkhtmltopdf.handler
import
Handler
...
...
@@ -56,6 +57,20 @@ class TestHandler(HandlerTestCase):
# 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
):
""" Test if metadata are inserted correclty """
handler
=
Handler
(
self
.
tmp_url
,
""
,
"png"
,
**
self
.
kw
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment