Skip to main content
Known Participant
March 21, 2013
Question

How do I preserve '<' and HTML tags in my output?

  • March 21, 2013
  • 2 replies
  • 2350 views

Our clients tend to enter both single angle brackers (i.e. "hours <4") and the HTML tags into a form field. We can not use HTMLEditFormat() on the field since they want their formatting preserved. At the same time, using a single bracket trancates the field output.

Is there a way to distinguish  a single "<" from the beginning of an HTML tag so we can internally substitute it with &lt;?

Thanks for your advice!

This topic has been closed for replies.

2 replies

Known Participant
March 22, 2013

<cfset newvalue = #ReReplace(yourinputfield,"&lt;","<","ALL")#>

That will replace ALL instances of a <  with &lt;

Unless I misunderstood what you're asking.

Participating Frequently
March 22, 2013

What exactly you want to do? can you explain more detail's.

glamorous_Wonder6C1C
Inspiring
March 21, 2013

I am not sure what do you want so say by "We can not use HTMLEditFormat() on the field since they want their formatting preserved".

But it seems that you can take help of regular expression.

First you have make a regular expression for detecting html tag. If make not of that expression you will get everything except html and for that you need to replace "<".

Anyway it will helpfull if you provide some more details regarding formatting.

Inspiring
March 22, 2013

Regarding - We can not use HTMLEditFormat() on the field since they want their formatting preserved.

If data is entered into a rich textearea, it will have html tags such as <b>.  Every line break will be create <p></p>.  If you output this using HTMLEditFormat(), or not only will these tags not function, but they will display.

It's a difficult question.

el_simAuthor
Known Participant
March 27, 2013

I usually request my client's to enter data in an editor (which operates in 1 of 2 modes, 'editor' and 'code')

In editor, they are writing the "content", so entering "hours < 4" would be written into the "code" side of the editor as "hours &lt; 4" automatically.  (ColdFusion's xmlFormat() can convert special characters like this into the proper equivalence.

If they are in 'code' mode, then they are writing the 'behind the scences' code, not the content.  In that mode, writing 'hours < 4' would be invalid, since the '<' tag is explicitly seen as the opening of a tag.  To make this easier on clients, most of the time, we disable 'code' mode and only let the use the 'editor' mode (relying on the editor to make clean, HTML5-validated code based on their use of it).

In the event you need to handle '<' tags when in a 'code'  view, I can see how RegEx's would be a good solution, but I (offhand) can't see how it can logically determine if a 'proper amount of opening and closing tags' are provided, as someone entering:

<p>I am > the sum of my parts, but < the least valuable.  Code is > great!</p>

Shows that there can be a random number of 'opening/closing' tags, even though in this case, they were 'supposed' to be interpreted as &lt; and &gt;


Editor is a very good idea. We are using it in a couple of other places. But we can not place an editor into this particular problematic one: our users like to cut-n-paste their pre-formatted descriptions into this field so the editor would create an additional hassle/obstacle for them. Thanks for your input!