• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

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!

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2013 Mar 22, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 25, 2013 Mar 25, 2013

Copy link to clipboard

Copied

Thank you. You gave a very clear description of our problem. Do you think it's possible to construct an adequate Reg Ex for this case?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 25, 2013 Mar 25, 2013

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2013 Mar 27, 2013

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 27, 2013 Mar 27, 2013

Copy link to clipboard

Copied

Go to cflib.org and look for a function called safetext().  You may find it helpful.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2013 Mar 27, 2013

Copy link to clipboard

Copied

Thank you, Dan. This is actually a great function. I had to write my own (much more simple one) for the same text cleaning purpose. Good to know! Unfortunately, it does not help with my current problem: it strips out listed HTML and Java events but it does not strip the plain single right angle braket. I'm afraid I want too much from my CF 9.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 25, 2013 Mar 25, 2013

Copy link to clipboard

Copied

Thank you for your reply. Yes, using a regular expresion is what I was thinking about too. But it seems to be pretty hard to construct a reg ex without simply looking for "<" and ">" pair. Can you suggest the one that would differ "less than" from the HTML tag opening?

As for the formatting details, Dan Bracuk below gave a great description:

"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."

Our users need to be able to place, for ex., <li> that will be displayed by a browser as a bullet point not as "<li>" text. At the same time they want to use a single "<" in the meaning of "less than".

I appreciate your thoughts and advice.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 21, 2013 Mar 21, 2013

Copy link to clipboard

Copied

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

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

Unless I misunderstood what you're asking.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 22, 2013 Mar 22, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 25, 2013 Mar 25, 2013

Copy link to clipboard

Copied

Unfortunately, it's not that simple. We can not replace ALL of the "<" instances. We need to replace only those that are NOT the opening angle braket of an HTML tag. We have to find a way to distinguish a single "less than" sign from a part of HTML.

I would appreciate any suggestions you might have.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation