Monthly Archives: October 2010

Embedding mediawiki templates inside <pre>

I’ve experimented with this a few times, but never found something that works.  My intent was to use some mediawiki templates inside code/file samples on the wiki. On the wiki, we typically use <pre> tags to properly format code/file samples. By definition, the html <pre> tag allows for pre-formatted text to be displayed as-is.  Meaning, most html tags inside <pre> will be displayed and not processed. There are exceptions for some font mark-up tags, but I’m not fully aware of which html tags are explicitly allowed inside <pre>.  Let’s try an example using the following html markup …

This is <strong>bold <span style="color: red;">red</span></strong> text
<a href="#link">This is a link</a>
<span style="color:green;
                font-family:'Times New Roman', Times, serif;
                font-weight:bolder;">big and green times</span>

This will display in a browser as …

This is bold red text
This is a link
big and green times

Introducing mediawiki into the mix complicates things slightly. By design (as security precaution I’d guess), mediawiki does not honor all HTML tags on a wiki page. However, it does recognize and permit some tags, <pre> being one of them. As noted previously, we use the <pre> quite a bit to call out command execution or file contents.

Where the wrinkle comes is trying to use mediawiki templates inside a <pre> block. Well why would you want to do that? Often, our command samples or file contents include Fedora release version specific information. Since Fedora releases come out about every 6 months, for every wiki page that doesn’t need to reference an explicit Fedora release, someone would need to modify every wiki page that references a Fedora version. At a quick glance, that comes to about ~179 wiki pages. As I mentioned, not all of those pages would need an update when a new release comes out, but it at least gives a rough estimate.

After some searching, I came across a forum post which recommends a solution that works. To demonstrate using a mediawiki template inside a <pre> block, I’ll use the wiki page Creating_a_Test_Day_Live_Image. On that page, we recommend checking out a git branch of spin-kickstarts whose name matches the upcoming Fedora release. I’d like to use the FedoraVersion template so we don’t need to constantly update this page each time a new version of Fedora is released.

To make use of the FedoraVersion mediawiki template inside a <pre> block, you would enter the following …

git clone 'git://' -b F-{{FedoraVersion|number|next}}

This instructs mediawiki to format the page as follows:

git clone 'git://' -b F-14

I have no idea why the magic combination of noinclude mediawiki tags works. Bonus points to anyone who can answer: why does this work?