Skip to content

Remove HTML Tags from a String in a Flow #1072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vermaamit1664
Copy link
Contributor

This code will make use of a regex and JavaScript replace function to get rid of HTML tags in a string by accepting HTML string variable as an input and giving plaintext string as an output without using the Replace String transformation function of flow designer which doesn't goes well with the HTML variables.

@kmxo kmxo self-assigned this Oct 1, 2024
@kmxo
Copy link
Contributor

kmxo commented Oct 1, 2024

Looks good to me!

@kmxo kmxo merged commit 01a30a8 into ServiceNowDevProgram:main Oct 1, 2024
1 check passed
Copy link

@szentpali-janos szentpali-janos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you could enhance the solution and replace the RegExp base HTML stripping with a one based on a built in function/method: new GlideSPScriptable().stripHTML('<html>')?
If we take for example HTML <p>One</p><p>Two</p>, running .replace(/<[^>]+>/g,'') over it produces output OneTwo but running new GlideSPScriptable().stripHTML() over it produces output One Two. I would say a better stripping, honoring the intent of the original HTML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants