1 <?xml version="1.0" encoding="UTF-8"?>
3 Copyright © 2014 František Kučera (frantovo.cz)
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 <xsl:stylesheet version="2.0"
19 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
20 xmlns:fn="http://www.w3.org/2005/xpath-functions"
21 xmlns:h="http://www.w3.org/1999/xhtml">
22 <xsl:output method="text" encoding="UTF-8"/>
23 <xsl:strip-space elements="*"/>
25 <xsl:output method="text" encoding="UTF-8"/>
26 <xsl:strip-space elements="*"/>
28 <xsl:variable name="urlBase" select="/h:html/h:head/h:base/@href"/>
31 <!-- Celý dokument -->
32 <xsl:template match="/">
33 <xsl:apply-templates select="h:html/h:body"/>
37 <xsl:template match="h:h1">
38 <xsl:value-of select="text()"/>
39 <xsl:text> </xsl:text>
40 <xsl:for-each select="1 to string-length(.)">=</xsl:for-each>
41 <xsl:text> </xsl:text>
42 <xsl:text> </xsl:text>
46 <xsl:template match="h:h2">
47 <xsl:value-of select="text()"/>
48 <xsl:text> </xsl:text>
49 <xsl:for-each select="1 to string-length(.)">-</xsl:for-each>
50 <xsl:text> </xsl:text>
51 <xsl:text> </xsl:text>
55 <xsl:template match="h:h3">
56 <xsl:for-each select="1 to 3">#</xsl:for-each>
57 <xsl:text> </xsl:text>
58 <xsl:value-of select="text()"/>
59 <xsl:text> </xsl:text>
60 <xsl:text> </xsl:text>
64 <xsl:template match="h:h4">
65 <xsl:for-each select="1 to 4">#</xsl:for-each>
66 <xsl:text> </xsl:text>
67 <xsl:value-of select="text()"/>
68 <xsl:text> </xsl:text>
69 <xsl:text> </xsl:text>
73 <xsl:template match="h:h5">
74 <xsl:for-each select="1 to 5">#</xsl:for-each>
75 <xsl:text> </xsl:text>
76 <xsl:value-of select="text()"/>
77 <xsl:text> </xsl:text>
78 <xsl:text> </xsl:text>
82 <xsl:template match="h:h6">
83 <xsl:for-each select="1 to 6">#</xsl:for-each>
84 <xsl:text> </xsl:text>
85 <xsl:value-of select="text()"/>
86 <xsl:text> </xsl:text>
87 <xsl:text> </xsl:text>
91 <xsl:template match="h:p">
92 <xsl:apply-templates/>
93 <xsl:text> </xsl:text>
94 <xsl:text> </xsl:text>
99 TODO: převzít odsazování z hellDesku?
101 <xsl:template match="h:blockquote/h:p">
102 <xsl:text>> </xsl:text>
103 <xsl:apply-templates/>
104 <xsl:text> </xsl:text>
105 <xsl:text> </xsl:text>
109 <xsl:template match="h:cite[not(matches(., '^("|„)'))]">
110 <xsl:text>„</xsl:text>
111 <xsl:apply-templates/>
112 <xsl:text>“</xsl:text>
116 <xsl:template match="h:a">
117 <xsl:if test="not(text() = @href)">
118 <xsl:text>'</xsl:text>
119 <xsl:apply-templates select="node()"/>
120 <xsl:text>' </xsl:text>
122 <xsl:text><</xsl:text>
124 <xsl:when test="matches(@href, '^(http:|https:|ftp:)')">
125 <xsl:value-of select="@href"/>
127 <xsl:when test="matches(@href, '^mailto:')">
128 <xsl:value-of select="substring-after(@href, 'mailto:')"/>
132 <xsl:when test="ends-with($urlBase, '/') or starts-with(@href, '/')">
133 <xsl:value-of select="concat($urlBase, @href)"/>
136 <xsl:value-of select="concat($urlBase, '/', @href)"/>
141 <xsl:text>></xsl:text>
142 <xsl:if test="@title and not(matches(@title, '^\s*$'))">
143 <xsl:text> (</xsl:text>
144 <xsl:value-of select="@title"/>
145 <xsl:text>)</xsl:text>
150 <xsl:template match="h:img">
151 <xsl:variable name="obrázek">
152 <h:a href="{@src}" title="{@title}">Obrázek: <xsl:value-of select="@alt"/></h:a>
154 <xsl:apply-templates select="$obrázek/node()"/>
158 <xsl:template match="h:strong|h:b">
159 <xsl:text>**</xsl:text>
160 <xsl:apply-templates/>
161 <xsl:text>**</xsl:text>
165 <xsl:template match="h:em|h:i">
166 <xsl:text>*</xsl:text>
167 <xsl:apply-templates/>
168 <xsl:text>*</xsl:text>
172 <xsl:template match="h:abbr[@title]">
173 <xsl:apply-templates/>
174 <xsl:text> (</xsl:text>
175 <xsl:value-of select="@title"/>
176 <xsl:text>)</xsl:text>
181 TODO: převzít odsazování z hellDesku?
183 <xsl:template match="h:pre">
184 <xsl:text>--------------------------------</xsl:text>
185 <xsl:text> </xsl:text>
186 <xsl:apply-templates/>
187 <xsl:text> </xsl:text>
188 <xsl:text>--------------------------------</xsl:text>
189 <xsl:text> </xsl:text>
190 <xsl:text> </xsl:text>
194 <xsl:template match="h:code">
195 <xsl:text>`</xsl:text>
196 <xsl:apply-templates/>
197 <xsl:text>`</xsl:text>
201 <xsl:template match="h:hr">
202 <xsl:text>----------------------------------------------------------------</xsl:text>
203 <xsl:text> </xsl:text>
204 <xsl:text> </xsl:text>
208 <xsl:template match="h:br">
209 <xsl:text> </xsl:text>
213 <xsl:template match="h:ol|h:ul">
214 <xsl:variable name="úroveň" select="count(ancestor::h:li)"/>
215 <xsl:variable name="odsazení">
216 <!-- položky na nejvyšší úrovni odsazené jednou mezerou -->
217 <xsl:value-of select="' '"/>
218 <xsl:for-each select="2 to $úroveň+1">
219 <!-- položky na druhé a vyšší úrovni odsazené vždy dvěma dalšími mezerami -->
220 <xsl:value-of select="' '"/>
224 <xsl:if test="$úroveň gt 0">
225 <xsl:text> </xsl:text>
228 <xsl:for-each select="h:li">
229 <xsl:if test="parent::h:ol"><xsl:value-of select="concat($odsazení, position(), ') ')"/></xsl:if>
230 <xsl:if test="parent::h:ul"><xsl:value-of select="concat($odsazení, '- ')"/></xsl:if>
231 <xsl:apply-templates/>
232 <xsl:if test="$úroveň = 0 or not(position() = last())">
233 <xsl:text> </xsl:text>
237 <xsl:if test="$úroveň = 0">
238 <xsl:text> </xsl:text>
243 <xsl:template match="text()[not(parent::h:pre)]">
244 <xsl:if test="matches(., '^\s') and preceding-sibling::node() and not(preceding-sibling::h:br)">
245 <xsl:text> </xsl:text>
247 <xsl:value-of select="normalize-space(.)"/>
248 <xsl:if test="matches(., '\s$') and following-sibling::node()">
249 <xsl:text> </xsl:text>
254 <xsl:template match="h:div[@class='wwwLinks']">
256 Dvě pomlčky a mezeru budou e-maliloví klienti považovat za začátek podpisu
257 a zobrazí ho šedivým písmem a nebudou ho citovat v odpovědích.
259 <xsl:text>-- </xsl:text>
260 <xsl:text> </xsl:text>
261 <xsl:apply-templates/>