commit: e31bf6646b9cdd21bef7b4f64083b1f8c2bbd913
parent 510392e4ca67fee4bf6fed9346f1ff708966e734
Author: HJ <30-hj@users.noreply.git.pleroma.social>
Date: Mon, 24 Jul 2023 22:58:54 +0000
Merge branch 'tusooa/1276-mentionsline-shouldbreak' into 'develop'
Make MentionsLine aware of line breaking by non-br elements
Closes #1276
See merge request pleroma/pleroma-fe!1849
Diffstat:
2 files changed, 37 insertions(+), 18 deletions(-)
diff --git a/changelog.d/mentionsline-shouldbreak.fix b/changelog.d/mentionsline-shouldbreak.fix
@@ -0,0 +1 @@
+Make MentionsLine aware of line breaking by non-br elements
diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx
@@ -8,6 +8,27 @@ import HashtagLink from 'src/components/hashtag_link/hashtag_link.vue'
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.
*
@@ -166,25 +187,22 @@ export default {
!(children && typeof children[0] === 'string' && children[0].match(/^\s/))
? lastSpacing
: ''
- switch (Tag) {
- case 'br':
+ if (MAYBE_LINE_BREAKING_ELEMENTS.includes(Tag)) {
+ // all the elements that can cause a line change
+ currentMentions = null
+ } else if (Tag === 'img') { // replace images with StillImage
+ return ['', [mentionsLinePadding, renderImage(opener)], '']
+ } else if (Tag === 'a' && this.handleLinks) { // replace mentions with MentionLink
+ if (fullAttrs.class && fullAttrs.class.includes('mention')) {
+ // Handling mentions here
+ return renderMention(attrs, children)
+ } else {
currentMentions = null
- break
- case 'img': // replace images with StillImage
- return ['', [mentionsLinePadding, renderImage(opener)], '']
- case 'a': // replace mentions with MentionLink
- if (!this.handleLinks) break
- if (fullAttrs.class && fullAttrs.class.includes('mention')) {
- // Handling mentions here
- return renderMention(attrs, children)
- } else {
- currentMentions = null
- break
- }
- case 'span':
- if (this.handleLinks && fullAttrs.class && fullAttrs.class.includes('h-card')) {
- return ['', children.map(processItem), '']
- }
+ }
+ } else if (Tag === 'span') {
+ if (this.handleLinks && fullAttrs.class && fullAttrs.class.includes('h-card')) {
+ return ['', children.map(processItem), '']
+ }
}
if (children !== undefined) {