aboutsummaryrefslogtreecommitdiff
path: root/src/components/rich_content/rich_content.jsx
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2021-06-13 13:29:26 +0300
committerHenry Jameson <me@hjkos.com>2021-06-13 15:24:29 +0300
commitbebafa1a2c38972245d37de70f4aec4bfb2083fd (patch)
tree733c738d15bda28210053fdfb80b789c8a9dd708 /src/components/rich_content/rich_content.jsx
parente825021ef1ae7a672b275227a6a1ff44d5f522bc (diff)
refactored line converter, untied its logic from greentexting, better
handling of broken cases
Diffstat (limited to 'src/components/rich_content/rich_content.jsx')
-rw-r--r--src/components/rich_content/rich_content.jsx10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/components/rich_content/rich_content.jsx b/src/components/rich_content/rich_content.jsx
index e188763f..328e9201 100644
--- a/src/components/rich_content/rich_content.jsx
+++ b/src/components/rich_content/rich_content.jsx
@@ -246,6 +246,7 @@ const getLinkData = (attrs, children, index) => {
*/
export const preProcessPerLine = (html, greentext, handleLinks) => {
const lastMentions = []
+ const greentextHandle = new Set(['p', 'div'])
let nonEmptyIndex = -1
const newHtml = convertHtmlToLines(html).reverse().map((item, index, array) => {
@@ -256,7 +257,14 @@ export const preProcessPerLine = (html, greentext, handleLinks) => {
nonEmptyIndex += 1
// Greentext stuff
- if (greentext && (string.includes('&gt;') || string.includes('&lt;'))) {
+ if (
+ // Only if greentext is engaged
+ greentext &&
+ // Only handle p's and divs. Don't want to affect blocquotes, code etc
+ item.level.every(l => greentextHandle.has(l)) &&
+ // Only if line begins with '>' or '<'
+ (string.includes('&gt;') || string.includes('&lt;'))
+ ) {
const cleanedString = string.replace(/<[^>]+?>/gi, '') // remove all tags
.replace(/@\w+/gi, '') // remove mentions (even failed ones)
.trim()