helpers/mimeTextPart.xsl
author František Kučera <franta-hg@frantovo.cz>
Wed, 31 Dec 2014 12:07:40 +0100
changeset 120 bb1c8a7b774c
parent 110 c81406884e16
permissions -rw-r--r--
XSLT: licence – GNU GPLv3
franta-hg@89
     1
<?xml version="1.0" encoding="UTF-8"?>
franta-hg@120
     2
<!--
franta-hg@120
     3
Copyright © 2014 František Kučera (frantovo.cz)
franta-hg@120
     4
franta-hg@120
     5
This program is free software: you can redistribute it and/or modify
franta-hg@120
     6
it under the terms of the GNU General Public License as published by
franta-hg@120
     7
the Free Software Foundation, either version 3 of the License, or
franta-hg@120
     8
(at your option) any later version.
franta-hg@120
     9
franta-hg@120
    10
This program is distributed in the hope that it will be useful,
franta-hg@120
    11
but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@120
    12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
franta-hg@120
    13
GNU General Public License for more details.
franta-hg@120
    14
franta-hg@120
    15
You should have received a copy of the GNU General Public License
franta-hg@120
    16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
franta-hg@120
    17
-->
franta-hg@89
    18
<xsl:stylesheet version="2.0"
franta-hg@89
    19
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
franta-hg@89
    20
	xmlns:fn="http://www.w3.org/2005/xpath-functions"
franta-hg@89
    21
	xmlns:h="http://www.w3.org/1999/xhtml">
franta-hg@89
    22
	<xsl:output method="text" encoding="UTF-8"/>
franta-hg@89
    23
	<xsl:strip-space elements="*"/>
franta-hg@89
    24
	
franta-hg@89
    25
	<xsl:output method="text" encoding="UTF-8"/>
franta-hg@89
    26
	<xsl:strip-space elements="*"/>
franta-hg@89
    27
	
franta-hg@89
    28
	<xsl:variable name="urlBase" select="/h:html/h:head/h:base/@href"/>
franta-hg@91
    29
franta-hg@89
    30
	
franta-hg@89
    31
	<!-- Celý dokument -->
franta-hg@89
    32
	<xsl:template match="/">
franta-hg@89
    33
		<xsl:apply-templates select="h:html/h:body"/>
franta-hg@89
    34
	</xsl:template>
franta-hg@89
    35
franta-hg@91
    36
franta-hg@89
    37
	<xsl:template match="h:h1">
franta-hg@89
    38
		<xsl:value-of select="text()"/>
franta-hg@89
    39
		<xsl:text>&#10;</xsl:text>
franta-hg@92
    40
		<xsl:for-each select="1 to string-length(.)">=</xsl:for-each>		
franta-hg@89
    41
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    42
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    43
	</xsl:template>
franta-hg@89
    44
	
franta-hg@91
    45
	
franta-hg@89
    46
	<xsl:template match="h:h2">
franta-hg@89
    47
		<xsl:value-of select="text()"/>
franta-hg@89
    48
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    49
		<xsl:for-each select="1 to string-length(.)">-</xsl:for-each>		
franta-hg@89
    50
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    51
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    52
	</xsl:template>
franta-hg@89
    53
	
franta-hg@91
    54
	
franta-hg@89
    55
	<xsl:template match="h:h3">
franta-hg@89
    56
		<xsl:for-each select="1 to 3">#</xsl:for-each>
franta-hg@89
    57
		<xsl:text> </xsl:text>
franta-hg@89
    58
		<xsl:value-of select="text()"/>
franta-hg@89
    59
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    60
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    61
	</xsl:template>
franta-hg@91
    62
	
franta-hg@89
    63
	
franta-hg@89
    64
	<xsl:template match="h:h4">
franta-hg@89
    65
		<xsl:for-each select="1 to 4">#</xsl:for-each>
franta-hg@89
    66
		<xsl:text> </xsl:text>
franta-hg@89
    67
		<xsl:value-of select="text()"/>
franta-hg@89
    68
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    69
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    70
	</xsl:template>
