diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/commonmark.c | 8 | ||||
-rw-r--r-- | src/inlines.c | 37 | ||||
-rw-r--r-- | test/entity_tests.py | 2 | ||||
-rw-r--r-- | test/regression.txt | 15 | ||||
-rw-r--r-- | test/spec.txt | 149 | ||||
-rw-r--r-- | tools/xml2md.xsl | 319 |
8 files changed, 478 insertions, 60 deletions
@@ -2,7 +2,7 @@ cmark ===== [![Build Status]](https://travis-ci.org/commonmark/cmark) -[![Windows Build Status]](https://ci.appveyor.com/project/commonmark/cmark) +[![Windows Build Status]](https://ci.appveyor.com/project/jgm/cmark-0ub06) `cmark` is the C reference implementation of [CommonMark], a rationalized version of Markdown syntax with a [spec][the spec]. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 995a9df..468b0f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -128,11 +128,13 @@ if (MSVC) APPEND PROPERTY LINK_FLAGS /INCREMENTAL:NO) endif(MSVC) -set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON) +if(NOT MSVC OR CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) + set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON) + include(InstallRequiredSystemLibraries) +endif() set(libdir lib${LIB_SUFFIX}) -include (InstallRequiredSystemLibraries) install(TARGETS ${PROGRAM} ${CMARK_INSTALL} EXPORT cmark RUNTIME DESTINATION bin diff --git a/src/commonmark.c b/src/commonmark.c index 95a1ae5..d701bab 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -167,6 +167,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node, int list_number; cmark_delim_type list_delim; int numticks; + bool extra_spaces; int i; bool entering = (ev_type == CMARK_EVENT_ENTER); const char *info, *code, *title; @@ -363,14 +364,17 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node, code = cmark_node_get_literal(node); code_len = strlen(code); numticks = shortest_unused_backtick_sequence(code); + extra_spaces = code_len == 0 || + code[0] == '`' || code[code_len - 1] == '`' || + code[0] == ' ' || code[code_len - 1] == ' '; for (i = 0; i < numticks; i++) { LIT("`"); } - if (code_len == 0 || code[0] == '`') { + if (extra_spaces) { LIT(" "); } OUT(cmark_node_get_literal(node), allow_wrap, LITERAL); - if (code_len == 0 || code[code_len - 1] == '`') { + if (extra_spaces) { LIT(" "); } for (i = 0; i < numticks; i++) { diff --git a/src/inlines.c b/src/inlines.c index 8bb82f1..171247e 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -323,6 +323,37 @@ static bufsize_t scan_to_closing_backticks(subject *subj, return 0; } +// Destructively modify string, converting newlines to +// spaces, then removing a single leading + trailing space. +static void S_normalize_code(cmark_strbuf *s) { + bufsize_t r, w; + + for (r = 0, w = 0; r < s->size; ++r) { + switch (s->ptr[r]) { + case '\r': + if (s->ptr[r + 1] != '\n') { + s->ptr[w++] = ' '; + } + break; + case '\n': + s->ptr[w++] = ' '; + break; + default: + s->ptr[w++] = s->ptr[r]; + } + } + + // begins and ends with space? + if (s->ptr[0] == ' ' && s->ptr[w - 1] == ' ') { + cmark_strbuf_drop(s, 1); + cmark_strbuf_truncate(s, w - 2); + } else { + cmark_strbuf_truncate(s, w); + } + +} + + // Parse backtick code section or raw backticks, return an inline. // Assumes that the subject has a backtick at the current position. static cmark_node *handle_backticks(subject *subj, int options) { @@ -338,8 +369,7 @@ static cmark_node *handle_backticks(subject *subj, int options) { cmark_strbuf_set(&buf, subj->input.data + startpos, endpos - startpos - openticks.len); - cmark_strbuf_trim(&buf); - cmark_strbuf_normalize_whitespace(&buf); + S_normalize_code(&buf); cmark_node *node = make_code(subj, startpos, endpos - openticks.len - 1, cmark_chunk_buf_detach(&buf)); adjust_subj_node_newlines(subj, node, endpos - startpos, openticks.len, options); @@ -347,6 +377,7 @@ static cmark_node *handle_backticks(subject *subj, int options) { } } + // Scan ***, **, or * and return number scanned, or 0. // Advances position. static int scan_delims(subject *subj, unsigned char c, bool *can_open, @@ -1314,7 +1345,7 @@ bufsize_t cmark_parse_reference_inline(cmark_mem *mem, cmark_chunk *input, // parse optional link_title beforetitle = subj.pos; spnl(&subj); - matchlen = scan_link_title(&subj.input, subj.pos); + matchlen = subj.pos == beforetitle ? 0 : scan_link_title(&subj.input, subj.pos); if (matchlen) { title = cmark_chunk_dup(&subj.input, subj.pos, matchlen); subj.pos += matchlen; diff --git a/test/entity_tests.py b/test/entity_tests.py index 0e3daad..ebaf9f7 100644 --- a/test/entity_tests.py +++ b/test/entity_tests.py @@ -54,7 +54,7 @@ for entity, utf8 in entities: print(entity, '[ERRORED (return code {})]'.format(rc)) print(err) elif check in actual: - print(entity, '[PASSED]') + # print(entity, '[PASSED]') # omit noisy success output passed += 1 else: print(entity, '[FAILED]') diff --git a/test/regression.txt b/test/regression.txt index 5f6b624..6fef3af 100644 --- a/test/regression.txt +++ b/test/regression.txt @@ -106,3 +106,18 @@ City: <meta itemprop="name" content="Springfield"> </span></p> ```````````````````````````````` + +Issue #530 - link parsing corner cases + +```````````````````````````````` example +[a](\ b) + +[a](<<b) + +[a](<b +) +. +<p>[a](\ b)</p> +<p><a href="%3C%3Cb">a</a></p> +<p><a href="%3Cb">a</a></p> +```````````````````````````````` diff --git a/test/spec.txt b/test/spec.txt index dc2f5d5..bd2affb 100644 --- a/test/spec.txt +++ b/test/spec.txt @@ -514,8 +514,8 @@ one block element does not affect the inline parsing of any other. ## Container blocks and leaf blocks We can divide blocks into two types: -[container block](@)s, -which can contain other blocks, and [leaf block](@)s, +[container blocks](@), +which can contain other blocks, and [leaf blocks](@), which cannot. # Leaf blocks @@ -1996,9 +1996,10 @@ by their start and end conditions. The block begins with a line that meets a [start condition](@) (after up to three spaces optional indentation). It ends with the first subsequent line that meets a matching [end condition](@), or the last line of -the document or other [container block]), if no line is encountered that meets the -[end condition]. If the first line meets both the [start condition] -and the [end condition], the block will contain just that line. +the document or other [container block](#container-blocks)), if no +line is encountered that meets the [end condition]. If the first line +meets both the [start condition] and the [end condition], the block +will contain just that line. 1. **Start condition:** line begins with the string `<script`, `<pre`, or `<style` (case-insensitive), followed by whitespace, @@ -2029,7 +2030,7 @@ followed by one of the strings (case-insensitive) `address`, `footer`, `form`, `frame`, `frameset`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `head`, `header`, `hr`, `html`, `iframe`, `legend`, `li`, `link`, `main`, `menu`, `menuitem`, -`meta`, `nav`, `noframes`, `ol`, `optgroup`, `option`, `p`, `param`, +`nav`, `noframes`, `ol`, `optgroup`, `option`, `p`, `param`, `section`, `source`, `summary`, `table`, `tbody`, `td`, `tfoot`, `th`, `thead`, `title`, `tr`, `track`, `ul`, followed by [whitespace], the end of the line, the string `>`, or @@ -2043,10 +2044,11 @@ or the end of the line.\ **End condition:** line is followed by a [blank line]. HTML blocks continue until they are closed by their appropriate -[end condition], or the last line of the document or other [container block]. -This means any HTML **within an HTML block** that might otherwise be recognised -as a start condition will be ignored by the parser and passed through as-is, -without changing the parser's state. +[end condition], or the last line of the document or other [container +block](#container-blocks). This means any HTML **within an HTML +block** that might otherwise be recognised as a start condition will +be ignored by the parser and passed through as-is, without changing +the parser's state. For instance, `<pre>` within a HTML block started by `<table>` will not affect the parser state; as the HTML block was started in by start condition 6, it @@ -2878,6 +2880,18 @@ The link destination may not be omitted: <p>[foo]</p> ```````````````````````````````` +The title must be separated from the link destination by +whitespace: + +```````````````````````````````` example +[foo]: <bar>(baz) + +[foo] +. +<p>[foo]: <bar>(baz)</p> +<p>[foo]</p> +```````````````````````````````` + Both title and destination can contain backslash escapes and literal backslashes: @@ -3208,7 +3222,7 @@ aaa # Container blocks -A [container block] is a block that has other +A [container block](#container-blocks) is a block that has other blocks as its contents. There are two basic kinds of container blocks: [block quotes] and [list items]. [Lists] are meta-containers for [list items]. @@ -5563,7 +5577,7 @@ foo ## Entity and numeric character references All valid HTML entity references and numeric character -references, except those occuring in code blocks and code spans, +references, except those occurring in code blocks and code spans, are recognized as such and treated as equivalent to the corresponding Unicode characters. Conforming CommonMark parsers need not store information about whether a particular character @@ -5714,9 +5728,15 @@ preceded nor followed by a backtick. A [code span](@) begins with a backtick string and ends with a backtick string of equal length. The contents of the code span are -the characters between the two backtick strings, with leading and -trailing spaces and [line endings] removed, and -[whitespace] collapsed to single spaces. +the characters between the two backtick strings, normalized in the +following ways: + +- First, [line endings] are converted to [spaces]. +- If the resulting string both begins *and* ends with a [space] + character, a single [space] character is removed from the + front and back. This allows you to include code that begins + or ends with backtick characters, which must be separated by + whitespace from the opening or closing backtick strings. This is a simple code span: @@ -5728,10 +5748,11 @@ This is a simple code span: Here two backticks are used, because the code contains a backtick. -This example also illustrates stripping of leading and trailing spaces: +This example also illustrates stripping of a single leading and +trailing space: ```````````````````````````````` example -`` foo ` bar `` +`` foo ` bar `` . <p><code>foo ` bar</code></p> ```````````````````````````````` @@ -5746,58 +5767,69 @@ spaces: <p><code>``</code></p> ```````````````````````````````` - -[Line endings] are treated like spaces: +Note that only *one* space is stripped: ```````````````````````````````` example -`` -foo -`` +` `` ` . -<p><code>foo</code></p> +<p><code> `` </code></p> ```````````````````````````````` +The stripping only happens if the space is on both +sides of the string: -Interior spaces and [line endings] are collapsed into -single spaces, just as they would be by a browser: +```````````````````````````````` example +` a` +. +<p><code> a</code></p> +```````````````````````````````` + +Only [spaces], and not [unicode whitespace] in general, are +stripped in this way: ```````````````````````````````` example -`foo bar - baz` +` b ` . -<p><code>foo bar baz</code></p> +<p><code> b </code></p> ```````````````````````````````` -Not all [Unicode whitespace] (for instance, non-breaking space) is -collapsed, however: +[Line endings] are treated like spaces: ```````````````````````````````` example -`a b` +`` +foo +bar +baz +`` . -<p><code>a b</code></p> +<p><code>foo bar baz</code></p> ```````````````````````````````` +```````````````````````````````` example +`` +foo +`` +. +<p><code>foo </code></p> +```````````````````````````````` -Q: Why not just leave the spaces, since browsers will collapse them -anyway? A: Because we might be targeting a non-HTML format, and we -shouldn't rely on HTML-specific rendering assumptions. -(Existing implementations differ in their treatment of internal -spaces and [line endings]. Some, including `Markdown.pl` and -`showdown`, convert an internal [line ending] into a -`<br />` tag. But this makes things difficult for those who like to -hard-wrap their paragraphs, since a line break in the midst of a code -span will cause an unintended line break in the output. Others just -leave internal spaces as they are, which is fine if only HTML is being -targeted.) +Interior spaces are not collapsed: ```````````````````````````````` example -`foo `` bar` +`foo bar +baz` . -<p><code>foo `` bar</code></p> +<p><code>foo bar baz</code></p> ```````````````````````````````` +Note that browsers will typically collapse consecutive spaces +when rendering `<code>` elements, so it is recommended that +the following CSS be used: + + code{white-space: pre-wrap;} + Note that backslash escapes do not work in code spans. All backslashes are treated literally: @@ -5813,6 +5845,19 @@ Backslash escapes are never needed, because one can always choose a string of *n* backtick characters as delimiters, where the code does not contain any strings of exactly *n* backtick characters. +```````````````````````````````` example +``foo`bar`` +. +<p><code>foo`bar</code></p> +```````````````````````````````` + +```````````````````````````````` example +` foo `` bar ` +. +<p><code>foo `` bar</code></p> +```````````````````````````````` + + Code span backticks have higher precedence than any other inline constructs except HTML tags and autolinks. Thus, for example, this is not parsed as emphasized text, since the second `*` is part of a code @@ -5950,15 +5995,17 @@ of one or more `_` characters that is not preceded or followed by a non-backslash-escaped `_` character. A [left-flanking delimiter run](@) is -a [delimiter run] that is (a) not followed by [Unicode whitespace], -and (b) not followed by a [punctuation character], or +a [delimiter run] that is (1) not followed by [Unicode whitespace], +and either (2a) not followed by a [punctuation character], or +(2b) followed by a [punctuation character] and preceded by [Unicode whitespace] or a [punctuation character]. For purposes of this definition, the beginning and the end of the line count as Unicode whitespace. A [right-flanking delimiter run](@) is -a [delimiter run] that is (a) not preceded by [Unicode whitespace], -and (b) not preceded by a [punctuation character], or +a [delimiter run] that is (1) not preceded by [Unicode whitespace], +and either (2a) not preceded by a [punctuation character], or +(2b) preceded by a [punctuation character] and followed by [Unicode whitespace] or a [punctuation character]. For purposes of this definition, the beginning and the end of the line count as Unicode whitespace. @@ -9003,10 +9050,10 @@ bar</em></p> Line breaks do not occur inside code spans ```````````````````````````````` example -`code +`code span` . -<p><code>code span</code></p> +<p><code>code span</code></p> ```````````````````````````````` diff --git a/tools/xml2md.xsl b/tools/xml2md.xsl new file mode 100644 index 0000000..0122e5f --- /dev/null +++ b/tools/xml2md.xsl @@ -0,0 +1,319 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + +xml2md.xsl +========== + +This XSLT stylesheet transforms the cmark XML format back to Commonmark. +Since the XML output is lossy, a lossless MD->XML->MD roundtrip isn't +possible. The XML->MD->XML roundtrip should produce the original XML, +though. + +Example usage with xsltproc: + + cmark -t xml doc.md | xsltproc -novalid xml2md.xsl - + +--> + +<xsl:stylesheet + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:md="http://commonmark.org/xml/1.0"> + +<xsl:output method="text" encoding="utf-8"/> + +<!-- Generic templates --> + +<xsl:template match="/ | md:document | md:list"> + <xsl:apply-templates select="md:*"/> +</xsl:template> + +<xsl:template match="md:*"> + <xsl:message>Unsupported element '<xsl:value-of select="local-name()"/>'</xsl:message> +</xsl:template> + +<xsl:template match="md:*" mode="indent"/> + +<!-- Indent blocks --> + +<xsl:template match="md:*" mode="indent-block"> + <xsl:if test="preceding-sibling::md:*"> + <xsl:if test="not(ancestor::md:list[1][@tight='true'])"> + <xsl:apply-templates select="ancestor::md:*" mode="indent"/> + <xsl:text> </xsl:text> + </xsl:if> + <xsl:apply-templates select="ancestor::md:*" mode="indent"/> + </xsl:if> +</xsl:template> + +<!-- Heading --> + +<xsl:template match="md:heading"> + <xsl:apply-templates select="." mode="indent-block"/> + <xsl:value-of select="substring('###### ', 7 - @level)"/> + <xsl:apply-templates select="md:*"/> + <xsl:text> </xsl:text> +</xsl:template> + +<!-- Paragraph --> + +<xsl:template match="md:paragraph"> + <xsl:apply-templates select="." mode="indent-block"/> + <xsl:apply-templates select="md:*"/> + <xsl:text> </xsl:text> +</xsl:template> + +<!-- Thematic break --> + +<xsl:template match="md:thematic_break"> + <xsl:apply-templates select="." mode="indent-block"/> + <xsl:text>*** </xsl:text> +</xsl:template> + +<!-- List --> + +<xsl:template match="md:list"> + <xsl:apply-templates select="." mode="indent-block"/> + <xsl:apply-templates select="md:*"/> +</xsl:template> + +<xsl:template match="md:item"> + <xsl:apply-templates select="." mode="indent-block"/> + <xsl:choose> + <xsl:when test="../@type = 'bullet'">-</xsl:when> + <xsl:when test="../@type = 'ordered'"> + <xsl:value-of select="../@start + position() - 1"/> + <xsl:choose> + <xsl:when test="../@delim = 'period'">.</xsl:when> + <xsl:when test="../@delim = 'paren'">)</xsl:when> + </xsl:choose> + </xsl:when> + </xsl:choose> + <xsl:text> </xsl:text> + <xsl:apply-templates select="md:*"/> +</xsl:template> + +<xsl:template match="md:item" mode="indent"> + <xsl:choose> + <xsl:when test="../@type = 'bullet'"> + <xsl:text> </xsl:text> + </xsl:when> + <xsl:when test="../@type = 'ordered'"> + <xsl:text> </xsl:text> + </xsl:when> + </xsl:choose> +</xsl:template> + +<!-- Block quote --> + +<xsl:template match="md:block_quote"> + <xsl:apply-templates select="." mode="indent-block"/> + <xsl:text>> </xsl:text> + <xsl:apply-templates select="md:*"/> +</xsl:template> + +<xsl:template match="md:block_quote" mode="indent"> + <xsl:text>> </xsl:text> +</xsl:template> + +<!-- Code block --> + +<xsl:template match="md:code_block"> + <xsl:apply-templates select="." mode="indent-block"/> + + <xsl:variable name="t" select="string(.)"/> + <xsl:variable name="delim"> + <xsl:call-template name="code-delim"> + <xsl:with-param name="text" select="$t"/> + <xsl:with-param name="delim" select="'```'"/> + </xsl:call-template> + </xsl:variable> + + <xsl:value-of select="$delim"/> + <xsl:value-of select="@info"/> + <xsl:text> </xsl:text> + <xsl:call-template name="indent-lines"> + <xsl:with-param name="code" select="$t"/> + </xsl:call-template> + <xsl:apply-templates select="ancestor::md:*" mode="indent"/> + <xsl:value-of select="$delim"/> + <xsl:text> </xsl:text> +</xsl:template> + +<!-- Inline HTML --> + +<xsl:template match="md:html_block"> + <xsl:apply-templates select="." mode="indent-block"/> + <xsl:value-of select="substring-before(., ' ')"/> + <xsl:text> </xsl:text> + <xsl:call-template name="indent-lines"> + <xsl:with-param name="code" select="substring-after(., ' ')"/> + </xsl:call-template> +</xsl:template> + +<!-- Indent multiple lines --> + +<xsl:template name="indent-lines"> + <xsl:param name="code"/> + <xsl:if test="contains($code, ' ')"> + <xsl:apply-templates select="ancestor::md:*" mode="indent"/> + <xsl:value-of select="substring-before($code, ' ')"/> + <xsl:text> </xsl:text> + <xsl:call-template name="indent-lines"> + <xsl:with-param name="code" select="substring-after($code, ' ')"/> + </xsl:call-template> + </xsl:if> +</xsl:template> + +<!-- Text --> + +<xsl:template match="md:text"> + <xsl:variable name="t" select="string(.)"/> + <xsl:variable name="first" select="substring($t, 1, 1)"/> + <xsl:variable name="marker-check" select="translate(substring($t, 1, 10), '0123456789', '')"/> + <xsl:choose> + <!-- Escape ordered list markers --> + <xsl:when test="starts-with($marker-check, '.') and $first != '.'"> + <xsl:value-of select="substring-before($t, '.')"/> + <xsl:text>\.</xsl:text> + <xsl:call-template name="escape-text"> + <xsl:with-param name="text" select="substring-after($t, '.')"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="starts-with($marker-check, ')') and $first != ')'"> + <xsl:value-of select="substring-before($t, ')')"/> + <xsl:text>\)</xsl:text> + <xsl:call-template name="escape-text"> + <xsl:with-param name="text" select="substring-after($t, ')')"/> + </xsl:call-template> + </xsl:when> + <!-- Escape leading block characters --> + <xsl:when test="contains('-+>#=~', $first)"> + <xsl:text>\</xsl:text> + <xsl:value-of select="$first"/> + <xsl:call-template name="escape-text"> + <xsl:with-param name="text" select="substring($t, 2)"/> + </xsl:call-template> + </xsl:when> + <!-- Otherwise --> + <xsl:otherwise> + <xsl:call-template name="escape-text"> + <xsl:with-param name="text" select="$t"/> + </xsl:call-template> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<!-- Breaks --> + +<xsl:template match="md:softbreak"> + <xsl:text> </xsl:text> + <xsl:apply-templates select="ancestor::md:*" mode="indent"/> +</xsl:template> + +<xsl:template match="md:linebreak"> + <xsl:text> </xsl:text> + <xsl:apply-templates select="ancestor::md:*" mode="indent"/> +</xsl:template> + +<!-- Emphasis --> + +<xsl:template match="md:emph"> + <xsl:text>*</xsl:text> + <xsl:apply-templates select="md:*"/> + <xsl:text>*</xsl:text> +</xsl:template> + +<xsl:template match="md:strong"> + <xsl:text>**</xsl:text> + <xsl:apply-templates select="md:*"/> + <xsl:text>**</xsl:text> +</xsl:template> + +<!-- Inline code --> + +<xsl:template match="md:code"> + <xsl:variable name="t" select="string(.)"/> + <xsl:variable name="delim"> + <xsl:call-template name="code-delim"> + <xsl:with-param name="text" select="$t"/> + <xsl:with-param name="delim" select="'`'"/> + </xsl:call-template> + </xsl:variable> + <xsl:value-of select="$delim"/> + <xsl:value-of select="$t"/> + <xsl:value-of select="$delim"/> +</xsl:template> + +<!-- Links and images --> + +<xsl:template match="md:link | md:image"> + <xsl:if test="self::md:image">!</xsl:if> + <xsl:text>[</xsl:text> + <xsl:apply-templates select="md:*"/> + <xsl:text>](</xsl:text> + <xsl:call-template name="escape-text"> + <xsl:with-param name="text" select="string(@destination)"/> + <xsl:with-param name="escape" select="'()'"/> + </xsl:call-template> + <xsl:if test="string(@title)"> + <xsl:text> "</xsl:text> + <xsl:call-template name="escape-text"> + <xsl:with-param name="text" select="string(@title)"/> + <xsl:with-param name="escape" select="'"'"/> + </xsl:call-template> + <xsl:text>"</xsl:text> + </xsl:if> + <xsl:text>)</xsl:text> +</xsl:template> + +<!-- Inline HTML --> + +<xsl:template match="md:html_inline"> + <xsl:value-of select="."/> +</xsl:template> + +<!-- Escaping helpers --> + +<xsl:template name="escape-text"> + <xsl:param name="text"/> + <xsl:param name="escape" select="'*_`<[]&'"/> + + <xsl:variable name="trans" select="translate($text, $escape, '\\\\\\\')"/> + <xsl:choose> + <xsl:when test="contains($trans, '\')"> + <xsl:variable name="safe" select="substring-before($trans, '\')"/> + <xsl:variable name="l" select="string-length($safe)"/> + <xsl:value-of select="$safe"/> + <xsl:text>\</xsl:text> + <xsl:value-of select="substring($text, $l + 1, 1)"/> + <xsl:call-template name="escape-text"> + <xsl:with-param name="text" select="substring($text, $l + 2)"/> + <xsl:with-param name="escape" select="$escape"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$text"/> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template name="code-delim"> + <xsl:param name="text"/> + <xsl:param name="delim"/> + + <xsl:choose> + <xsl:when test="contains($text, $delim)"> + <xsl:call-template name="code-delim"> + <xsl:with-param name="text" select="$text"/> + <xsl:with-param name="delim" select="concat($delim, '`')"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$delim"/> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +</xsl:stylesheet> |