View Full Version : TableManager Moon Wizard Question

October 17th, 2017, 02:49
MW, you have the following in the onTableRoll handler of the manager_table.lua file:

elseif (bTopTable or (#v.aTableLinks == 0)) then
if sText:match("^<[biu]>") then
sAddDesc = sAddDesc .. "<p>" .. UtilityManager.encodeXML(sText):gsub("&lt;(/?[phbiu])&gt;", "<%1>") .. "</p>";
elseif sText:match("^<[ph]>") then
sAddDesc = sAddDesc .. UtilityManager.encodeXML(sText):gsub("&lt;(/?[phbiu])&gt;", "<%1>");
sAddDesc = sAddDesc .. "<list><li>" .. UtilityManager.encodeXML(sText) .. "</li></list>";

This code is in the section that outputs table rolls to a story window. What it appears to do is:
1. search for bold, underlined, or italicized text, encode that text and then strip out the xml safe tags (the &lt; and &gt;) after the XML encoding.
2. do the same for paragraph and heading tags in text.
3. if the text doesn't have any of the tags, surround it with xml encoded text bounded by table tags (<list><li>)

Later, the text is then saved to the story data node.

So, the questions I have are:
1. Why encode the text with encodeXML and then go to the trouble to reverse the encoding for the text formatting tags?
2. Does the DB.setValue call with a formattedtext type field not do the xml encoding?
3. If the answer to #2 is yes, then why is it necessary to explicitly encode the generated table text in the code above?
4. If the answer to #2 is no, then how does the '<' character which is forbidden in xml (other than tags) ever get encoded since you are stripping the encoding out?

Moon Wizard
October 17th, 2017, 04:02
1. This allows people to specify formatting in their table for story output. (Just p/h/b/i/u tags) This was a feature request.
2. No, it does not. The setValue for formattedtext database nodes assumes you pass it valid XML, using FG formattedtext tags and encoded text. Otherwise, we wouldn't know which tags should be encoded, and which ones shouldn't.
3/4. If you look at the pattern matching, we are explicitly only rewriting these tags back to XML. (<p>, <h>, <b>, <i>, <u>, </p>, </h>, </b>, </i>, </u>) Thus, any other uses of the <> characters will be encoded.


October 17th, 2017, 04:27
Thanks, MW. I was thinking backwards.

October 18th, 2017, 03:03
One follow-up, MW. Why did you put paragraph markings around text markup except for headings? (obviously, you didn't want to nest them around user-inserted paragraph tags)?

Moon Wizard
October 18th, 2017, 03:06
That’s required for the internal FG formatted text format. See the formattedtextcontrol reference in the Ruleset Reference API.


October 18th, 2017, 03:49
Hey, MW, that section of the documentation seems to have an error. In the 'table' tag section it says:

table - Indicates a table. Tables can not be created or edited, only accessed via modules created outside of FG.

This leads one to think you cannot edit a table in the interface, but above that, in the list of keyboard commands is the following:

CTRL+TAB - Insert new cell in table, or assign speaker to chat text.
CTRL+PLUS - Increase column width of table cell by one.
CTRL+MINUS - Decrease column width of tabel cell by one.

Maybe I am not understanding something....

Moon Wizard
October 18th, 2017, 10:55
When the documentation gets updated, we typically upgrade the existing documentation. The note about being unable to create tables in the user interface looks like a leftover note from a time when that was true. (It was true when I started working on FG.) I’ll note it for a fix.