helpers/mimeTextPart.xsl
author František Kučera <franta-hg@frantovo.cz>
Mon Oct 17 19:50:23 2011 +0200 (2011-10-17)
changeset 91 70286a6cf338
parent 90 2ed2497d4559
child 92 a865136070a0
permissions -rw-r--r--
Drupal: text/plain – podpora obrázků a dalších vnořených elementů uvnitř odkazů.
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <xsl:stylesheet version="2.0"
     3 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     4 	xmlns:fn="http://www.w3.org/2005/xpath-functions"
     5 	xmlns:h="http://www.w3.org/1999/xhtml">
     6 	<xsl:output method="text" encoding="UTF-8"/>
     7 	<xsl:strip-space elements="*"/>
     8 	
     9 	<xsl:output method="text" encoding="UTF-8"/>
    10 	<xsl:strip-space elements="*"/>
    11 	
    12 	<xsl:variable name="urlBase" select="/h:html/h:head/h:base/@href"/>
    13 
    14 	
    15 	<!-- Celý dokument -->
    16 	<xsl:template match="/">
    17 		<xsl:apply-templates select="h:html/h:body"/>
    18 	</xsl:template>
    19 
    20 
    21 	<xsl:template match="h:h1">
    22 		<xsl:value-of select="text()"/>
    23 		<xsl:text>&#10;</xsl:text>
    24 		<xsl:for-each select="1 to string-length(.)">#</xsl:for-each>		
    25 		<xsl:text>&#10;</xsl:text>
    26 		<xsl:text>&#10;</xsl:text>
    27 	</xsl:template>
    28 	
    29 	
    30 	<xsl:template match="h:h2">
    31 		<xsl:value-of select="text()"/>
    32 		<xsl:text>&#10;</xsl:text>
    33 		<xsl:for-each select="1 to string-length(.)">-</xsl:for-each>		
    34 		<xsl:text>&#10;</xsl:text>
    35 		<xsl:text>&#10;</xsl:text>
    36 	</xsl:template>
    37 	
    38 	
    39 	<xsl:template match="h:h3">
    40 		<xsl:for-each select="1 to 3">#</xsl:for-each>
    41 		<xsl:text> </xsl:text>
    42 		<xsl:value-of select="text()"/>
    43 		<xsl:text>&#10;</xsl:text>
    44 		<xsl:text>&#10;</xsl:text>
    45 	</xsl:template>
    46 	
    47 	
    48 	<xsl:template match="h:h4">
    49 		<xsl:for-each select="1 to 4">#</xsl:for-each>
    50 		<xsl:text> </xsl:text>
    51 		<xsl:value-of select="text()"/>
    52 		<xsl:text>&#10;</xsl:text>
    53 		<xsl:text>&#10;</xsl:text>
    54 	</xsl:template>
    55 	
    56 	
    57 	<xsl:template match="h:h5">
    58 		<xsl:for-each select="1 to 5">#</xsl:for-each>
    59 		<xsl:text> </xsl:text>
    60 		<xsl:value-of select="text()"/>
    61 		<xsl:text>&#10;</xsl:text>
    62 		<xsl:text>&#10;</xsl:text>
    63 	</xsl:template>
    64 	
    65 	
    66 	<xsl:template match="h:h6">
    67 		<xsl:for-each select="1 to 6">#</xsl:for-each>
    68 		<xsl:text> </xsl:text>
    69 		<xsl:value-of select="text()"/>
    70 		<xsl:text>&#10;</xsl:text>
    71 		<xsl:text>&#10;</xsl:text>
    72 	</xsl:template>
    73 
    74 
    75 	<xsl:template match="h:p">
    76 		<xsl:apply-templates/>
    77 		<xsl:text>&#10;</xsl:text>
    78 		<xsl:text>&#10;</xsl:text>
    79 	</xsl:template>
    80 
    81 	
    82 	<xsl:template match="h:blockquote/h:p">
    83 		<xsl:text>&gt; </xsl:text>
    84 		<xsl:apply-templates/>
    85 		<xsl:text>&#10;</xsl:text>
    86 		<xsl:text>&#10;</xsl:text>
    87 	</xsl:template>
    88 	
    89 	
    90 	<xsl:template match="h:a">
    91 		<xsl:text>"</xsl:text>
    92 		<xsl:apply-templates select="node()"/>
    93 		<xsl:text>" &lt;</xsl:text>
    94 		<xsl:choose>
    95 			<xsl:when test="matches(@href, '^(http:|https:|ftp:)')">
    96 				<xsl:value-of select="@href"/>
    97 			</xsl:when>
    98 			<xsl:when test="matches(@href, '^mailto:')">
    99 				<xsl:value-of select="substring-after(@href, 'mailto:')"/>
   100 			</xsl:when>
   101 			<xsl:otherwise>
   102 				<xsl:choose>
   103 					<xsl:when test="ends-with($urlBase, '/') or starts-with(@href, '/')">
   104 						<xsl:value-of select="concat($urlBase, @href)"/>
   105 					</xsl:when>
   106 					<xsl:otherwise>
   107 						<xsl:value-of select="concat($urlBase, '/', @href)"/>
   108 					</xsl:otherwise>
   109 				</xsl:choose>
   110 			</xsl:otherwise>
   111 		</xsl:choose>	
   112 		<xsl:text>&gt;</xsl:text>
   113 		<xsl:if test="@title and not(matches(@title, '^\s*$'))">
   114 			<xsl:text> (</xsl:text>
   115 			<xsl:value-of select="@title"/>
   116 			<xsl:text>)</xsl:text>
   117 		</xsl:if>
   118 	</xsl:template>
   119 	
   120 	
   121 	<xsl:template match="h:img">
   122 		<xsl:variable name="obrázek">
   123 			<h:a href="{@src}" title="{@title}">Obrázek: <xsl:value-of select="@alt"/></h:a>
   124 		</xsl:variable>
   125 		<xsl:apply-templates select="$obrázek/node()"/>
   126 	</xsl:template>
   127 	
   128 	
   129 	<xsl:template match="h:strong|h:b">
   130 		<xsl:text>**</xsl:text>
   131 		<xsl:apply-templates/>
   132 		<xsl:text>**</xsl:text>
   133 	</xsl:template>
   134 	
   135 	
   136 	<xsl:template match="h:em|h:i">
   137 		<xsl:text>*</xsl:text>
   138 		<xsl:apply-templates/>
   139 		<xsl:text>*</xsl:text>
   140 	</xsl:template>
   141 	
   142 	
   143 	<xsl:template match="h:abbr[@title]">
   144 		<xsl:apply-templates/>
   145 		<xsl:text> (</xsl:text>
   146 		<xsl:value-of select="@title"/>
   147 		<xsl:text>)</xsl:text>
   148 	</xsl:template>
   149 	
   150 	
   151 	<xsl:template match="h:pre">
   152 		<xsl:text>--------------------------------</xsl:text>
   153 		<xsl:text>&#10;</xsl:text>
   154 		<xsl:apply-templates/>
   155 		<xsl:text>&#10;</xsl:text>
   156 		<xsl:text>--------------------------------</xsl:text>
   157 		<xsl:text>&#10;</xsl:text>
   158 		<xsl:text>&#10;</xsl:text>
   159 	</xsl:template>
   160 	
   161 	
   162 	<xsl:template match="h:code">
   163 		<xsl:text>`</xsl:text>
   164 		<xsl:apply-templates/>
   165 		<xsl:text>`</xsl:text>
   166 	</xsl:template>
   167 	
   168 	
   169 	<xsl:template match="h:hr">
   170 		<xsl:text>----------------------------------------------------------------</xsl:text>
   171 		<xsl:text>&#10;</xsl:text>
   172 		<xsl:text>&#10;</xsl:text>
   173 	</xsl:template>
   174 	
   175 	
   176 	<xsl:template match="h:ul">
   177 		<xsl:apply-templates/>
   178 		<xsl:text>&#10;</xsl:text>
   179 	</xsl:template>
   180 	
   181 	
   182 	<xsl:template match="h:ul/h:li">
   183 		<xsl:text> - </xsl:text>
   184 		<xsl:apply-templates/>
   185 		<xsl:text>&#10;</xsl:text>
   186 	</xsl:template>
   187 	
   188 	
   189 	<xsl:template match="h:ol">
   190 		<xsl:for-each select="h:li">
   191 			<xsl:value-of select="concat(' ', position(), ') ')"/>
   192 			<xsl:apply-templates/>
   193 			<xsl:text>&#10;</xsl:text>
   194 		</xsl:for-each>		
   195 		<xsl:text>&#10;</xsl:text>
   196 	</xsl:template>
   197 	
   198 	
   199 	<xsl:template match="text()[not(parent::h:pre)]">
   200 		<xsl:if test="matches(., '^\s')">
   201 			<xsl:text> </xsl:text>
   202 		</xsl:if>
   203 		<xsl:value-of select="normalize-space(.)"/>
   204 		<xsl:if test="matches(., '\s$')">
   205 			<xsl:text> </xsl:text>
   206 		</xsl:if>
   207 	</xsl:template>
   208 
   209 	
   210 	<xsl:template match="h:div[@class='wwwLinks']">
   211 		<!-- 
   212 			Dvě pomlčky a mezeru budou e-maliloví klienti považovat za začátek podpisu
   213 			a zobrazí ho šedivým písmem a nebudou ho citovat v odpovědích.
   214 		-->
   215 		<xsl:text>-- </xsl:text>
   216 		<xsl:text>&#10;</xsl:text>
   217 		<xsl:apply-templates/>	
   218 	</xsl:template>	
   219 
   220 
   221 </xsl:stylesheet>