Skip to content

Commit d6775e7

Browse files
committed
fix: normalize table rendering in note view
1 parent 6471aec commit d6775e7

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed

apps/mobile/v1/src/screens/ViewNote/NoteContent.tsx

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,55 @@ export function NoteContent({
248248
border-radius: 3px;
249249
}
250250
251+
/* Table wrapper for horizontal scroll */
252+
.table-wrapper {
253+
overflow-x: auto;
254+
-webkit-overflow-scrolling: touch;
255+
margin: 12px 0;
256+
}
257+
258+
/* Tables */
259+
table {
260+
border-collapse: collapse;
261+
width: auto;
262+
min-width: 100%;
263+
table-layout: auto;
264+
}
265+
266+
th, td {
267+
border: 1px solid ${theme.colors.border} !important;
268+
padding: 8px 12px !important;
269+
vertical-align: top;
270+
font-size: 16px !important;
271+
white-space: nowrap;
272+
}
273+
274+
/* Allow text wrapping for cells with longer content */
275+
td p, th p {
276+
white-space: normal;
277+
min-width: 120px;
278+
}
279+
280+
th {
281+
background-color: ${theme.isDark ? 'rgba(255, 255, 255, 0.05)' : theme.colors.muted} !important;
282+
font-weight: 600;
283+
}
284+
285+
/* Force consistent font-size inside table cells */
286+
th *, td *,
287+
th p, td p,
288+
th span, td span {
289+
font-size: 16px !important;
290+
margin: 0 !important;
291+
}
292+
293+
/* Remove p margins inside table cells and force inherit alignment */
294+
th p, td p,
295+
th > p, td > p,
296+
table th p, table td p {
297+
text-align: inherit !important;
298+
}
299+
251300
.note-header {
252301
padding: 8px 16px 0 16px;
253302
}
@@ -359,6 +408,56 @@ ${note.content}
359408
document.querySelectorAll('pre code').forEach((block) => {
360409
hljs.highlightElement(block);
361410
});
411+
412+
// Fix tables: wrap in scrollable div and normalize styling
413+
document.querySelectorAll('table').forEach((table) => {
414+
// Wrap table in scrollable div if not already wrapped
415+
if (!table.parentElement.classList.contains('table-wrapper')) {
416+
const wrapper = document.createElement('div');
417+
wrapper.className = 'table-wrapper';
418+
table.parentNode.insertBefore(wrapper, table);
419+
wrapper.appendChild(table);
420+
}
421+
422+
// Remove inline styles from table
423+
table.removeAttribute('style');
424+
425+
// Remove colgroup widths
426+
table.querySelectorAll('col').forEach((col) => {
427+
col.removeAttribute('style');
428+
col.removeAttribute('width');
429+
});
430+
});
431+
432+
// Fix table cell alignment and remove fixed widths
433+
document.querySelectorAll('th, td').forEach((cell) => {
434+
// Remove colwidth attribute
435+
cell.removeAttribute('colwidth');
436+
437+
// Get alignment before removing style
438+
const style = cell.getAttribute('style') || '';
439+
const alignMatch = style.match(/text-align:\\s*(left|center|right|justify)/i);
440+
441+
// Remove all inline styles (including width)
442+
cell.removeAttribute('style');
443+
444+
// Re-apply alignment if it was set
445+
if (alignMatch) {
446+
const alignment = alignMatch[1];
447+
cell.style.textAlign = alignment;
448+
cell.querySelectorAll('p').forEach((p) => {
449+
p.style.textAlign = alignment;
450+
});
451+
}
452+
453+
// Remove inline styles from all child elements
454+
cell.querySelectorAll('*').forEach((el) => {
455+
if (el.style) {
456+
el.style.fontSize = '';
457+
el.style.width = '';
458+
}
459+
});
460+
});
362461
`}
363462
364463
// Send content height to React Native
@@ -480,6 +579,8 @@ ${note.content}
480579
}
481580
} else if (data.type === 'error') {
482581
console.error('WebView error:', data.error);
582+
} else if (data.type === 'debug') {
583+
console.log('DEBUG TABLE HTML:', data.table);
483584
}
484585
} catch {
485586
// Ignore parse errors

apps/mobile/v1/src/screens/ViewNote/htmlGenerator.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,42 @@ export function generateNoteHtml(
2525
document.querySelectorAll('pre code').forEach((block) => {
2626
hljs.highlightElement(block);
2727
});
28+
29+
// Fix tables: wrap in scrollable div and normalize styling
30+
document.querySelectorAll('table').forEach((table) => {
31+
if (!table.parentElement.classList.contains('table-wrapper')) {
32+
const wrapper = document.createElement('div');
33+
wrapper.className = 'table-wrapper';
34+
table.parentNode.insertBefore(wrapper, table);
35+
wrapper.appendChild(table);
36+
}
37+
table.removeAttribute('style');
38+
table.querySelectorAll('col').forEach((col) => {
39+
col.removeAttribute('style');
40+
col.removeAttribute('width');
41+
});
42+
});
43+
44+
// Fix table cell alignment and remove fixed widths
45+
document.querySelectorAll('th, td').forEach((cell) => {
46+
cell.removeAttribute('colwidth');
47+
const style = cell.getAttribute('style') || '';
48+
const alignMatch = style.match(/text-align:\\s*(left|center|right|justify)/i);
49+
cell.removeAttribute('style');
50+
if (alignMatch) {
51+
const alignment = alignMatch[1];
52+
cell.style.textAlign = alignment;
53+
cell.querySelectorAll('p').forEach((p) => {
54+
p.style.textAlign = alignment;
55+
});
56+
}
57+
cell.querySelectorAll('*').forEach((el) => {
58+
if (el.style) {
59+
el.style.fontSize = '';
60+
el.style.width = '';
61+
}
62+
});
63+
});
2864
});
2965
</script>
3066
<style>
@@ -190,6 +226,54 @@ export function generateNoteHtml(
190226
}
191227
` : ''}
192228
229+
/* Table wrapper for horizontal scroll */
230+
.table-wrapper {
231+
overflow-x: auto;
232+
-webkit-overflow-scrolling: touch;
233+
margin: 16px 0;
234+
}
235+
236+
/* Tables */
237+
table {
238+
border-collapse: collapse;
239+
width: auto;
240+
min-width: 100%;
241+
table-layout: auto;
242+
}
243+
244+
th, td {
245+
border: 1px solid ${themeColors.muted} !important;
246+
padding: 8px 12px !important;
247+
text-align: left;
248+
vertical-align: top;
249+
font-size: 16px !important;
250+
white-space: nowrap;
251+
}
252+
253+
/* Allow text wrapping for cells with longer content */
254+
td p, th p {
255+
white-space: normal;
256+
min-width: 120px;
257+
}
258+
259+
th {
260+
background-color: ${themeColors.muted} !important;
261+
font-weight: 600;
262+
}
263+
264+
/* Force consistent font-size inside table cells */
265+
th *, td *,
266+
th p, td p,
267+
th span, td span {
268+
font-size: 16px !important;
269+
margin: 0 !important;
270+
}
271+
272+
/* Remove default margins from p inside table cells and inherit alignment */
273+
th p, td p {
274+
text-align: inherit !important;
275+
}
276+
193277
/* Scrollbar styling */
194278
pre::-webkit-scrollbar {
195279
height: 6px;

0 commit comments

Comments
 (0)