Make MentionsLine aware of line breaking by non-br elements
This commit is contained in:
parent
510392e4ca
commit
56a74aa392
1
changelog.d/mentionsline-shouldbreak.fix
Normal file
1
changelog.d/mentionsline-shouldbreak.fix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Make MentionsLine aware of line breaking by non-br elements
|
@ -8,6 +8,27 @@ import HashtagLink from 'src/components/hashtag_link/hashtag_link.vue'
|
|||||||
|
|
||||||
import './rich_content.scss'
|
import './rich_content.scss'
|
||||||
|
|
||||||
|
const MAYBE_LINE_BREAKING_ELEMENTS = [
|
||||||
|
'blockquote',
|
||||||
|
'br',
|
||||||
|
'hr',
|
||||||
|
'ul',
|
||||||
|
'ol',
|
||||||
|
'li',
|
||||||
|
'p',
|
||||||
|
'table',
|
||||||
|
'tbody',
|
||||||
|
'td',
|
||||||
|
'th',
|
||||||
|
'thead',
|
||||||
|
'tr',
|
||||||
|
'h1',
|
||||||
|
'h2',
|
||||||
|
'h3',
|
||||||
|
'h4',
|
||||||
|
'h5'
|
||||||
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RichContent, The Über-powered component for rendering Post HTML.
|
* RichContent, The Über-powered component for rendering Post HTML.
|
||||||
*
|
*
|
||||||
@ -166,22 +187,19 @@ export default {
|
|||||||
!(children && typeof children[0] === 'string' && children[0].match(/^\s/))
|
!(children && typeof children[0] === 'string' && children[0].match(/^\s/))
|
||||||
? lastSpacing
|
? lastSpacing
|
||||||
: ''
|
: ''
|
||||||
switch (Tag) {
|
if (MAYBE_LINE_BREAKING_ELEMENTS.includes(Tag)) {
|
||||||
case 'br':
|
// all the elements that can cause a line change
|
||||||
currentMentions = null
|
currentMentions = null
|
||||||
break
|
} else if (Tag === 'img') { // replace images with StillImage
|
||||||
case 'img': // replace images with StillImage
|
|
||||||
return ['', [mentionsLinePadding, renderImage(opener)], '']
|
return ['', [mentionsLinePadding, renderImage(opener)], '']
|
||||||
case 'a': // replace mentions with MentionLink
|
} else if (Tag === 'a' && this.handleLinks) { // replace mentions with MentionLink
|
||||||
if (!this.handleLinks) break
|
|
||||||
if (fullAttrs.class && fullAttrs.class.includes('mention')) {
|
if (fullAttrs.class && fullAttrs.class.includes('mention')) {
|
||||||
// Handling mentions here
|
// Handling mentions here
|
||||||
return renderMention(attrs, children)
|
return renderMention(attrs, children)
|
||||||
} else {
|
} else {
|
||||||
currentMentions = null
|
currentMentions = null
|
||||||
break
|
|
||||||
}
|
}
|
||||||
case 'span':
|
} else if (Tag === 'span') {
|
||||||
if (this.handleLinks && fullAttrs.class && fullAttrs.class.includes('h-card')) {
|
if (this.handleLinks && fullAttrs.class && fullAttrs.class.includes('h-card')) {
|
||||||
return ['', children.map(processItem), '']
|
return ['', children.map(processItem), '']
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user