fix: fix html style of glitch-soc markdown content (#1350)
This commit is contained in:
parent
53f0fdf1a8
commit
6fafe19454
10
src/routes/_utils/massageStatusPlainText.js
Normal file
10
src/routes/_utils/massageStatusPlainText.js
Normal file
|
@ -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 <p> tags, so wrap them
|
||||||
|
if (text && !STARTING_TAG_REGEX.test(text)) {
|
||||||
|
text = `<p>${text}</p>`
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
|
@ -1,12 +1,9 @@
|
||||||
import { emojifyText } from './emojifyText'
|
import { emojifyText } from './emojifyText'
|
||||||
|
import { massageStatusPlainText } from './massageStatusPlainText'
|
||||||
|
|
||||||
export function massageUserText (text, emojis, $autoplayGifs) {
|
export function massageUserText (text, emojis, $autoplayGifs) {
|
||||||
text = text || ''
|
text = text || ''
|
||||||
text = emojifyText(text, emojis, $autoplayGifs)
|
text = emojifyText(text, emojis, $autoplayGifs)
|
||||||
|
text = massageStatusPlainText(text)
|
||||||
// GNU Social and Pleroma don't add <p> tags
|
|
||||||
if (text && !text.startsWith('<p>')) {
|
|
||||||
text = `<p>${text}</p>`
|
|
||||||
}
|
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { mark, stop } from './marks'
|
import { mark, stop } from './marks'
|
||||||
|
import { massageStatusPlainText } from './massageStatusPlainText'
|
||||||
|
|
||||||
let domParser = process.browser && new DOMParser()
|
let domParser = process.browser && new DOMParser()
|
||||||
|
|
||||||
|
@ -37,10 +38,7 @@ export function statusHtmlToPlainText (html, mentions) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
mark('statusHtmlToPlainText')
|
mark('statusHtmlToPlainText')
|
||||||
// GNU Social and Pleroma don't add <p> tags
|
html = massageStatusPlainText(html)
|
||||||
if (!html.startsWith('<p>')) {
|
|
||||||
html = `<p>${html}</p>`
|
|
||||||
}
|
|
||||||
let doc = domParser.parseFromString(html, 'text/html')
|
let doc = domParser.parseFromString(html, 'text/html')
|
||||||
massageMentions(doc, mentions)
|
massageMentions(doc, mentions)
|
||||||
let res = innerTextRetainingNewlines(doc)
|
let res = innerTextRetainingNewlines(doc)
|
||||||
|
|
Loading…
Reference in a new issue