aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2019-11-14 00:41:14 +0200
committerHenry Jameson <me@hjkos.com>2019-11-14 00:41:14 +0200
commit692ee0e95a852b1f803b7ae92d65cbf4f3ce3445 (patch)
treed425c47e8bcde4913fe9ed55cff08d46b4168d1a /src
parent50dc9df8a44d408dd83ae4b17c407fa36c85cf8e (diff)
Fix regex, tag detector condition
Diffstat (limited to 'src')
-rw-r--r--src/components/status/status.js2
-rw-r--r--src/services/tiny_post_html_processor/tiny_post_html_processor.service.js25
2 files changed, 13 insertions, 14 deletions
diff --git a/src/components/status/status.js b/src/components/status/status.js
index 6dbb2199..416aa36a 100644
--- a/src/components/status/status.js
+++ b/src/components/status/status.js
@@ -43,7 +43,7 @@ const Status = {
showingTall: this.inConversation && this.focused,
showingLongSubject: false,
error: null,
- // Initial state
+ // not as computed because it sets the initial state which will be changed later
expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject,
}
},
diff --git a/src/services/tiny_post_html_processor/tiny_post_html_processor.service.js b/src/services/tiny_post_html_processor/tiny_post_html_processor.service.js
index c9ff81e1..b96c1ccf 100644
--- a/src/services/tiny_post_html_processor/tiny_post_html_processor.service.js
+++ b/src/services/tiny_post_html_processor/tiny_post_html_processor.service.js
@@ -9,17 +9,15 @@
export const processHtml = (html, processor) => {
const handledTags = new Set(['p', 'br', 'div'])
const openCloseTags = new Set(['p', 'div'])
- const tagRegex = /(?:<\/(\w+)>|<(\w+)\s?[^/]*?\/?>)/gi
let buffer = '' // Current output buffer
const level = [] // How deep we are in tags and which tags were there
let textBuffer = '' // Current line content
let tagBuffer = null // Current tag buffer, if null = we are not currently reading a tag
- // Extracts tagname from tag, i.e. <span a="b"> => span
+ // Extracts tag name from tag, i.e. <span a="b"> => span
const getTagName = (tag) => {
- // eslint-disable-next-line no-unused-vars
- const result = tagRegex.exec(tag)
+ const result = /(?:<\/(\w+)>|<(\w+)\s?[^/]*?\/?>)/gi.exec(tag)
return result && (result[1] || result[2])
}
@@ -49,28 +47,29 @@ export const processHtml = (html, processor) => {
for (let i = 0; i < html.length; i++) {
const char = html[i]
- if (char === '<' && tagBuffer !== null) {
+ if (char === '<' && tagBuffer === null) {
tagBuffer = char
} else if (char !== '>' && tagBuffer !== null) {
tagBuffer += char
} else if (char === '>' && tagBuffer !== null) {
tagBuffer += char
- const tagName = getTagName(tagBuffer)
+ const tagFull = tagBuffer
+ tagBuffer = null
+ const tagName = getTagName(tagFull)
if (handledTags.has(tagName)) {
if (tagName === 'br') {
- handleBr(tagBuffer)
+ handleBr(tagFull)
}
- if (openCloseTags.has(tagBuffer)) {
- if (tagBuffer[1] === '/') {
- handleClose(tagBuffer)
+ if (openCloseTags.has(tagFull)) {
+ if (tagFull[1] === '/') {
+ handleClose(tagFull)
} else {
- handleOpen(tagBuffer)
+ handleOpen(tagFull)
}
}
} else {
- textBuffer += tagBuffer
+ textBuffer += tagFull
}
- tagBuffer = null
} else if (char === '\n') {
handleBr(char)
} else {