"Context-sensitivity" of headers

Michel Fortin michel.fortin at michelf.com
Wed Mar 9 20:28:32 EST 2005


Le 9 mars 2005, à 13:48, Lasar Liepins a écrit :

> I did build a little PHP function which goes through HTML code and
> changes all Header tags to a smaller header by a definable "level",
> stopping at 6 of course.
>
> 	<?php
> 	function downsize ( $code, $level=1 ) {
> 		for ( $h=5; $h>=1; $h-- ) {
> 			$newlevel = $h+$level;
> 			if ( $newlevel>6 ) { $newlevel=6; }
> 			$code = preg_replace ( "/<(\/*)h".$h.">/", "<\\1h".$newlevel.">",  
> $code );
> 		}
> 		return $code;
> 	}
> 	?>

Nice, but I have the feeling that what I wrote last february to do  
exactly that is a little more efficient since it runs preg_replace only  
once. See this if you're interested:

<http://six.pairlist.net/pipermail/markdown-discuss/2005-February/ 
001019.html>

> What is semantically more logical here? To use second level headers in
> the text file all along, or to dynamically downgrade these headers to
> the next level?

I think it makes more sense to shift headers dynamically. This way, if  
you take you HTML snippet elsewhere, you can adjust it to the right  
header level knowing that the first header level in your text is h1.

But I guess it all depends on what you want to do. The title of a  
weblog entry which is entered in a separate field could be considered  
as the first header and then the rest of your entry would contain h2.

> Also I'm not sure how options to change MarkDown's output fit into the
> philosophy of MarkDown, since currently there are none.

Well, there is one: it's used when you want Markdown to output HTML  
instead of XHTML. But I think that doesn't fall in the same category of  
option.


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


More information about the Markdown-Discuss mailing list