May 31st, 2012

So, I implemented the custom-action in PmWiki last night, and updated the WordPress plugin to match.

This is much, much better, as there is no longer a mostly-duplicated, hacked version of PmWiki floating around.

I still have to handle CSS issues, and interaction with other markup.

I’m looking at the WP-GeSHi-Highlight plugin which has some great notes on avoiding such issues:

– WP-GeSHi-Highlight filters&replaces code snippets as early as possible. The
highlighted code is inserted as late as possible. Hence, interference with
other plugins is minimized.
– If it does not find any code snippet, it does not waste performance by
senseless inclusion of highlighter libraries etc. And it does not send its
css code to the user if not necessary (others do).

This is how the plugin works for all page requests
I) “template_redirect hook”:

1) The user has sent his request. WordPress has set up its `$wp_query` object.
`$wp_query` has information about all the content potentially shown to the
2) This plugin iterates over this content, i.e. over each post, including each
(approved) comment belonging to this post.
3) While iterating over the post and comment texts, occurrences of the pattern
<pre args> CODE </pre>
are searched.
4) If one such occurrence is found, the information (args and CODE basically)
is stored safely in a global variable, together with a “match index”.
5) Furthermore, the occurrence of <pre args> CODE </pre> in the original
content (post/comment text) is deleted and replaced by a unique identifier
containing the corresponding “match index”. Therefore, the content cannot be
altered by any other wordpress plugin afterwords.
6) Now GeSHi iterates over all code snippets. For each, it generates HTML code
that highlights the snippet according to the given programming language
(with or without line numbers).
7) Additionally, GeSHi generates optimized CSS code for each snippet. All CSS
code generated by GeSHi ends up in one string.
8) For each code snippet, highlighted HTML code AND the corresponding match
index is stored safely in a global variable.

no comments yet.

comments RSS trackBack identifier URI

leave a comment

  • syndicate

    • Add to MyMSN
    • Add to MyYahoo
    • Add to Google Reader
    • Add to Bloglines
    • Add to Newsgator
    • Add to NewsIsFree