Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An experimental textplug to give the feature-block-plugins branch optional full HTML5 compatibility.
<?php
/**
* HTML5 textplug for textile
* ==========================
*
* Makes use of the default block handler implementation. Override by editing this file if you so wish.
*
* Usage
* -----
*
* place "HTML5. On" (without the quotes & note the capitalisation) as the first line of your HTML5 document. Thereafter you should be able to use HTML5
* throughout your document and have textile issue abbrs, instead of acronyms.
*/
Textile::RegisterBlockHandler( 'HTML5', '_textile_html5_block_handler' );
function _textile_html5_block_handler( $textile, $tag, $att, $atts, $ext, $cite, $o1, $o2, $content, $c2, $c1, $eat )
{
if( $tag === 'HTML5' )
{
# Remap the now deprecated 'acronym' with 'abbr'...
$textile->glyph_replace[6] = '<abbr title="$2">$1</abbr>'; # TODO Glyph indexing will need to be made semantic
# No visible output from this blockhandler...
$eat = true;
}
return array($o1, $o2, $content, $c2, $c1, $eat);
}
# None of the following (AFAIK) require special implementations so they use the default textile block implementation
# indicated by a null handler.
Textile::RegisterBlockHandler( 'nav', null );
Textile::RegisterBlockHandler( 'section', null );
Textile::RegisterBlockHandler( 'aside', null );
Textile::RegisterBlockHandler( 'detail', null );
Textile::RegisterBlockHandler( 'header', null );
Textile::RegisterBlockHandler( 'footer', null );
Textile::RegisterBlockHandler( 'address', null );
Textile::RegisterBlockHandler( 'hgroup', null );
Textile::RegisterBlockHandler( 'figure', null );
Textile::RegisterBlockHandler( 'figcaption', null );
# End of file.
@netcarver
Copy link
Author

netcarver commented Jan 23, 2011

Experimenting with HTML5 support via a textplug.

The glyph indexing is in need of some work to make it more accessible to textplugs. Perhaps an interface is needed to control and extend the glyphs. In fact the tag HTML5 could be generalised to a glyph replacement modifier. Something like...

glyph(name.replace). replace regex

...or...

glyph(name.match). match regex
glyph(name.replace). replace regex

So our example for acronym => abbr. (with existing indexing) might become...

glyph(6.replace). <abbr title="$2">$1</abbr>

To remove an unwanted glyph, you might do...

glyph(name). Off

...so killing the caps around 3+ uppercase runs would be turned off with something like...

glyph(capspans). Off

The span markup patterns and replacements could be extendible if they were pulled out of the span() routine too.

@netcarver
Copy link
Author

netcarver commented Jan 23, 2011

Actually, an interface to the glyphs and spans would be better -- then core could change the implementation if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment