3
votes

Having a issue with a razor macro in Umbraco 4.11.10 which really has me stumped,

The problem:

Having html elements inside a textbox multiline field "breaks" attribute boundary's when executing the razor script.

More details:

The basic macro has a textbox multiple field which is passed into the razor script as a parameter.

With plain text this works great but a recent requirement requires tags being added to this text at various points.

What I have tried:

Initially I tried escaping the html like this

>sup<1,2>/sup<

This worked great until I reloaded the node and republished, when looking in the db, it seems the first time the macro is saved, the correct escaped html is included as the macro parameter:

description="(text here)>sup<1,2>/sup<(more text)" ...

When the node is reloaded the rendered output is the actual html characters (assuming this is decoded before being displayed in the umbraco backend).

<sup>1,2</sup>

which when republished is passed "as is" to the Razor macro.

 description="SINGLE (n=833) <sup>1,2</sup>

This then outputs from the end of the first html tag to the end of the macro parameters as its output:

<p> ***+ ***vs ***(Should Stop Here)" hideBorder="0" preview="0" /></p>

which should be

blah blah blah + **vs *(Should Stop Here)" hideBorder="0" preview="0" />

The Question:

My question is, is there any way to add html elements to a textbox multiple when used as a razor parameter, or a way to stop the decoding when the node is reloaded.

Because of legacy and the impact I would prefer not to change the macro/parameters if at all possible but if its a must its a must.

Thanks for taking the time to read!

2

2 Answers

4
votes

I had a similar problem where I wanted HTML/Javascript to be directly inserted into the RTE via a macro that took textMultiLine as a parameter.

The solution to get the tags out without them being escaped was:

@Html.Raw(HttpUtility.HtmlDecode(Parameter.Code));
1
votes

In the end I decided to use a helper function with RegEx to replace custom html element keys for example $gt$ for > and $lt$ for <.

$lt$span$gt$1,2,3 $lt$/span$gt$

Its a ugly solution but saved me having to revert to multiple DocTypes(instead of the macros) or RichTextEditor properties which would of also solved the problem.

Hopefully it might save someone from having to waste as much time as I did on it.