Skip to content

Commit

Permalink
#2498 - Fix the link bug in the chat (#2499)
Browse files Browse the repository at this point in the history
* fix the link rendering issue

* updates for the change reuqest

* revert unecessary prev-fix

* remove another unecessary logic

* add a comment
  • Loading branch information
SebinSong authored Jan 9, 2025
1 parent 2e5cc01 commit 1f05932
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function createRecursiveDomObjects (element: any): DomObject {

const isNodeTypeText = element?.nodeType === Node.TEXT_NODE
const isNodeCodeElement = element?.nodeName === 'CODE' // <code> ... </code> element needs a special treatment in the chat.
const isBodyElement = element?.nodeName === 'BODY'

const nodeObj: DomObject = isNodeTypeText
? { tagName: null, attributes: {}, text: element.textContent }
Expand All @@ -87,9 +88,14 @@ function createRecursiveDomObjects (element: any): DomObject {
nodeObj.children.push(createRecursiveDomObjects(child))
}

nodeObj.children = nodeObj.children.filter(
child => child.tagName || (child.text || '').trim().length
)
nodeObj.children = nodeObj.children.filter(child => {
if (child.tagName) return true
else {
return isBodyElement
? child.text !== '\n' // DOMParser.parseFromString() adds a '\n' at the end of the body content which needs to be removed.
: (child.text || '').length
}
})
}

return nodeObj
Expand Down
1 change: 0 additions & 1 deletion frontend/views/utils/markdown-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export function renderMarkdown (str: string): any {
// STEP 3. Remove the unecessary starting/end line-breaks added in/outside of the converted html tags.
converted = converted.replace(/<([a-z]+)>\n/g, '<$1>')
.replace(/\n<\/([a-z]+)>/g, '</$1>')

return converted
}

Expand Down

0 comments on commit 1f05932

Please sign in to comment.