Skip to content
Open
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
10 changes: 6 additions & 4 deletions packages/happy-app/sources/components/markdown/MarkdownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const MarkdownView = React.memo((props: {
} else if (block.type === 'options') {
return <RenderOptionsBlock items={block.items} key={index} first={index === 0} last={index === blocks.length - 1} selectable={selectable} onOptionPress={props.onOptionPress} />;
} else if (block.type === 'table') {
return <RenderTableBlock headers={block.headers} rows={block.rows} key={index} first={index === 0} last={index === blocks.length - 1} />;
return <RenderTableBlock headers={block.headers} rows={block.rows} key={index} first={index === 0} last={index === blocks.length - 1} selectable={selectable} />;
} else {
return null;
}
Expand Down Expand Up @@ -235,7 +235,8 @@ function RenderTableBlock(props: {
headers: string[],
rows: string[][],
first: boolean,
last: boolean
last: boolean,
selectable: boolean
}) {
const columnCount = props.headers.length;
const rowCount = props.rows.length;
Expand All @@ -261,7 +262,7 @@ function RenderTableBlock(props: {
>
{/* Header cell for this column */}
<View style={[style.tableCell, style.tableHeaderCell, style.tableCellFirst]}>
<Text style={style.tableHeaderText}>{header}</Text>
<Text selectable={props.selectable} style={style.tableHeaderText}>{header}</Text>
</View>
{/* Data cells for this column */}
{props.rows.map((row, rowIndex) => (
Expand All @@ -272,7 +273,7 @@ function RenderTableBlock(props: {
isLastRow(rowIndex) && style.tableCellLast
]}
>
<Text style={style.tableCellText}>{row[colIndex] ?? ''}</Text>
<Text selectable={props.selectable} style={style.tableCellText}>{row[colIndex] ?? ''}</Text>
</View>
))}
</View>
Expand Down Expand Up @@ -526,6 +527,7 @@ const style = StyleSheet.create((theme) => ({
borderBottomWidth: 1,
borderBottomColor: theme.colors.divider,
alignItems: 'flex-start',
minHeight: 40, // padding (8+8) + lineHeight (24) to prevent empty cell collapse
},
tableCellFirst: {
borderTopWidth: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ function parseTable(lines: string[], startIndex: number): { table: MarkdownBlock
return { table: null, nextIndex: startIndex };
}

// Extract header cells from the first line, filtering out empty cells that may result from leading/trailing pipes
const headerLine = tableLines[0].trim();
// Extract header cells from the first line, stripping leading/trailing pipes but preserving empty interior cells
const headerLine = tableLines[0].trim().replace(/^\||\|$/g, '');
const headers = headerLine
.split('|')
.map(cell => cell.trim())
.filter(cell => cell.length > 0);
.map(cell => cell.trim());

if (headers.length === 0) {
return { table: null, nextIndex: startIndex };
Expand All @@ -39,15 +38,11 @@ function parseTable(lines: string[], startIndex: number): { table: MarkdownBlock
for (let i = 2; i < tableLines.length; i++) {
const rowLine = tableLines[i].trim();
if (rowLine.startsWith('|')) {
const rowCells = rowLine
const rowCells = rowLine.replace(/^\||\|$/g, '')
.split('|')
.map(cell => cell.trim())
.filter(cell => cell.length > 0);
.map(cell => cell.trim());

// Include rows that contain actual content, filtering out empty rows
if (rowCells.length > 0) {
rows.push(rowCells);
}
rows.push(rowCells);
}
}

Expand Down