Unverified Commit 26aae0e6 authored by Hyoban's avatar Hyoban Committed by GitHub

fix: blank line after table (#298)

parent 95c8d8fc
...@@ -6,11 +6,15 @@ describe("test marked parser", () => { ...@@ -6,11 +6,15 @@ describe("test marked parser", () => {
test("test markdown table", () => { test("test markdown table", () => {
const tests = [ const tests = [
{ {
markdown: `| a | b | c | markdown: `text above the table
| a | b | c |
|---|---|---| |---|---|---|
| 1 | 2 | 3 | | 1 | 2 | 3 |
| 4 | 5 | 6 |`, | 4 | 5 | 6 |
want: `<table> text below the table
`,
want: `<p>text above the table</p>
<table>
<thead> <thead>
<tr> <tr>
<th>a</th><th>b</th><th>c</th> <th>a</th><th>b</th><th>c</th>
...@@ -19,7 +23,9 @@ describe("test marked parser", () => { ...@@ -19,7 +23,9 @@ describe("test marked parser", () => {
<tbody> <tbody>
<tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr> <tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr>
</tbody> </tbody>
</table>`, </table>
<p>text below the table</p>
`,
}, },
{ {
markdown: `| a | b | c | markdown: `| a | b | c |
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* | 1 | 2 | 3 | * | 1 | 2 | 3 |
* | 4 | 5 | 6 | * | 4 | 5 | 6 |
*/ */
export const TABLE_REG = /^(\|.*\|)(?:(?:\n(?:\|-*)+\|))((?:\n\|.*\|)+)/; export const TABLE_REG = /^(\|.*\|)(?:(?:\n(?:\|-*)+\|))((?:\n\|.*\|)+)(\n?)/;
const renderer = (rawStr: string): string => { const renderer = (rawStr: string): string => {
const matchResult = rawStr.match(TABLE_REG); const matchResult = rawStr.match(TABLE_REG);
...@@ -35,7 +35,7 @@ const renderer = (rawStr: string): string => { ...@@ -35,7 +35,7 @@ const renderer = (rawStr: string): string => {
<tbody> <tbody>
${tableBody.map((row) => `<tr>${row.map((str) => `<td>${str}</td>`).join("")}</tr>`).join("")} ${tableBody.map((row) => `<tr>${row.map((str) => `<td>${str}</td>`).join("")}</tr>`).join("")}
</tbody> </tbody>
</table>`; </table>${matchResult[3]}`;
}; };
export default { export default {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment