closing html tags in comments & strings

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
80083r
Kobold
Posts: 19
Joined: Tue Jan 04, 2011 11:24 pm

closing html tags in comments & strings

Post by 80083r »

Not sure how to word this, I normally wave my hands in the air and draw pictures.
I was trying to build some strings for formatting like so:

Code: Select all

[h: headingDv = strformat('<div style = "width:auto; background-color:#C0C0C0; color:#000000; margin:0px; padding:3px; font-size:1em; font-weight:bold;">')]
[h: textDv = strformat('<div style = "width:auto; background-color:#EEEEAA; color:#000000; margin:0px; padding:2px; font-size:1em;">')]
[h: dvEnd = strformat('</div>')]
and then building a string with these bits - so I can reuse the same format on mulitple <div> blocks. I assume that's fairly common, but every time I ran the macro, there was a whitespace output.

...because there's an open <div> in the STRING BUILDER, that isn't closed IN ANOTHER STRING. ARGHGHAGHASDFHH!!@#$!@#$!!! (humourous anger intended).

It took a good long while to track down the solution, seen here:

Code: Select all

[h:"<!-- every string that has <div> or <span> in it (including THIS COMMENT!) must have a matching </div> or </span> -->"]
[h:"<!-- otherwise, a blank line of output is created. -->"]
[h:"<!-- so if you create a string with an opening tag in it, you MUST close that tag, even if it doesn't display anywhere -->"]

[h: headingDv = strformat('<div style = "width:auto; background-color:#C0C0C0; color:#000000; margin:0px; padding:3px; font-size:1em; font-weight:bold;">')]
[h: dvEnd = strformat('</div>')]
[h: textDv = strformat('<div style = "width:auto; background-color:#EEEEAA; color:#000000; margin:0px; padding:2px; font-size:1em;">')]
[h:"<!-- </div> -->"]
tl;dr: EVERY html element that is made, ANYWHERE, needs a CLOSING tag somewhere later, regardless of what kind of construction it's buried in.

p.s. If I'm wrong, please gosh correct me, but this was the solution I ended up with.

p.p.s. v1.11.5

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: closing html tags in comments & strings

Post by wolph42 »

you're partially right. The biggest reason for whitespaces on execution of a macro are <!-- comments --> these ALWAYS render a whitespace if there is no further output. The only way to prevent that from happening is:
[h:'<!-- comment -->'] ('single' or "double" quotes are equally fine).

After that if code still produces whitespaces, you indeed need to check the html output. Im not sure that the <div> is the sole cause, i think its sooner the comments that were the issue, the <div> might have been an additional issue.
hence im failry confident that if you remove the line:
[h:"<!-- </div> -->"]
you still don't get a whitespace

80083r
Kobold
Posts: 19
Joined: Tue Jan 04, 2011 11:24 pm

Re: closing html tags in comments & strings

Post by 80083r »

I did TEST that before I posted.

Check it out:

Code: Select all

[h: "<!-- <div> -->"]
will produce a line in chat.

Code: Select all

[h: "<!-- <div> -->"]
[h: "<!-- </div> -->"]
will not


...the code in the first post is still very, very bad. I was on about 14 hours of caffeine and communicating frustration that is unwarranted. Maptools is AWESOME, especially at this price point.

in the end, I just made the strings to include the stuff between the quotes in the <style> tag.

Code: Select all

[h: headingDv = "width:auto; background-color:#C0C0C0; color:#000000; margin:0px; padding:3px; font-size:1em; font-weight:bold;"]
and then I can add more style elments if I need some extras... I'm basically trying to work around not having CSS available in the chat output.

p.s. big fan of what you have accomplished with the bag of tricks. Many of your posts in this forum have helped me a lot.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: closing html tags in comments & strings

Post by wolph42 »

ok that is new to me. Thank you for bringing that to my attention. I guess its a breakpoint of the parser for some obscure reason.

Post Reply

Return to “Macros”