Home > front end >  Opening/Closing tag formatting mismatch
Opening/Closing tag formatting mismatch

Time:11-08

When receiving HTML from backend encountering that escape characters has whitespace, thus not allows to close tag and show text, like show below in the example.

<p&#6 2;Please check for BAC and get customer to confirm via secure phone line the account change. "customer has wrote wrong bankname" does not confirm the account change.</p>

Whitespace can be in various place of the tag <p&#62 ; <p& #62; <p &#62; and also appear for the opening tags.

Would there be possibility to avoid whitespace, that would allow to create tag and create a formatting solution?

CodePudding user response:

As @kissu suggested, it seems the cleanest solution would be to fix it on back-end. Especially, as the closing tag is fine.

If that's not an option, you can use JavaScript to remove the extra space, e.g. with something like this:

const response = '<p&#6 2;Please check for BAC...</p>';
const fixedResponse = response.replace(/(<.*)\s(.*;)/, "$1$2");

This script finds characters "<" and ";", and removes a space between them.

If you have multiple issues like this in the response, you might need to update the regex to make it more robust.

Documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement

  • Related