@t7/utils
Version:
Utility methods for T7 components.
22 lines (18 loc) • 553 B
JavaScript
/*
You would call this when receiving a plain text
value back from an API, and before inserting the
text into the `contenteditable` area on a page.
*/
const contentToMarkup = (value = '') => {
value = value.trim()
value = value.replace(/>/g, '>')
value = value.replace(/</g, '<')
value = value.replace(/\n+\s+\n+/g, '\n\n')
value = value.replace(/\n\n+/g, '\n\n')
value = value.replace(/\n/g, '<br>')
value = value.replace(/\s+/g, ' ')
// Expose string.
return value
}
// Expose function.
export default contentToMarkup