Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2243 - Fix markdown <code> element issue #2247

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/assets/style/components/_custom-markdowns.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
background-color: $general_1;
line-height: 1.4;
margin: 0;
max-width: 100%;
overflow-x: auto;
}

* + pre,
Expand Down
6 changes: 6 additions & 0 deletions frontend/views/containers/chatroom/MessageBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export default ({
display: flex;
align-items: flex-start;
gap: 0.5rem;
max-width: 100%;
}

.c-avatar {
Expand All @@ -342,6 +343,10 @@ export default ({
width: 100%;
}

.c-body {
max-width: calc(100% - 2.5rem);
}

.c-who {
display: flex;

Expand All @@ -354,6 +359,7 @@ export default ({
word-break: break-word; // too much long words will break
white-space: pre-line; // break \n to a new line
margin: 0;
max-width: 100%;

// When .c-shot is the only element (when .c-who isn't rendered)
&:first-child:last-child {
Expand Down
1 change: 1 addition & 0 deletions frontend/views/containers/chatroom/MessageReactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default ({
.c-emoticons-list {
padding-left: 3rem;
display: flex;
flex-wrap: wrap;
Copy link
Collaborator Author

@SebinSong SebinSong Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix for the overflowing emoji issues @Silver-IT found.


&.for-type-poll {
@include phone {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const RenderMessageWithMarkdown: any = {
const recursiveCall = (entry: any): any => {
if (entry.tagName) {
const hasChildren = Array.isArray(entry.children)
const isCodeElement = entry.tagName === 'CODE'

const routerOptions = { isInAppRouter: false, route: {}, href: '' }
if (entry.tagName === 'A' && entry.attributes.href) {
Expand Down Expand Up @@ -65,7 +66,7 @@ const RenderMessageWithMarkdown: any = {
opts,
hasChildren
? entry.children.map(child => recursiveCall(child))
: undefined
: isCodeElement ? entry.text : undefined
)
} else if (entry.text) {
return createElement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,27 @@ function createRecursiveDomObjects (element: any): DomObject {
This outcome will be used by a Vue render function to render converted markdown cleanly without breaking the html structure.
*/

const isNodeTypeText = (el: any): boolean => el?.nodeType === Node.TEXT_NODE
const isNodeTypeText = element?.nodeType === Node.TEXT_NODE
const isNodeCodeElement = element?.nodeName === 'CODE' // <code> ... </code> element needs a special treatment in the chat.

const nodeObj: DomObject = isNodeTypeText(element)
const nodeObj: DomObject = isNodeTypeText
? { tagName: null, attributes: {}, text: element.textContent }
: { tagName: element.tagName, attributes: {} }
: {
tagName: element.tagName,
text: isNodeCodeElement
// $FlowFixMe[prop-missing]
? element.innerText.replaceAll('<br>', '')
: undefined,
attributes: {}
}

if (element.attributes?.length) {
for (const attr of element.attributes) {
nodeObj.attributes[attr.name] = attr.value
}
}

if (element.childNodes?.length) {
if (!isNodeCodeElement && element.childNodes?.length) {
nodeObj.children = []

for (const child of element.childNodes) {
Expand Down
Loading