Fenced-Code-Blocks in Python-Markdown
Michel Fortin
michel.fortin at michelf.com
Mon May 12 07:16:12 EDT 2008
Le 2008-05-12 à 1:01, Waylan Limberg a écrit :
> I'd like to announce a beta release of the Fenced-Code-Blocks
> Extension for Python-Markdown.
>
> <http://www.freewisdom.org/projects/python-markdown/Available_Extensions
> >
Wow, that was fast! :-)
There is one particularity in my implementation I think you've missed
though (which is not surprising given I haven't mentioned it anywhere,
yet). It touches the output when there are leading blank lines.
If you try this in various browsers:
<pre>
a
</pre>
You'll notice, when serving the file as text/html, that the first
newline is lost. When parsing the file as XML, it stays there however.
If you then add:
<pre><code>
a
</code></pre>
you'll then notice that the first line is there in Gecko, but still
lost with Web Kit. So basically, you can't just add newlines at the
start of a code block and expect it to work.
PHP Markdown Extra's output when you have a leading newline is as such:
<pre><code><br />a
</code></pre>
which solves the situation in both Safari and Gecko-based browsers
(haven't tested in others). If you have two leading newlines, then
you'll get two <br />s, etc.
> The same syntax is used as the just released PHP Markdown Extra 1.2. I
> did add the option to define a class on the block for language
> identification. Here's an example:
>
> ~~~~~~~~~~~~
> <p>Hello World!</p>
> ~~~~~~~~~~~~{.html}
>
> Becomes:
>
> <pre><code class="html"><p>Hello World!</p>
> </code></pre>
While it has been suggested some time ago that {.class-name} stand for
a class attribute applied to an arbitrary element, I'm wondering if we
can't do something better than that for code blocks.
I'm currently thinking of allowing the following, which I find more
appealing visually:
~~~~~~~~~~~~~~ .html
<p>Hello World!</p>
~~~~~~~~~~~~~~
> Unfortunately, including the class
> definition makes PHP Markdown Extra fail to match the block. Consider
> yourself warned.
Indeed.
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Markdown-Discuss
mailing list