@@ -10,8 +10,6 @@ Since the XML output is lossy, a lossless MD->XML->MD roundtrip isn't
10
10
possible. The XML->MD->XML roundtrip should produce the original XML,
11
11
though.
12
12
13
- HTML blocks and inlines aren't supported.
14
-
15
13
Example usage with xsltproc:
16
14
17
15
cmark -t xml doc.md | xsltproc -novalid xml2md.xsl -
@@ -123,15 +121,23 @@ Example usage with xsltproc:
123
121
124
122
<xsl : template match =" md:code_block" >
125
123
<xsl : apply-templates select =" ." mode =" indent-block" />
126
- <!-- TODO: Longer delimiter if text contains ``` -->
127
- <xsl : text >```</xsl : text >
124
+
125
+ <xsl : variable name =" t" select =" string(.)" />
126
+ <xsl : variable name =" delim" >
127
+ <xsl : call-template name =" code-delim" >
128
+ <xsl : with-param name =" text" select =" $t" />
129
+ <xsl : with-param name =" delim" select =" '```'" />
130
+ </xsl : call-template >
131
+ </xsl : variable >
132
+
133
+ <xsl : value-of select =" $delim" />
128
134
<xsl : value-of select =" @info" />
129
135
<xsl : text > </xsl : text >
130
136
<xsl : call-template name =" indent-lines" >
131
- <xsl : with-param name =" code" select =" . " />
137
+ <xsl : with-param name =" code" select =" $t " />
132
138
</xsl : call-template >
133
139
<xsl : apply-templates select =" ancestor::md:*" mode =" indent" />
134
- <xsl : text >```</ xsl : text >
140
+ <xsl : value-of select = " $delim " / >
135
141
<xsl : text > </xsl : text >
136
142
</xsl : template >
137
143
@@ -228,28 +234,16 @@ Example usage with xsltproc:
228
234
<!-- Inline code -->
229
235
230
236
<xsl : template match =" md:code" >
231
- <xsl : call-template name =" escape-code" >
232
- <xsl : with-param name =" text" select =" string(.)" />
233
- </xsl : call-template >
234
- </xsl : template >
235
-
236
- <xsl : template name =" escape-code" >
237
- <xsl : param name =" text" />
238
- <xsl : param name =" delim" select =" '`'" />
239
-
240
- <xsl : choose >
241
- <xsl : when test =" contains($text, $delim)" >
242
- <xsl : call-template name =" escape-code" >
243
- <xsl : with-param name =" text" select =" $text" />
244
- <xsl : with-param name =" delim" select =" concat($delim, '`')" />
245
- </xsl : call-template >
246
- </xsl : when >
247
- <xsl : otherwise >
248
- <xsl : value-of select =" $delim" />
249
- <xsl : value-of select =" $text" />
250
- <xsl : value-of select =" $delim" />
251
- </xsl : otherwise >
252
- </xsl : choose >
237
+ <xsl : variable name =" t" select =" string(.)" />
238
+ <xsl : variable name =" delim" >
239
+ <xsl : call-template name =" code-delim" >
240
+ <xsl : with-param name =" text" select =" $t" />
241
+ <xsl : with-param name =" delim" select =" '`'" />
242
+ </xsl : call-template >
243
+ </xsl : variable >
244
+ <xsl : value-of select =" $delim" />
245
+ <xsl : value-of select =" $t" />
246
+ <xsl : value-of select =" $delim" />
253
247
</xsl : template >
254
248
255
249
<!-- Links and images -->
@@ -280,7 +274,7 @@ Example usage with xsltproc:
280
274
<xsl : value-of select =" ." />
281
275
</xsl : template >
282
276
283
- <!-- Escape text -->
277
+ <!-- Escaping helpers -->
284
278
285
279
<xsl : template name =" escape-text" >
286
280
<xsl : param name =" text" />
@@ -305,4 +299,21 @@ Example usage with xsltproc:
305
299
</xsl : choose >
306
300
</xsl : template >
307
301
302
+ <xsl : template name =" code-delim" >
303
+ <xsl : param name =" text" />
304
+ <xsl : param name =" delim" />
305
+
306
+ <xsl : choose >
307
+ <xsl : when test =" contains($text, $delim)" >
308
+ <xsl : call-template name =" code-delim" >
309
+ <xsl : with-param name =" text" select =" $text" />
310
+ <xsl : with-param name =" delim" select =" concat($delim, '`')" />
311
+ </xsl : call-template >
312
+ </xsl : when >
313
+ <xsl : otherwise >
314
+ <xsl : value-of select =" $delim" />
315
+ </xsl : otherwise >
316
+ </xsl : choose >
317
+ </xsl : template >
318
+
308
319
</xsl : stylesheet >
0 commit comments