There are a couple of instances of scripts out there that automatically apply abbr and acronym tags to pages, but I wanted to be able to do the same in ecto. This is also the first time I wrote a plugin script for ecto, and I wanted to do it in python.

Please note that this here script is untested until I get onto my Mac and test the hell out of it.

The script works, with the caveat listed in TODO.

#! /usr/bin/env python

'A script for ecto that adds abbr and acronym tags to the text'

TODO = '''
Fix it so that acronyms without a space either side (for example,
that finish a sentence) work.

Lookup on the internet for a list of acronyms/abbreviations?
'''

acronyms={'WYSIWYG':'What You See Is What You Get',
          'DOM':'Document Object Model'}
abbrs={'XHTML':'eXtensible HyperText Markup Language',
       'NSLU2':'[Linksys] Network Storage Link (USB) 2.0'}

# Add more values to your hearts content…

# get input data - depends on implementation.  For ecto:
import sys
data = open(sys.argv[1]).read()

# replace only the first instance of each acronym/abbreviation
for each in acronyms:
    data.replace(' '+each+' ', '<acronym title="'+acronyms[each]+'">'+each+'</acronym>',1)
for each in abbrs:
    data.replace(' '+each+' ', '<abbr title="'+abbrs[each]+'">'+each+'</abbr>',1)

#return data to ecto
open(sys.argv[1],'w').write(data)

Note: Comments turned off: too much Spam on this entry.

  RSS Feed for Comments on this Post