-
Notifications
You must be signed in to change notification settings - Fork 1
fix(frontend): render markdown tables in post bodies #389
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
Changes from all commits
1ebacdf
0d8b6f4
7b551bf
3880376
0c2f706
5118500
d4a486b
788bacd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,20 +172,44 @@ function stripHtmlTags(text: string): string { | |
| function splitSemanticParagraphs(text: string): string[] { | ||
| const paragraphs: string[] = []; | ||
| let lines: string[] = []; | ||
| let pipeTableRows: string[] = []; | ||
| const flush = () => { | ||
| const paragraph = lines.join(" ").trimEnd(); | ||
| if (paragraph.trim()) paragraphs.push(paragraph); | ||
| lines = []; | ||
| }; | ||
| const flushPipeTableRows = () => { | ||
| const hasSeparator = pipeTableRows.some((row) => { | ||
| const cells = row.trim().replace(/^\|/, "").replace(/\|$/, "").split("|"); | ||
| return cells.length >= 2 && cells.every((cell) => /^\s*:?-{3,}:?\s*$/.test(cell)); | ||
| }); | ||
| if (pipeTableRows.length >= 2 && hasSeparator) { | ||
| flush(); | ||
| paragraphs.push(pipeTableRows.map((row) => row.trim()).join("\n")); | ||
| } else { | ||
| lines.push(...pipeTableRows); | ||
| } | ||
| pipeTableRows = []; | ||
| }; | ||
|
seonghobae marked this conversation as resolved.
Comment on lines
+181
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Separator accepted anywhere when grouping, required at row 1 when rendering
Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| for (const line of text.split("\n")) { | ||
| const trimmed = line.trim(); | ||
| if (trimmed.includes("|")) { | ||
| const cells = trimmed.replace(/^\|/, "").replace(/\|$/, "").split("|"); | ||
| if (cells.length >= 2 && cells.some((cell) => cell.trim())) { | ||
| pipeTableRows.push(line); | ||
| continue; | ||
| } | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| } | ||
| if (pipeTableRows.length > 0) flushPipeTableRows(); | ||
|
seonghobae marked this conversation as resolved.
Comment on lines
+197
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Pipe-bearing list items merge into one paragraph A line containing Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| if (!line.trim()) { | ||
| flush(); | ||
| continue; | ||
| } | ||
| if (lines.length > 0 && LIST_ITEM_START.test(line)) flush(); | ||
| lines.push(lines.length === 0 ? line.replace(/[ \t]+$/g, "") : line.trim()); | ||
| } | ||
| if (pipeTableRows.length > 0) flushPipeTableRows(); | ||
| flush(); | ||
| return paragraphs; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.