0
Add "\n" to tags in nested HTML
Community Beginner
,
/t5/coldfusion-discussions/add-quot-n-quot-to-tags-in-nested-html/td-p/15191301
Mar 04, 2025
Mar 04, 2025
Copy link to clipboard
Copied
I need to prepare html for sending via the Postmark API.
Given the following:
<cfset vHTML = "<html><body><div>This is html</div></body></html>">
What would be the cleanest way to arrive at:
<cfset vPostmarkHTML = "<html>\n<body>\n<div>This is postmark html</div>\n</body>\n</html>">
i.e. surround every nested tag group with "\n" except the outer <html> group
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
LATEST
/t5/coldfusion-discussions/add-quot-n-quot-to-tags-in-nested-html/m-p/15193620#M200240
Mar 05, 2025
Mar 05, 2025
Copy link to clipboard
Copied
<cfset vHTML = "<html><body><div>This is a div.</div><div>This is a second div.</div></body></html>">
<!--- Test both versions of line-feed, and see which fits your needs. --->
<!---<cfset LF=chr(10)>--->
<cfset LF="\n">
<cfset vPostmarkHTML = vHTML.replaceNoCase("<body>","#LF#<body>").replaceNoCase("<div>","#LF#<div>","all").replaceNoCase("</body>","</body>#LF#").replaceNoCase("</div>","</div>#LF#","all")>
<cfoutput>
<strong>vPostmarkHTML</strong><br>
#vPostmarkHTML#
</cfoutput>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

