Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: blank line after table (#298)

Hyoban26aae0e6372b
diff --git a/web/src/labs/marked/marked.test.ts b/web/src/labs/marked/marked.test.ts
index 7db8477c4..cf7f9afb5 100644
--- a/web/src/labs/marked/marked.test.ts
+++ b/web/src/labs/marked/marked.test.ts
@@ -6,11 +6,15 @@ describe("test marked parser", () => {
test("test markdown table", () => {
const tests = [
{
- markdown: `| a | b | c |
+ markdown: `text above the table
+| a | b | c |
|---|---|---|
| 1 | 2 | 3 |
-| 4 | 5 | 6 |`,
- want: `<table>
+| 4 | 5 | 6 |
+text below the table
+`,
+ want: `<p>text above the table</p>
+<table>
<thead>
<tr>
<th>a</th><th>b</th><th>c</th>
@@ -19,7 +23,9 @@ describe("test marked parser", () => {
<tbody>
<tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr>
</tbody>
-</table>`,
+</table>
+<p>text below the table</p>
+`,
},
{
markdown: `| a | b | c |
diff --git a/web/src/labs/marked/parser/Table.ts b/web/src/labs/marked/parser/Table.ts
index 050c8446a..e267a3cd1 100644
--- a/web/src/labs/marked/parser/Table.ts
+++ b/web/src/labs/marked/parser/Table.ts
@@ -6,7 +6,7 @@
* | 1 | 2 | 3 |
* | 4 | 5 | 6 |
*/
-export const TABLE_REG = /^(\|.*\|)(?:(?:\n(?:\|-*)+\|))((?:\n\|.*\|)+)/;
+export const TABLE_REG = /^(\|.*\|)(?:(?:\n(?:\|-*)+\|))((?:\n\|.*\|)+)(\n?)/;
const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(TABLE_REG);
@@ -35,7 +35,7 @@ const renderer = (rawStr: string): string => {
<tbody>
${tableBody.map((row) => `<tr>${row.map((str) => `<td>${str}</td>`).join("")}</tr>`).join("")}
</tbody>
-</table>`;
+</table>${matchResult[3]}`;
};
export default {