franta-hg@91
    71
	
franta-hg@89
    72
	
franta-hg@89
    73
	<xsl:template match="h:h5">
franta-hg@89
    74
		<xsl:for-each select="1 to 5">#</xsl:for-each>
franta-hg@89
    75
		<xsl:text> </xsl:text>
franta-hg@89
    76
		<xsl:value-of select="text()"/>
franta-hg@89
    77
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    78
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    79
	</xsl:template>
franta-hg@89
    80
	
franta-hg@91
    81
	
franta-hg@89
    82
	<xsl:template match="h:h6">
franta-hg@89
    83
		<xsl:for-each select="1 to 6">#</xsl:for-each>
franta-hg@89
    84
		<xsl:text> </xsl:text>
franta-hg@89
    85
		<xsl:value-of select="text()"/>
franta-hg@89
    86
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    87
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    88
	</xsl:template>
franta-hg@89
    89
franta-hg@89
    90
franta-hg@89
    91
	<xsl:template match="h:p">
franta-hg@89
    92
		<xsl:apply-templates/>
franta-hg@89
    93
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    94
		<xsl:text>&#10;</xsl:text>
franta-hg@89
    95
	</xsl:template>
franta-hg@91
    96
franta-hg@89
    97
	
franta-hg@120
    98
	<!--
franta-hg@120
    99
		TODO: převzít odsazování z hellDesku?
franta-hg@120
   100
	-->
franta-hg@90
   101
	<xsl:template match="h:blockquote/h:p">
franta-hg@90
   102
		<xsl:text>&gt; </xsl:text>
franta-hg@90
   103
		<xsl:apply-templates/>
franta-hg@90
   104
		<xsl:text>&#10;</xsl:text>
franta-hg@90
   105
		<xsl:text>&#10;</xsl:text>
franta-hg@90
   106
	</xsl:template>
franta-hg@92
   107
franta-hg@97
   108
	
franta-hg@92
   109
	<xsl:template match="h:cite[not(matches(., '^(&quot;|„)'))]">
franta-hg@92
   110
		<xsl:text>„</xsl:text>
franta-hg@92
   111
		<xsl:apply-templates/>
franta-hg@92
   112
		<xsl:text>“</xsl:text>
franta-hg@92
   113
	</xsl:template>	
franta-hg@91
   114
	
franta-hg@97
   115
	
franta-hg@89
   116
	<xsl:template match="h:a">
franta-hg@120
   117
		<xsl:if test="not(text() = @href)">
franta-hg@120
   118
			<xsl:text>'</xsl:text>
franta-hg@120
   119
			<xsl:apply-templates select="node()"/>
franta-hg@120
   120
			<xsl:text>' </xsl:text>
franta-hg@120
   121
		</xsl:if>
franta-hg@120
   122
		<xsl:text>&lt;</xsl:text>
franta-hg@89
   123
		<xsl:choose>
franta-hg@89
   124
			<xsl:when test="matches(@href, '^(http:|https:|ftp:)')">
franta-hg@89
   125
				<xsl:value-of select="@href"/>
franta-hg@89
   126
			</xsl:when>
franta-hg@89
   127
			<xsl:when test="matches(@href, '^mailto:')">
franta-hg@89
   128
				<xsl:value-of select="substring-after(@href, 'mailto:')"/>
franta-hg@89
   129
			</xsl:when>
franta-hg@89
   130
			<xsl:otherwise>
franta-hg@89
   131
				<xsl:choose>
franta-hg@89
   132
					<xsl:when test="ends-with($urlBase, '/') or starts-with(@href, '/')">
franta-hg@89
   133
						<xsl:value-of select="concat($urlBase, @href)"/>
franta-hg@89
   134
					</xsl:when>
franta-hg@89
   135
					<xsl:otherwise>
franta-hg@89
   136
						<xsl:value-of select="concat($urlBase, '/', @href)"/>
franta-hg@89
   137
					</xsl:otherwise>
franta-hg@89
   138
				</xsl:choose>
franta-hg@89
   139
			</xsl:otherwise>
