TidyTags

This script looks for all MT tags (in any supported format) and replaces them using the following standard:

  • lowercase prefix with a colon: mt:
  • CamelCase tag name
  • dollar signs wrapping function tags
  • slash for all closing block tags

If an unknown tag is found the tag will be modified:

  • lowercase prefix with a colon “mt:”
  • a closing forward slash if the tag had one
  • and a html comment added as a suffix: <!-- unknown tag -->

Example

If you had a bunch of code in various different formats (and even some imaginary tags) such as this:

<MTEntries>
    <MTEntryTitle>
    <$MTEntryBody$>
    <mt:EntryPermalink>
    <MTFakeTagHere>
</MTEntries>

It would be converted to:

<mt:Entries>
    <$mt:EntryTitle$>
    <$mt:EntryBody$>
    <$mt:EntryPermalink$>
    <mt:FakeTagHere><!-- unknown tag -->
</mt:Entries>

Please note:

  • This is not a Movable Type plugin, it is a command line tool to “tidy” template tags in text files.
  • With simple modification, this script will work with future releases of Movable Type as well as with template tags created by plugins. All that is required is to add the additional template tags to the script under function or block, respectively. If not added

Usage

  • Many files w/ back up

    perl -pi.orig MTTidyTags.pl *.mtml
    
  • Single file w/ back up

    perl -pi.orig MTTidyTags.pl file.mtml
    
  • Overwrite file

    perl -pi MTTidyTags.pl file.mtml
    

Download

Revision History

v1.6 - 2008 Jun 19
Adding Tags from MT Community Solution and MT Professional Pack
v1.5 - 2008 Jun 19
Added code (uncommented by default) for using script as TextMate command.
v1.4 - 2008 Jun 18
Fixed issue with adding an extra “$” to the end of `<__trans phrase="Phrase">` tags.
v1.3 - 2008 Jun 12
Fixed issue with script not converting some tags containing attributes using code ported from TypePad
v1.2 - 2008 Jun 09
Added case for non-core/unknown tags
v1.0 - 2008 May 28
Initial Release
Compatible with Movable Type 4.15 and older

Authors

5 Comments

I’ve wanted this forever, thanks Beau (I’d been forced to convert mine using Brad’s old script, one-by-one!)

I hope to see it as a plugin form in the future - something that populates an itemset action on the template listing so I can just check templates I would like to normalize :)

@arvind - thx, good call, I should convert this to a “more items…” menu item. Perhaps during an upcoming hack-a-thon.

If you have tags that are not listed in the script, the tags will be replaced with “”, less than ideal. Thinking of updating the script to ignore tags it’s not aware of and/or to place a html comment (<!— Unknown Tag —>) after the tag.

@arvind ยป actually I forgot that the plugin you seek already exists, Tim Appnel’s MTTidy which does the same thing.

I wanted a way to “tidy” the templates w/o needing to use Movable Type, thus this script was conceived.

I’ve been doing this exact stuff by hand quite a bit with my templates recently. Thanks so much for putting this script together! :)

Leave a comment