Fix regex, tag detector condition
This commit is contained in:
parent
50dc9df8a4
commit
692ee0e95a
2 changed files with 13 additions and 14 deletions
|
@ -43,7 +43,7 @@ const Status = {
|
||||||
showingTall: this.inConversation && this.focused,
|
showingTall: this.inConversation && this.focused,
|
||||||
showingLongSubject: false,
|
showingLongSubject: false,
|
||||||
error: null,
|
error: null,
|
||||||
// Initial state
|
// not as computed because it sets the initial state which will be changed later
|
||||||
expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject,
|
expandingSubject: !this.$store.getters.mergedConfig.collapseMessageWithSubject,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,17 +9,15 @@
|
||||||
export const processHtml = (html, processor) => {
|
export const processHtml = (html, processor) => {
|
||||||
const handledTags = new Set(['p', 'br', 'div'])
|
const handledTags = new Set(['p', 'br', 'div'])
|
||||||
const openCloseTags = new Set(['p', 'div'])
|
const openCloseTags = new Set(['p', 'div'])
|
||||||
const tagRegex = /(?:<\/(\w+)>|<(\w+)\s?[^/]*?\/?>)/gi
|
|
||||||
|
|
||||||
let buffer = '' // Current output buffer
|
let buffer = '' // Current output buffer
|
||||||
const level = [] // How deep we are in tags and which tags were there
|
const level = [] // How deep we are in tags and which tags were there
|
||||||
let textBuffer = '' // Current line content
|
let textBuffer = '' // Current line content
|
||||||
let tagBuffer = null // Current tag buffer, if null = we are not currently reading a tag
|
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) => {
|
const getTagName = (tag) => {
|
||||||
// eslint-disable-next-line no-unused-vars
|
const result = /(?:<\/(\w+)>|<(\w+)\s?[^/]*?\/?>)/gi.exec(tag)
|
||||||
const result = tagRegex.exec(tag)
|
|
||||||
return result && (result[1] || result[2])
|
return result && (result[1] || result[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,28 +47,29 @@ export const processHtml = (html, processor) => {
|
||||||
|
|
||||||
for (let i = 0; i < html.length; i++) {
|
for (let i = 0; i < html.length; i++) {
|
||||||
const char = html[i]
|
const char = html[i]
|
||||||
if (char === '<' && tagBuffer !== null) {
|
if (char === '<' && tagBuffer === null) {
|
||||||
tagBuffer = char
|
tagBuffer = char
|
||||||
} else if (char !== '>' && tagBuffer !== null) {
|
} else if (char !== '>' && tagBuffer !== null) {
|
||||||
tagBuffer += char
|
tagBuffer += char
|
||||||
} else if (char === '>' && tagBuffer !== null) {
|
} else if (char === '>' && tagBuffer !== null) {
|
||||||
tagBuffer += char
|
tagBuffer += char
|
||||||
const tagName = getTagName(tagBuffer)
|
const tagFull = tagBuffer
|
||||||
|
tagBuffer = null
|
||||||
|
const tagName = getTagName(tagFull)
|
||||||
if (handledTags.has(tagName)) {
|
if (handledTags.has(tagName)) {
|
||||||
if (tagName === 'br') {
|
if (tagName === 'br') {
|
||||||
handleBr(tagBuffer)
|
handleBr(tagFull)
|
||||||
}
|
}
|
||||||
if (openCloseTags.has(tagBuffer)) {
|
if (openCloseTags.has(tagFull)) {
|
||||||
if (tagBuffer[1] === '/') {
|
if (tagFull[1] === '/') {
|
||||||
handleClose(tagBuffer)
|
handleClose(tagFull)
|
||||||
} else {
|
} else {
|
||||||
handleOpen(tagBuffer)
|
handleOpen(tagFull)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
textBuffer += tagBuffer
|
textBuffer += tagFull
|
||||||
}
|
}
|
||||||
tagBuffer = null
|
|
||||||
} else if (char === '\n') {
|
} else if (char === '\n') {
|
||||||
handleBr(char)
|
handleBr(char)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue