-
Notifications
You must be signed in to change notification settings - Fork 1
Common Problems
These are some common problems:
- You find
internalHtmlVal=/HTML/=
in the generated HTML - Your element tags are being escaped with values such as
<p>
- Value of x, element 0-based index y had an unsupported type
This value is part of the internal representation of HTML elements. They are useful while developing and debugging but they are not meant to be displayed in the end result.
Here are some possible causes.
Not calling MarkupGen_html_toText
Make sure that you call MarkupGen_html_toText
after generating all HTML elements. Also, make sure you call it only once on a top-level expression rule and not inside a nested expression rule.
For XML generation, you need to call MarkupGen_xml_toText
.
Calling concat or concatenating with & before calling MarkupGen_xml_toText
/* Code with problem */
Markupgen_html_totext(
markupgen_html_newelem("b", null, "Description: ") & "Some text"
)
Solution: replace the & or concat with an array:
Markupgen_html_totext(
{
markupgen_html_newelem("b", null, "Description: "),
"Some text"
}
)
If the final output after calling MarkupGen_html_toText
contains something like this:
<p>
but you expected
<p>
This means that the HTML elements were first converted to text and then passed to MarkupGen_html_toText
.
Although this problem may occur to you, especially while you get used to the plugin, the behaviour is one of the strengths of this plugin. Escaping by default instead of manually calling rules for escaping text is a better position to be in, especially when user input is included inside the HTML content.
Possible causes are as described below.
Concatenating an HTML element
There may be text concatenated with an HTML element, like in the following example:
/* Code with problem */
MarkupGen_html_newElem("p") & "Some Text"
or concatenated with the concat function
/* Code with problem */
concat(MarkupGen_html_newElem("p"), "Some Text")
Solution: turn these contents to an array
{
MarkupGen_html_newElem("p"),
"Some Text"
}
Note that you will need to call MarkupGen_html_toText
with those results somewhere in the code to properly turn the internal representation to text. In the previous example, if all we had were those two elements then we could call MarkupGen_html_toText:
MarkupGen_html_toText(
{
MarkupGen_html_newElem("p"),
"Some Text"
}
)
You passed the result of MarkupGen_html_newElem
to a rule with input of type Text
Consider the case of a rule, rule1, that has input contents as Text:
MarkupGen_html_toText(
{
rule!rule1(
contents: MarkupGen_html_newElem("p")
),
"Some other content"
}
)
When calling rule!rule1
, the value of contents will first be converted to text. When calling MarkupGen_html_toText
all text values will be escaped.
In order to fix this, change the rule input type to Any Type, or under certain circumstances to MarkupGen_HtmlPart or an array of MarkupGen_HtmlPart.
A value of an unsupported data type was passed in to the contents of an HTML element. For instance:
/* produces error*/
Markupgen_html_totext(
MarkupGen_html_newElem("p", null,
{
"Message sent on :",
date(1970, 1, 1) /* problematic */
}
)
)
produces the following error:
Expression evaluation error at function 'MarkupGen_html_newElem':
java.lang.RuntimeException: Value for 'contents', element of 0-based index 1
had an unsupported type [Date]
Cause
Values such as date or date/time are not supported.
Only an HTML part, text, a number or an array of any of those is allowed.
Solution
Convert non-supported types to Text. For instance, to convert a date to text you may use the datetext function.
The previous example can be changed to:
Markupgen_html_totext(
MarkupGen_html_newElem("p", null,
{
"Message sent on: ",
datetext(date(1970, 1, 1), "yyyy-MM-dd")
}
)
)