Fix regex, tag detector condition

This commit is contained in:
Henry Jameson 2019-11-14 00:41:14 +02:00
parent 50dc9df8a4
commit 692ee0e95a
2 changed files with 13 additions and 14 deletions

View file

@ -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,
}
},

View file

@ -9,7 +9,6 @@
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
@ -18,8 +17,7 @@ export const processHtml = (html, processor) => {
// 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 {