diff --git 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
@@ -3208,7 +3210,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].
@@ -5714,9 +5716,16 @@ 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], unless they are
+ adjacent to [spaces], in which case they are ignored.
+- If the 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 +5737,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 +5756,70 @@ 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:
+
+```````````````````````````````` example
+` a`
+.
+<p><code> a</code></p>
+````````````````````````````````
-Interior spaces and [line endings] are collapsed into
-single spaces, just as they would be by a browser:
+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, unless they
+come after spaces, in which case they are ignored.
```````````````````````````````` 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 +5835,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
@@ -9006,7 +9041,7 @@ Line breaks do not occur inside code spans
`code
span`
.
-<p><code>code span</code></p>
+<p><code>code span</code></p>
````````````````````````````````