franta-hg@89
   140
		</xsl:choose>	
franta-hg@89
   141
		<xsl:text>&gt;</xsl:text>
franta-hg@89
   142
		<xsl:if test="@title and not(matches(@title, '^\s*$'))">
franta-hg@89
   143
			<xsl:text> (</xsl:text>
franta-hg@89
   144
			<xsl:value-of select="@title"/>
franta-hg@89
   145
			<xsl:text>)</xsl:text>
franta-hg@89
   146
		</xsl:if>
franta-hg@89
   147
	</xsl:template>
franta-hg@89
   148
	
franta-hg@91
   149
	
franta-hg@89
   150
	<xsl:template match="h:img">
franta-hg@89
   151
		<xsl:variable name="obrázek">
franta-hg@89
   152
			<h:a href="{@src}" title="{@title}">Obrázek: <xsl:value-of select="@alt"/></h:a>
franta-hg@89
   153
		</xsl:variable>
franta-hg@89
   154
		<xsl:apply-templates select="$obrázek/node()"/>
franta-hg@89
   155
	</xsl:template>
franta-hg@89
   156
	
franta-hg@91
   157
	
franta-hg@89
   158
	<xsl:template match="h:strong|h:b">
franta-hg@89
   159
		<xsl:text>**</xsl:text>
franta-hg@89
   160
		<xsl:apply-templates/>
franta-hg@89
   161
		<xsl:text>**</xsl:text>
franta-hg@89
   162
	</xsl:template>
franta-hg@89
   163
	
franta-hg@91
   164
	
franta-hg@89
   165
	<xsl:template match="h:em|h:i">
franta-hg@89
   166
		<xsl:text>*</xsl:text>
franta-hg@89
   167
		<xsl:apply-templates/>
franta-hg@89
   168
		<xsl:text>*</xsl:text>
franta-hg@89
   169
	</xsl:template>
franta-hg@89
   170
	
franta-hg@91
   171
	
franta-hg@89
   172
	<xsl:template match="h:abbr[@title]">
franta-hg@89
   173
		<xsl:apply-templates/>
franta-hg@89
   174
		<xsl:text> (</xsl:text>
franta-hg@89
   175
		<xsl:value-of select="@title"/>
franta-hg@89
   176
		<xsl:text>)</xsl:text>
franta-hg@89
   177
	</xsl:template>
franta-hg@89
   178
	
franta-hg@91
   179
	
franta-hg@120
   180
	<!--
franta-hg@120
   181
		TODO: převzít odsazování z hellDesku?
franta-hg@120
   182
	-->
franta-hg@89
   183
	<xsl:template match="h:pre">
franta-hg@89
   184
		<xsl:text>--------------------------------</xsl:text>
franta-hg@89
   185
		<xsl:text>&#10;</xsl:text>
franta-hg@89
   186
		<xsl:apply-templates/>
franta-hg@89
   187
		<xsl:text>&#10;</xsl:text>
franta-hg@89
   188
		<xsl:text>--------------------------------</xsl:text>
franta-hg@89
   189
		<xsl:text>&#10;</xsl:text>
franta-hg@89
   190
		<xsl:text>&#10;</xsl:text>
franta-hg@89
   191
	</xsl:template>
franta-hg@89
   192
	
franta-hg@91
   193
	
franta-hg@89
   194
	<xsl:template match="h:code">
franta-hg@89
   195
		<xsl:text>`</xsl:text>
franta-hg@89
   196
		<xsl:apply-templates/>
franta-hg@89
   197
		<xsl:text>`</xsl:text>
franta-hg@89
   198
	</xsl:template>
franta-hg@89
   199
	
franta-hg@91
   200
	
franta-hg@89
   201
	<xsl:template match="h:hr">
franta-hg@89
   202
		<xsl:text>----------------------------------------------------------------</xsl:text>
franta-hg@89
   203
		<xsl:text>&#10;</xsl:text>
franta-hg@89
   204
		<xsl:text>&#10;</xsl:text>
franta-hg@89
   205
	</xsl:template>
