The link below explains how I managed to create such a beast:
http://www.zope.org/Members/alburt/dtml_mode
It relies on a DTD file to define the format of DTML code and then letting
PSGML, a package for editing SGML/XML code, do all the work.
--- Alastair Burt