-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfluence2xhtml.xsl
151 lines (143 loc) · 4.15 KB
/
confluence2xhtml.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/"
xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/"
xmlns:acxhtml="http://www.atlassian.com/schema/confluence/4/"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xsl ac ri acxhtml">
<!-- Transform Confluence storage format to XHTML -->
<!-- Identity transform: by default, simply copy all attributes and nodes to output -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- Replace the Confluence page root element with XHTML wrapper -->
<xsl:template match="/*">
<html>
<head>
<title>Confluence page</title>
<style type="text/css">
/* <![CDATA[ */
body {
font-family: sans-serif;
background-color: white;
color: black;
}
/* Content styles */
table
{
border-collapse: collapse;
}
th
{
vertical-align: bottom;
text-align: left;
background-color: #F0F0F0;
}
td
{
vertical-align: top;
}
td, th
{
border: 1px solid #909090;
padding: 0.5em;
}
/* Markup-related styles */
.markup {
color: #A9A9A9;
}
.element-name {
color: #800080;
font-weight: bold;
}
.comment {
color: green;
}
.cdata {
color: #CC0066;
}
.text {
font-family: sans-serif;
color: black;
}
.attribute-name {
color: #800080;
}
.attribute-value {
color: black;
}
div.extension-element {
margin-top: 0.5em;
margin-bottom: 0.5em;
border: 1px solid #DDDDDD;
background-color: #F0F0F0;
}
p.extension-element-markup {
margin-top: 0.2em;
margin-bottom: 0.2em;
padding-left: 0.5em;
padding-right: 0.5em;
}
div.extension-element-contents {
border-top: 1px solid #DDDDDD;
padding: 0.5em;
background-color: #FFFFFF;
}
/* ]]> */
</style>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<!-- Omit the xml-stylesheet PI from the output -->
<xsl:template match="processing-instruction('xml-stylesheet')"/>
<!-- Move XHTML-like elements into XHTML namespace -->
<xsl:template match="acxhtml:*">
<xsl:element name="{local-name(.)}" namespace = "http://www.w3.org/1999/xhtml">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<!-- Represent extension elements as their XML source -->
<xsl:template match="ac:* | ri:*">
<div class="extension-element">
<p class="extension-element-markup">
<span class="element-name">
<xsl:value-of select="name(.)"/>
</span>
<xsl:apply-templates select="@*"/>
</p>
<xsl:if test="node()">
<div class="extension-element-contents">
<xsl:choose>
<xsl:when test="name(.) = 'ac:plain-text-body'">
<pre><xsl:apply-templates select="node()"/></pre>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="node()"/>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:if>
</div>
</xsl:template>
<!-- Represent extension attributes as their XML source -->
<xsl:template match="ac:*/@* | ri:*/@*">
<xsl:text> </xsl:text>
<span class="attribute-name">
<xsl:value-of select="name(.)"/>
</span>
<span class="markup">
<xsl:text>="</xsl:text>
</span>
<span class="attribute-value">
<xsl:value-of select="."/>
</span>
<span class="markup">
<xsl:text>"</xsl:text>
</span>
</xsl:template>
</xsl:stylesheet>