This is the first general release of my macros plugin, a highly generalized macro package modelled on (but not actually based on, code-wise) Brad Choate’s MT-Macros package.

This release includes string macros, pattern macros, tag macros (html-like tags without content, like html’s <img>) and content tag macros (html-like tags with content, like html’s <a>…</a>). String and pattern macros may be restricted to only match in content areas, not in markup. Any macro can be set to only match once per story.

See the documentation in the plugin itself, or the macro files I actually use or that I test with, for documentation and examples of the syntax.

To install:

  1. download and unzip the plugin.
  2. Copy it to your plugins directory. Make sure it’s world-readable.
  3. Create a $plugin_state_dir/.macros directory, and put macro definition files in it.
  4. Use it!
  5. Drop me a note to let me know you’re using it; if you’re having problems, let me know and I might be able to help. If everything’s working okay, please let me know that, too.

Things that are missing (not all of them appear useful, though):

  • MT-Macros ‘recursion’ option isn’t available. If this is a real problem for you, please let me know, preferably with a good example of what you can’t accomplish currently (remember, macros are invoked in the order they’re defined, which you can control with filename naming)
  • tag and ctag macros can’t be used in HTML markup. This would be a big problem for Movable Type, where parameter replacement is done with psuedo-HTML, but doesn’t seem to be a problem for Blosxom. If it is for you, please let me know, again along with an example.
  • MT-Macros ‘no_case’ option isn’t available. This can be done by including (?i) in your patterns or defining them with qr//i, instead.
  • tag and ctag macros can’t be explicitely named, because the ‘name’ parameter is already being used. Future versions may change tag and ctag to use ’string’ or ‘pattern’ for what ‘name’ is currently used for, and use ‘name’ to define a macro. That will only be done if there’s a good use for names, though.
  • Once defined, macros are always active. They can’t be deactivated on a per-story basis. This might be handled with a meta- header at some point, if someone gives me a reasonable example for why they need it.
  • There’s no built-in data-based macro definition syntax. It’s not clear to me that a literal define_macro() call is any more difficult than MT-Macros’ HTML-looking (but not HTML-acting) definition syntax, though, and as shown above simpler syntaxes ban be custom-built as appropriate. I’d be more than happy to include a simpler syntax, though, if someone were to develop one that were obviously better than define_syntax().

Plugins that I think could be replaced with this:

  • strip_unix_comments (pattern ^#.*?$ -> ”)
  • asin
  • dictionary (macro definition file that reads the dictionary file to create macros)
  • citysearchtag
  • macrolinks
  • galleryref
  • amps

Plugins that can’t be, but maybe should be — missing functionality?

  • wikiwordish (would need to be able to invoke a user function to get replacement text)
  • functions (same as wikiwordish)
  • date_fullname (would need to be able to repalce text after interpolation, and to run against date as well as story)
  • date_translate
  • seemore (would need to be able to enable/disable macro based on $path or parameter)

2 Responses

excellent!

plugin evolution like this is good to see.

j.

This macro makes it simple to add a Creative Commons license notification in a story.

Leave a Response

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">