I've been doing some experimenting (and rewriting my %HTML.r script...)
and came across this interesting behaviour for 'build-tag:
>> build-tag [BODY BGCOLOR #FFFFF0 TEXT #000000 LINK #CC0000 VLINK
#330099 ALINK #FF3300]
== <BODY BGCOLOR="FFFFF0" TEXT="000000" LINK="CC0000" VLINK="330099"
ALINK="FF3300">
That looks OK, until I realised the "#" was missing. I could do it this
way:
>> build-tag [BODY BGCOLOR "#FFFFF0"]
== <BODY BGCOLOR="#FFFFF0">
But that offends me. I also tried this:
>> build-tag [/BODY]
== <="BODY">
For a closing tag, that's really strange. :-/
>> source build-tag
build-tag: func [
"Generates a tag from a composed block."
blk [block!] "Block of parens to evaluate and other data"
/local m out
][
blk: compose blk
out: copy ""
foreach item blk [
append out rejoin either not word? item [[{="} item {"}]
] [[" " item]
]
]
to-tag trim out
]
Then I noticed the extra uneeded local word 'm in the source for
build-tag. So I decided to rebuild 'Build-tag like this:
StartTag: function [
Name [string!] {Name of tag eg HTML BODY TABLE}
/Attributes
TagAttributes [block!] {Block of attributes for tag.}
][
TagContent
][
ToTagString either Attributes [
TagContent: copy Name
TagAttributes: compose TagAttributes
foreach TagAttribute TagAttributes [
append TagContent join {} either not word? TagAttribute [
[{="} either issue? TagAttribute [mold
TagAttribute][TagAttribute]
{"}]
][
[" " uppercase to-string :TagAttribute]
]
]
trim TagContent
][
Name
]
]
This seems to work well, except for end tags, but I have a special
function for that:
EndTag: func [Name [string!]][ToTagString join "/" Name]
Which works really well with:
Tag: function [
Name [string!] {Name of tag eg HTML BODY TABLE}
Content [block! string!] {What's between start and end tags.}
/Multi-Line {Separate tags by newlines.}
/Attributes
TagAttributes [block!] {Block of attributes for tag.}
][
Multi-Line?
][
Multi-Line?: func [][either Multi-Line [newline][""]]
rejoin [
Multi-Line?
either Attributes [StartTag/Attributes Name TagAttributes][StartTag
Name]
either any [string? Content empty? Content][Content][Rejoin Content]
Multi-Line?
EndTag Name
]
]
and
EndlessTag: func [
Name [string!] {Name of tag eg HTML BODY TABLE}
/Attributes
TagAttributes [block!] {Block of attributes for tag.}
][
rejoin ["^/" either Attributes [StartTag/Attributes Name
TagAttributes][StartTag Name]]
]
So, could:
either issue? TagAttribute [mold TagAttribute][TagAttribute]
or something similar, be inserted into build-tag and the extra local
word be removed?
And instead of this:
>> build-tag [/BODY]
== <="BODY">
Have this:
>> build-tag [/BODY]
== </BODY>
Andrew Martin
Who's practising rambling bug reports...
[EMAIL PROTECTED]
http://members.xoom.com/AndrewMartin/
Online @ 33,600 Baud!
-><-