Header ids in PHP Markdown Extra

Michel Fortin michel.fortin at michelf.com
Sat Sep 3 10:20:33 EDT 2005


Le 2005-09-03 à 9:04, Lou Quillio a écrit :


> Great news, Michel. Ids on any block-level element will provide

> targets for XHTML and hooks for most CSS things you'd want to do.


This is only for headers right now, not "every block-level element".
It will take more time to have it with more elements, but making it
work at one place is a good start and I will stick there for 1.0.
Eventually you should be able to put an id everywhere.


> The only burning need for class assignment that I can see is oddball

> mechanical stuff, like alternating row colors in tables -- but then

> tables are persistently a special case. Since PHP Markdown Extra

> takes them up, it might be useful to also have an *optional* switch

> in the table syntax that would inject alternating class attributes

> into TRs (odd_row, even_row). That way they could be styled as an

> abstraction, or a little more discretely in the context of the

> table's id. Or ignored. User's choice.


Something like this?

function AddParityClassToTableRows($text) {
return preg_replace_callback(
'/<tr|<table/',
'AddParityClassToTableRows_callback',
$text);
}
function AddParityClassToTableRows_callback($matches) {
static $parity = 1;
$classes = array('even_row', 'odd_row');
if ($matches[0] = '<tr') {
$parity = ($parity + 1) % 2;
return "<tr class=\"$classes[$parity]\"";
}
# Reset parity.
$parity = 1;
return $matches[0];
}

Ok, I haven't tested it (written directly in mail) but this should do
what you want if you call `AddParityClassToTableRows` just after
calling `Markdown`. Note that this may not work correctly if your
table rows already contain a class attribute.

I'm really not sure if something like this should be part of
Markdown. But I guess it could be part of PHP Markdown Extra.



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




More information about the Markdown-Discuss mailing list