sgmllib nit
Fredrik Lundh
fredrik at effbot.org
Sun Dec 10 05:34:06 EST 2000
Robin Becker wrote:
> I realise that it does that! Unfortunately Zope's dtml isn't HTML.
after a bit more research, I found this little piece of text from
the SGML specification:
If "SHORTTAG YES" is specified on the SGML declaration,
the name and [the separator] can be omitted if the
attribute value specification is an undelimited name token
that is a member of a group specified in the declared value
for that attribute.
or in other words, you can leave out the *attribute name*, not
the value...
(this is why you cannot use the same enumeration value for
more than one attribute in the same tag)
...so if DTML expects
<dtml-var standard_html_header>
to mean
<dtml-var standard_html_header=''>
instead of
<dtml-var standard_html_header='standard_html_header'>
it's neither SGML, HTML, nor XML.
> Which parser should one use to analyse dtml which can contain tags like
> <dtml-var standard_html_header>?
dtmllib?
I suggest asking the Zope folks if/why they're using an embraced
and extended syntax, and what parser they recommend...
if you want to fix this in sgmllib, the id hack is way too ugly
-- better move
if not rest:
attrvalue = attrname
elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
attrvalue[:1] == '"' == attrvalue[-1:]:
attrvalue = attrvalue[1:-1]
attrs.append((string.lower(attrname), attrvalue))
into a separate method, and override it from a dtmllib module.
another way to solve it (in dtmllib) would be to have a map of
attributes that are supposed to be minimized (derived from the
DTML DTD). just use a simple dictionary:
minimize = {
("dtml-var", "standard_html_header"): 1,
...
}
...
if attrname == attrvalue and minimize.has_key((tag, attrname)):
out.write(" %s" % attrname)
else:
out.write(" %s=%s" % (attrname, repr(escape(attrvalue))))
...
> I guess I need to write my own parser that doesn't make unnecessary
> assumptions.
well, if you think that assuming SGML is an "unnecessary assumption"
for something called sgmllib, there's not much I can do to help.
</F>
More information about the Python-list
mailing list