glossary preformater
Lee Joramo <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
I have created a preformatter that does glossary substitutions similar
to "shortcuts" in Radio Userland.
The basic idea is that glossary words will be replaced by specified
text. For example, I have created a glossary entry:
{joramo}
which is replaced with the link to my web site:
<a href="http://www.joramo.com">Lee Joramo</a>
Below you will find the glossary.py (the preformatter code),
glossary.txt (the glossary substitution file, and a sample blog entry.
Question: in glossary.py, I use a full file spec for glossary.txt. Is
there a better way to do this? Where would be the best location to
store the glossary.txt file in pyblosxom's directory? I also don't
quite understand the preformatter mechanism. Can there only be one
formatter specified in the pyblosxom configuration? I wrote this code
while offline, so I suppose if I was online, a quick search would
answer this question....
Any comments and suggestions most welcome.
Lee Joramo
www.joramo.com
---glossary.py--START---
# Lee Joramo
# www.joramo.com
#
# implements a glossary subsitution system similar to
# the one found in Radio Userland
#
from libs.preformatters.base import PreFormatterBase
import string
class PreFormatter(PreFormatterBase):
def __init__(self, text = ''):
self.text = ''.join(text)
def parse(self):
result = self.text
glossary = getGlossary()
for word in glossary.keys():
result = string.replace(result, word, glossary[word])
return result
def getGlossary():
glossary = {}
f =
open('/Users/ljoramo/Sites/cgi-bin/blog/libs/preformatters/
glossary.txt', 'r')
line = f.readline()
while line:
line = line.strip()
if line == "":
# empty lines
pass
elif string.find(line, "#") == 0:
# comment line
pass
else:
linesplit = line.split("\t")
glossary[linesplit[0]] = string.join(linesplit[1:], "/t")
line = f.readline()
f.close()
return glossary
---glossary.py--END---
---glossary.txt--START---
#Lee's Glossary
# blank whitespace lines ignored
# lines with a leading # are ignored
# all other lines are in the format:
# [keyword][TAB][replacement text]
# it is a good idea to use some special formating
# to distinish keywords, so that you do not get
# unexpected subsitutions. If you created a glossary
# for the word "red" (without quotes) then all
# occurances of the string "red" would be replaced
# including those within HTML or withing words such
# such as "hundred".
# To mark my glossary words, I prefer to use {curly}
# braces around my keywords. However, if you are
# trying to be compatible with Radio Userland,
# you will need to use "double quotes"
# LINKS
{joramo} <a href="http://www.joramo.com">Lee Joramo</a>
{uuus} <a href="http://www.uuus.org">UUUS</a>
{google} <a href="http://www.google.com">Google</a>
# IMAGES
{joramo.jpeg} <img
src="http://www.joramo.com/images/my/leeajoramo.jpeg" alt="Lee Joramo"
height="140" width="187">
# FORMATING
# here is the start and end of a block quote:
{quote} <table><tr><td width="15"> </td><td><i>
{quote/} </i></td></tr></table>
# BOILER PLATE
{copyright} My attorney said: Eat SPAM and EGGS Daily!
# RADIO USERLAND
# if you have a blog that used Radio, you could follow
# this example to bring over you glossary.
"radio keyword" <a href="http://radio.userland.com">Radio Userland</a>
---glossary.txt--END---
---sample blog entry--START---
Glossary for PyBlosxom
My web address is {joramo}.
{quote}
All of this text is in a block quote. Have you visited {google} lately?
<br><br>
{joramo.jpeg}
<br><br>
{copyright}
{quote/}
Glossaries are called shortcuts in "radio shortcut".
---sample blog entry--END---
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf