Code transform
Programming code and computer input files have one thing in common. They are best read in monospace fonts. It’s lovely if you know the line numbers too—particularly helpful in making references. I have two kinds of input files from different types of structural analysis software:
- SACS input files are in a fixed format. Column sensitive information.
- SESAM, USFOS and ABAQUS input files are in a free format. Column insensitive information.
I wanted a simple solution to display my structural analysis input files—for some articles I have restarted working on—without modifying them or embedding them within the post markup, albeit painfully. So I turned to Dunstan’s tag transformations. Mathias Bynens wrote a plugin—based on Dunstan’s tag transformation, which also includes image transformation. I didn’t need the image transformation bit, so I edited Bynens’s plugin to include only the code transformation.
How it works: I upload an input file or input file snippet—say filename.txt—to a folder called inputfiles in the root. Then, in the article, I add the following code—to display the input file, together with line numbers (auto-generated via the plugin):
<codeins="filename" />
Download: The edited plugin is here, if you’re interested.
Install and use: Rename the downloaded file to code-transform.php and upload to your WordPress plugin folder (wp-content/plugins/). Go to the Plugins page, and activate “Code transform” plugin. That’s all.
Important note: For this plugin to work, you will need to uncheck “WordPress should correct invalidly nested XHTML automatically.” under Options > Writing.
A demo of this plugin can be seen here.
Presentation style [update]: You may use Dunstan’s CSS code to style the displayed code in your post. Just copy the CSS code and paste it in style.css in your active theme folder.
