Solved

How can I keep <sup>whatever</sup> & <sub>whatever</sub> html tags in my coldfusion string but get rid of all other html tags?

Posted on 2016-08-06
5
56 Views
Last Modified: 2016-08-07
How can I keep <sup>whatever</sup> & <sub>whatever</sub> html tags in my coldfusion string but get rid of all other html tags?
0
Comment
Question by:brihol44
  • 3
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 41746371
Right before you strip the tags replace the sup tags with some character that doesn't exist in the string like a [ and a ] so it looks like
[sup] and [/sup].
Then strip the tags.
Then replace the [sup] and [/sup] 
with <sup> and </sup>.

Open in new window

0
 

Author Comment

by:brihol44
ID: 41746482
Nice! Have it working but is there a way to condense this code wise? Is there a delimiter to do something like... <cfset editedValue = REReplace(editedValue, "<sup>|</sup>", "|", "ALL")> (only for conveying to you) to condense the code? Or is this just handled like "ReReplace(REReplace(...." just curious if there's a pre-defined delimiter.

Thank you!

<cfset editedValue = "<sup>Hello!</sup>" >
<cfset editedValue = REReplace(editedValue, "<sup>", "[sup]", "ALL")>
<cfset editedValue = REReplace(editedValue, "</sup>", "[/sup]", "ALL")>
<cfset editedValue = REReplace(editedValue, "<sub>", "[sub]", "ALL")>
<cfset editedValue = REReplace(editedValue, "</sub>", "[/sub]", "ALL")>
<cfset editedValue = REReplace(editedValue, "(<[^>]*>)", "", "ALL")>
<cfset editedValue = Replace(editedValue, "[sup]", "<sup>", "ALL")>
<cfset editedValue = Replace(editedValue, "[/sup]", "</sup>", "ALL")>
<cfset editedValue = Replace(editedValue, "[sub]", "<sub>", "ALL")>
<cfset editedValue = Replace(editedValue, "[/sub]", "</sub>", "ALL")>

Open in new window

0
 

Author Closing Comment

by:brihol44
ID: 41746485
Thank you!
0
 

Author Comment

by:brihol44
ID: 41746487
oops. my example was not wrapped by code tags...
<cfset editedValue = REReplace(editedValue, "<sup>|</sup>", "[sup]|[/sup]", "ALL")>

Open in new window

0
 
LVL 25

Expert Comment

by:dgrafx
ID: 41746589
Here ya go!

<b>Original:</b><br />
<cfsavecontent variable="editedValue">
<b>This</b> is some <sub>testing</sub> <u>text</u>. <sup>Hello</sup>!<br>
I walk <sub>that</sub> a <b>child</b> <sup>might</sup> <i>live</i> ...
</cfsavecontent>
#variables.editedValue#<br />
<hr>

<b>Preserve sub & sup:</b><br>
<cfset editedValue = ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(variables.editedValue,
		"</sub>","[/sub]","ALL"),"<sub>","[sub]","ALL"),"</sup>","[/sup]","ALL"),"<sup>","[sup]","ALL")
	>
#variables.editedValue#<br />
<hr>

<b>Strip tags:</b><br>
<cfset editedValue = ReReplace(variables.editedValue, "(,)|(<[^>]*>)", "", "All")>
#variables.editedValue#<br>
<hr>

<b>Final:</b><br>
<cfset editedValue = ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(ReplaceNoCase(variables.editedValue,
		"[/sub]","</sub>","ALL"),"[sub]","<sub>","ALL"),"[/sup]","</sup>","ALL"),"[sup]","<sup>","ALL")
	>
#variables.editedValue#

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CF 11 throws error after following lock-down procedure 5 43
Coldfusion combining queries 15 73
Passing value to a stored procedure 8 100
ColdFusion 10 Error 2 50
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question