Skip to content

Commit 7721946

Browse files
committed
Merge remote-tracking branch 'github/sf-site-migration/ui' into feat/1.1.1/user-center
2 parents 388d169 + fd31a26 commit 7721946

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

ui/src/components/Editor/utils/index.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ export function createEditorUtils(
8080

8181
export function htmlRender(el: HTMLElement | null) {
8282
if (!el) return;
83+
// Replace all br tags with newlines
84+
// Fixed an issue where the BR tag in the editor block formula HTML caused rendering errors.
85+
el.querySelectorAll('p').forEach((p) => {
86+
if (p.innerHTML.startsWith('$$') && p.innerHTML.endsWith('$$')) {
87+
const str = p.innerHTML.replace(/<br>/g, '\n');
88+
p.innerHTML = str;
89+
}
90+
});
91+
8392
import('mermaid').then(({ default: mermaid }) => {
8493
mermaid.initialize({ startOnLoad: false });
8594

@@ -99,6 +108,7 @@ export function htmlRender(el: HTMLElement | null) {
99108
render(el, {
100109
delimiters: [
101110
{ left: '$$', right: '$$', display: true },
111+
{ left: '$$<br>', right: '<br>$$', display: true },
102112
{
103113
left: '\\begin{equation}',
104114
right: '\\end{equation}',
@@ -114,8 +124,26 @@ export function htmlRender(el: HTMLElement | null) {
114124
},
115125
);
116126

117-
// remove change table style to htmlToReact function
118-
/**
119-
* @description: You modify the DOM with other scripts after React has rendered the DOM. This way, on the next render cycle (re-render), React cannot find the DOM node it rendered before, because it has been modified or removed by other scripts.
120-
*/
127+
// change table style
128+
129+
el.querySelectorAll('table').forEach((table) => {
130+
if (
131+
(table.parentNode as HTMLDivElement)?.classList.contains(
132+
'table-responsive',
133+
)
134+
) {
135+
return;
136+
}
137+
138+
table.classList.add('table', 'table-bordered');
139+
const div = document.createElement('div');
140+
div.className = 'table-responsive';
141+
table.parentNode?.replaceChild(div, table);
142+
div.appendChild(table);
143+
});
144+
145+
// video width 100%
146+
el.querySelectorAll('video').forEach((video) => {
147+
video.style.width = '100%';
148+
});
121149
}

0 commit comments

Comments
 (0)