Accept attributes in inline image syntax
[multimarkdown] / XSLT / clean-text-poetry.xslt
1 <?xml version="1.0" encoding="utf-8"?>
2
3 <!-- XHTML2LaTeX replace-substring utility file by Fletcher Penney
4         specifically designed for use with MultiMarkdown created XHTML
5         
6         Extracted this routine so that it can be changed more easily by users.
7         
8         This file is responsible for cleaning up special characters into
9                 a LaTeX-friendly format.
10         
11         Modified to support features needed for poetry.
12
13         MultiMarkdown Version 2.0.b5
14                 
15         $Id: clean-text-poetry.xslt 488 2008-01-14 00:46:15Z fletcher $
16 -->
17
18 <!-- 
19 # Copyright (C) 2005-2008  Fletcher T. Penney <fletcher@fletcherpenney.net>
20 #
21 # This program is free software; you can redistribute it and/or modify
22 # it under the terms of the GNU General Public License as published by
23 # the Free Software Foundation; either version 2 of the License, or
24 # (at your option) any later version.
25 #
26 # This program is distributed in the hope that it will be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29 # GNU General Public License for more details.
30 #
31 # You should have received a copy of the GNU General Public License
32 # along with this program; if not, write to the
33 #    Free Software Foundation, Inc.
34 #    59 Temple Place, Suite 330
35 #    Boston, MA 02111-1307 USA
36 -->
37
38
39 <xsl:stylesheet
40         xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
41         xmlns:html="http://www.w3.org/1999/xhtml"
42         version="1.0">
43
44         <!-- It's still built on the original -->
45         <xsl:import href="clean-text.xslt"/>
46
47
48         <!-- Find the longest line of a poem -->
49         <xsl:template name="longest-line">
50                 <xsl:param name="source"/>
51                 <xsl:variable name="first">
52                         <xsl:value-of select="substring-before($source, $newline)"/>
53                 </xsl:variable>
54                 <xsl:variable name="rest">
55                         <xsl:value-of select="substring-after($source, $newline)"/>
56                 </xsl:variable>
57                 <xsl:choose>
58                         <xsl:when test="contains($rest, $newline)">
59                                 <xsl:variable name="second">
60                                         <xsl:call-template name="longest-line">
61                                                 <xsl:with-param name="source">
62                                                         <xsl:value-of select="$rest"/>
63                                                 </xsl:with-param>
64                                         </xsl:call-template>
65                                 </xsl:variable>
66                                 <xsl:choose>
67                                         <xsl:when test="string-length($first) &gt; string-length($second)">
68                                                 <xsl:value-of select="$first"/>
69                                         </xsl:when>
70                                         <xsl:otherwise>
71                                                 <xsl:value-of select="$second"/>
72                                         </xsl:otherwise>
73                                 </xsl:choose>
74                         </xsl:when>
75                         <xsl:otherwise>
76                                 <xsl:value-of select="$rest"/>
77                         </xsl:otherwise>
78                 </xsl:choose>
79         </xsl:template>
80
81
82         <!-- This version is for blocks of poetry.  In additional to the usual
83                 cleanup, it changes the newlines for poetry typesetting, and replaces
84                 leading spaces or tabs with \vin -->
85         <xsl:template name="poetry-text">
86                 <xsl:param name="source"/>
87                 <xsl:call-template name="replace-substring">
88                         <xsl:with-param name="original">
89                 <xsl:call-template name="replace-substring">
90                         <xsl:with-param name="original">
91                 <xsl:call-template name="replace-substring">
92                         <xsl:with-param name="original">
93                                 <xsl:call-template name="clean-text-utility">
94                                         <xsl:with-param name="source">
95                                                 <xsl:value-of select="$source"/>
96                                         </xsl:with-param>
97                                 </xsl:call-template>
98                         </xsl:with-param>
99                         <xsl:with-param name="substring">
100                                 <xsl:value-of select="$newline"/>
101                         </xsl:with-param>
102                         <xsl:with-param name="replacement">
103                                 <xsl:text> \\</xsl:text>
104                                 <xsl:value-of select="$newline"/>
105                         </xsl:with-param>
106                 </xsl:call-template>
107                         </xsl:with-param>
108                         <xsl:with-param name="substring">
109                                 <xsl:value-of select="$newline"/>
110                                 <xsl:text> \\</xsl:text>
111                                 <xsl:value-of select="$newline"/>
112                         </xsl:with-param>
113                         <xsl:with-param name="replacement">
114                                 <xsl:text>!</xsl:text>
115                                 <xsl:value-of select="$newline"/>
116                                 <xsl:value-of select="$newline"/>
117                         </xsl:with-param>
118                 </xsl:call-template>
119                         </xsl:with-param>
120                         <xsl:with-param name="substring">
121                                 <xsl:text>    </xsl:text>
122                         </xsl:with-param>
123                         <xsl:with-param name="replacement">
124                                 <xsl:text>\vin </xsl:text>
125                         </xsl:with-param>
126                 </xsl:call-template>
127         </xsl:template>
128
129 </xsl:stylesheet>