franta-hg@89
   206
	
franta-hg@91
   207
	
franta-hg@110
   208
	<xsl:template match="h:br">
franta-hg@110
   209
		<xsl:text>&#10;</xsl:text>
franta-hg@110
   210
	</xsl:template>	
franta-hg@110
   211
franta-hg@110
   212
franta-hg@96
   213
	<xsl:template match="h:ol|h:ul">
franta-hg@95
   214
		<xsl:variable name="úroveň" select="count(ancestor::h:li)"/>
franta-hg@95
   215
		<xsl:variable name="odsazení">
franta-hg@96
   216
			<!-- položky na nejvyšší úrovni odsazené jednou mezerou -->
franta-hg@96
   217
			<xsl:value-of select="' '"/>
franta-hg@96
   218
			<xsl:for-each select="2 to $úroveň+1">
franta-hg@96
   219
				<!-- položky na druhé a vyšší úrovni odsazené vždy dvěma dalšími mezerami -->
franta-hg@95
   220
				<xsl:value-of select="'  '"/>
franta-hg@95
   221
			</xsl:for-each>
franta-hg@95
   222
		</xsl:variable>
franta-hg@95
   223
		
franta-hg@95
   224
		<xsl:if test="$úroveň gt 0">
franta-hg@95
   225
			<xsl:text>&#10;</xsl:text>
franta-hg@95
   226
		</xsl:if>
franta-hg@95
   227
		
franta-hg@89
   228
		<xsl:for-each select="h:li">
franta-hg@96
   229
			<xsl:if test="parent::h:ol"><xsl:value-of select="concat($odsazení, position(), ') ')"/></xsl:if>
franta-hg@96
   230
			<xsl:if test="parent::h:ul"><xsl:value-of select="concat($odsazení, '- ')"/></xsl:if>
franta-hg@89
   231
			<xsl:apply-templates/>
franta-hg@96
   232
			<xsl:if test="$úroveň = 0 or not(position() = last())">
franta-hg@96
   233
				<xsl:text>&#10;</xsl:text>
franta-hg@96
   234
			</xsl:if>
franta-hg@120
   235
		</xsl:for-each>
franta-hg@96
   236
		
franta-hg@96
   237
		<xsl:if test="$úroveň = 0">
franta-hg@89
   238
			<xsl:text>&#10;</xsl:text>
franta-hg@96
   239
		</xsl:if>
franta-hg@89
   240
	</xsl:template>
franta-hg@89
   241
	
franta-hg@89
   242
	
franta-hg@89
   243
	<xsl:template match="text()[not(parent::h:pre)]">
franta-hg@120
   244
		<xsl:if test="matches(., '^\s') and preceding-sibling::node() and not(preceding-sibling::h:br)">
franta-hg@89
   245
			<xsl:text> </xsl:text>
franta-hg@89
   246
		</xsl:if>
franta-hg@89
   247
		<xsl:value-of select="normalize-space(.)"/>
franta-hg@99
   248
		<xsl:if test="matches(., '\s$') and following-sibling::node()">
franta-hg@89
   249
			<xsl:text> </xsl:text>
franta-hg@89
   250
		</xsl:if>
franta-hg@89
   251
	</xsl:template>
franta-hg@89
   252
franta-hg@89
   253
	
franta-hg@89
   254
	<xsl:template match="h:div[@class='wwwLinks']">
franta-hg@91
   255
		<!-- 
franta-hg@91
   256
			Dvě pomlčky a mezeru budou e-maliloví klienti považovat za začátek podpisu
franta-hg@91
   257
			a zobrazí ho šedivým písmem a nebudou ho citovat v odpovědích.
franta-hg@91
   258
		-->
franta-hg@89
   259
		<xsl:text>-- </xsl:text>
franta-hg@89
   260
		<xsl:text>&#10;</xsl:text>
franta-hg@89
   261
		<xsl:apply-templates/>	
franta-hg@89
   262
	</xsl:template>	
franta-hg@89
   263
franta-hg@89
   264
franta-hg@89
   265
</xsl:stylesheet>