[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]
[wml] Handling unknown attributes
- From: Denis Barbier <nospam@thanx>
- Date: Sun, 9 Jul 2000 00:40:48 +0200
On Wed, Jul 05, 2000 at 11:40:39AM +0000, Jan Holler wrote:
[...]
> > I'll give another example which I programmed yet:
> >
> > <ptable> is a container for a table made of photos and text.
> > <ptable:text> is used to put text in one of this cells.
> > <ptable:pic> is used to put a picture in one of this cells.
>
> O.k. I use to work with tables straight away at the basic
> HTML-code because I need the following <TD>-features quiet often:
> BGCOLOR
> BACKGROUND
> ALIGN, VALIGN
> STYLE (Netscapes 4.x CSS-implementation is sometimes a pain)
> I think it's more powerful to use basic-HTML coding instead
> of "makros" which sometimes do not have the necessary
> extensions available.
[...]
I work on this topic for a week now after a suggestion by Ralf, and
have good results. The idea is to allow any attribute without having
to know all valid names.
For instance, say we want to define our own macro to write hyperlinks:
<define-tag hyperlink whitespace=delete>
<preserve url>
<preserve text>
<set-var %attributes>
<defvar text "<get-var url>">
<a href="<get-var url>"><get-var text></a>
<restore text>
<restore url>
</define-tag>
If we want to add CSS support, we have to explicitly preserve/restore
new attributes, and write them into <a> tag.
Mp4h version 1.0.4 introduces 3 new tags to play with attributes:
<attributes-remove name1,name2,... %attributes>
Like %attributes, but remove variables whose name is one of
name1, name2, and so on.
<attributes-extract name1,name2,... %attributes>
Prints only the name=value pair matching names name1, name2,...
<attributes-quotes %attributes>
The two macros above gobble quotes like any other mp4h macros.
This one prints its attributes with value between quotes. It must
only be used when printing its content on output without any
further processing.
Here is a version suitable for mp4h 1.0.4:
<define-tag hyperlink whitespace=delete>
<preserve url text>
<set-var <attributes-extract url,text %attributes>>
<defvar text "<get-var url>">
<a <attributes-quote <attributes-remove url,text %attributes>> \
href="<get-var url>"><get-var text></a>
<restore url text>
</define-tag>
<hyperlink url="http://..." class=www>
The <preserve>/<restore> commands now accept any number of arguments,
which make this definition much more readable and easy to maintain.
The line
<set-var <attributes-extract url,text %attributes>>
sets only `url' and `text' variables if they appear in %attributes.
And
<attributes-remove url,text %attributes>
remove these 2 variables from %attributes, so this expression expands
to
class=www
I put this expression within <attributes-quote> to ensure that all
name=value pairs are quoted as they should be (but quotes within text
value are not escaped in current implementation).
Next step is to add an `image' attribute:
<define-tag hyperlink whitespace=delete>
<preserve url text image>
<set-var <attributes-extract url,text,image %attributes>>
<defvar text "<get-var url>">
<a <attributes-quote <attributes-remove url,text,image %attributes>> \
href="<get-var url>">
<if <get-var image>
<img src="<get-var image>" alt="<get-var text>">
<get-var text>>
</a>
<restore url text image>
</define-tag>
<hyperlink url="http://..." class=www image=foo.gif>
But there is a trivial flaw in this implementation, we have to choose if
unknown attributes go into <a> or <img>.
So there must be a way to specify to which tags each unknown attribute
is for. The only solution i found is to use namespaces, e.g.
<hyperlink url="http://..." image=foo.gif
a:class=www img:id=foo>
But namespaces must be removed from output, previous example must expand
into
<a class="www" href="http://...">
<img id="foo" src="foo.gif" alt="http://...">
</a>
I hope it will work soon, but if you have any suggestion i will be glad
to hear of them.
--
Denis Barbier
WML Maintainer
______________________________________________________________________
Website META Language (WML) www.engelschall.com/sw/wml/
Official Support Mailing List sw-wml@engelschall.com
Automated List Manager majordomo@engelschall.com