Thanks to several google-translated Japanese Movable Type blog entries [makotokw, kazuno, and tadateto], I've finally figured out how to hack MT to get python code pretty-printed. (To read these Japanese articles, I recommend searching using google and then pressing Translate this page.) The code is downloaded from google and the original idea was from Thomas Guest.
To get this to work, you have to do four things:
- Add google's prettify.css stylesheet to your header page template
<link rel="stylesheet" href="/mt-static/css/prettify.css" type="text/css" />
- Add google's prettify.js JavaScript to you header page template
<script type="text/javascript" src="/mt-static/js/prettify.js"> </script>
- Get your body.onload to call prettyPrint()
<body class="mt-main-index layout-wtt" onload="prettyPrint();">
- Mark the sections that you want pretty-printed
<pre class="prettyprint">
The third step is the most involved. You have to change three templates:
- Page
<MTSetVar name="body_onload" value="prettyPrint();"> <MTIfCommentsAccepted> <$MTSetVar name="body_onload" value="prettyPrint();individualArchivesOnLoad(commenter_name)"$> </MTIfCommentsAccepted> - Entry
<MTSetVar name="body_onload" value="prettyPrint();"> <MTIfCommentsAccepted>< $MTSetVar name="body_onload" value="prettyPrint();individualArchivesOnLoad(commenter_name)"$> </MTIfCommentsAccepted> - Comment Preview
<MTSetVar name="body_onload" value="prettyPrint();individualArchivesOnLoad(commenter_name)">
2008-06-27: Did I say three templates? I meant five. Here are two more templates to change:
- Search results
<MTSetVar name="body_onload" value="prettyPrint();">
- Archive index
<MTSetVar name="body_onload" value="prettyPrint();">

Leave a comment