diff --git a/src/routes/_utils/massageStatusPlainText.js b/src/routes/_utils/massageStatusPlainText.js new file mode 100644 index 00000000..d64e1f6c --- /dev/null +++ b/src/routes/_utils/massageStatusPlainText.js @@ -0,0 +1,10 @@ +// Glitch Social can have statuses that just contain blockquote/ol/ul, no p +const STARTING_TAG_REGEX = /^<(?:p|blockquote|ol|ul)>/i + +export function massageStatusPlainText (text) { + // GNU Social and Pleroma don't add

tags, so wrap them + if (text && !STARTING_TAG_REGEX.test(text)) { + text = `

${text}

` + } + return text +} diff --git a/src/routes/_utils/massageUserText.js b/src/routes/_utils/massageUserText.js index 7c052b69..f5e636d3 100644 --- a/src/routes/_utils/massageUserText.js +++ b/src/routes/_utils/massageUserText.js @@ -1,12 +1,9 @@ import { emojifyText } from './emojifyText' +import { massageStatusPlainText } from './massageStatusPlainText' export function massageUserText (text, emojis, $autoplayGifs) { text = text || '' text = emojifyText(text, emojis, $autoplayGifs) - - // GNU Social and Pleroma don't add

tags - if (text && !text.startsWith('

')) { - text = `

${text}

` - } + text = massageStatusPlainText(text) return text } diff --git a/src/routes/_utils/statusHtmlToPlainText.js b/src/routes/_utils/statusHtmlToPlainText.js index a8563a17..2c63ea8b 100644 --- a/src/routes/_utils/statusHtmlToPlainText.js +++ b/src/routes/_utils/statusHtmlToPlainText.js @@ -1,4 +1,5 @@ import { mark, stop } from './marks' +import { massageStatusPlainText } from './massageStatusPlainText' let domParser = process.browser && new DOMParser() @@ -37,10 +38,7 @@ export function statusHtmlToPlainText (html, mentions) { return '' } mark('statusHtmlToPlainText') - // GNU Social and Pleroma don't add

tags - if (!html.startsWith('

')) { - html = `

${html}

` - } + html = massageStatusPlainText(html) let doc = domParser.parseFromString(html, 'text/html') massageMentions(doc, mentions) let res = innerTextRetainingNewlines(doc)