Sometimes we need to get only the text from an HTML document, like the Rich Text format available for the text type inside Dataverse/Model-driven app.
If you need to perform this action client-side, a simple JavaScript function can be used:
function parseHTML(html) { let doc = new DOMParser().parseFromString(html, 'text/html'); return doc.body.textContent || ""; } function test_richtext_OnChange(executionContext) { var formContext = executionContext.getFormContext(); let richTextValue = formContext.getAttribute("test_richtext").getValue(); let cleanValue = parseHTML(richTextValue); formContext.getAttribute("test_plaintext").setValue(cleanValue); }It uses the DOMParser interface, here a screenshot on how the result looks like inside a model-driven app:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1glwJnEqyygSqE7MxRQQB_UGa1qoL4mre0P0zx0A8AUSo_fSl8dWTi34dBaQvKZto-S24sxtHkM7D1GrkXNHbsKmv28AfQBbqNZdk-PwK_0KRuYj4woo7r6x3PjIyw-FaxvIItVtGLA24Q9KE74npUwId_8SHhUuzaI0JefzJht5qun_zXMyzKwPARWc/w640-h304/parse_html.jpg)
do you known how can we maintain the Paragraph spacing between the contents when extracting rich text to Simple Text.
ReplyDelete