PHP Markdown: Block tag syntax experiments

Michel Fortin michel.fortin at michelf.com
Sat Aug 21 13:42:22 EDT 2004


For some times now, I've been playing with the way PHP Markdown handles 
block tags, trying to improve it.

So I've made a version 1.0 Experimental of PHP Markdown that include 
some cool improvements regarding the way block tags are handled in 
markdown-formatted text. The source may be available later.

For now you may try the expermiental version on the PHP Markdown Dingus 
here: <http://www.michelf.com/projects/php-markdown/dingus/>. Select 
the "MD Experimental" filter.

Following is a description of the goals and the experiments made.


Goals
-----

Here are the problems I wanted to solve/improve:

1.  Nested tags need to follow very strict indentation rules, or
     else Markdown will produce strange output, like closing
     "div"s inside a paragraph.

     While this is easy to follow if you write the code yourself,
     it gets more tricky if you insert code generated elsewhere.

     So Markdown should be able work with any valid HTML/XHTML.
     This would make things easier.

2.  Many people would like Markdown to filter what is inside
     "div" tags. It would be great if there was a simple way to
     tell Markdown to do this.

3.	Some tags, like "script" and "math" should not at all be
     altered by Markdown. Currently this works only if they are
     not in a paragraph, but consider something like this:

         Current time is <script> write_current_time(); </script>.

     It get converted to this (obviously wrong):

         <p>Current time is <script> write<em>current</em>time(); 
</script>.</p>


First Experiment
----------------

Revised handling of block tags to remove current limitations. Block 
tags can be nested and indented arbitrarily, like this:

     <div>
       <div>
     </div>
       </div>

Blocks tags now fall into three categories:

1.  Always-block tags, like "div" or "p".
     First tag need to be the first thing on the line, with
     no indentation (or this will make a code block). Following
     content and closing tag can be anywhere. Some examples:

         <div><p>Test</p></div>

         <div>
         <div>
         </div>
         </div>

2.  Context-block tags, like "ins", "del", "script" and "noscript";
     They may be either inside a paragraph or used as a block.
	To be treated like a block, the first tag need to be the
	first thing on the line, with no indentation (or this will
	make a code block). and it need to be alone. Following
     content and closing tag can be anywhere. Some examples:

         <ins>
         <p>This one is a block and is not altered by Markdown</p>
         </ins>

         <ins>This ins will be included inside the paragraph tag.</ins>

3.  Don't-touch tags, like "math" or "script";
     The content should not be processed by Markdown, even when
     inside a paragraph.


Second Experiment
-----------------

Block tags content can also be processed by adding a dot after the 
opening tag:
	
     <div>.
     1. My list
     </div>

     <ins>.
     My paragraph.
     </ins>


Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/



More information about the Markdown-discuss mailing list