Newline before </code></pre>

Jon Noring jon at noring.name
Sun Jul 2 18:32:49 EDT 2006


Milian Wolff wrote:


> What's the point in adding a newline before the closing tags of a

> preformatted code block? Example:

>

> This is Code

>

> Will become:

>

> <pre><code>This is Code

> </code></pre>

>

> (In both PHP and Perl Markdown)

>

> I don't really see the point, especially because this is not what I

> would want to see. With a normal stylesheet which has

white-space:pre; set on pre/code blocks, you'll see an empty line

> after "This is Code". In my eyes that is wrong.

>

> It's pretty easy to prevent though, you'll just have to remove the

> newline before `</code></pre>` in _DoCodeBlocks(_callback).


Some background:

In XHTML, the <pre> tag means all the text characters in the content,
including the white space characters, is significant (that is, the
XML attribute 'xml:space' is designated the value of 'preserve'.) The
white space characters are:

space (U+0020)
tab (U+0009)
carriage return (U+000D)
line feed (U+000A)

(To note: For ordinary XHTML elements, where xml:space is set the
value of 'default', the default browser/user agent behavior is to
collapse a sequence of one or more white space characters in content
to a single space character. Also, leading and trailing white space
is ignored.)

Thus,

<pre><code>This is Code
</code></pre>

is different than:

<pre><code>This is Code</code></pre>

For comparison, for ordinary XHTML markup where xml:space has the
value of 'default':

<p>This is a paragraph.</p>

Is the same to browsers as:

<p>
This is a paragraph.
</p>


Now, I don't know the reason in Perl or PHP markdown for preserving
CR/LF characters using <pre>, but there must be some reason. I'm
only trying to give some background information.


Jon Noring



More information about the Markdown-Discuss mailing list