AH-Hammi / pandoc-grid-table

MIT License
1 stars 0 forks source link

Format table get unexpected right aligment #1

Open riyueniao opened 2 weeks ago

riyueniao commented 2 weeks ago

My input grid table.

+-----+-------------------------+
| No. | Description             |
+:===:+=========================+
| 1   | - This is a long string |
|     |   + Short string        |
|     |   + Short string        |
|     |   + Short string        |
|     |   + Short string        |
|     |   + Short string        |
+-----+-------------------------+

After pressing TAB. formatted table as below. which is not the format I expected, and will cause the list not working.

+-----+-------------------------+
| No. | Description             |
+:===:+=========================+
| 1   | - This is a long string |
|     |          + Short string |
|     |          + Short string |
|     |          + Short string |
|     |          + Short string |
|     |          + Short string |
+-----+-------------------------+
AH-Hammi commented 2 weeks ago

Hey Preston thanks for sharing this issue with me I will look into it once I have time again

AH-Hammi commented 2 weeks ago

Hey Preston, this issue comes due to a missing check. It is only right aligned due to the "+" char which indicates a new cell. I think I there should be a check if we have a valid cell separator above or something.

Thanks for opening

riyueniao commented 2 weeks ago

Hi Hammi, I have fixed this issue in my local git repository. Can you give me permission to create a pull request?

AH-Hammi commented 2 weeks ago

Hey Preston, did you implement a test for the new case and gone ahead and tested your code? I want to have 100% Coverage on all scripts except the extension.ts file. Just run `npm run coverage and take a look at the coverage report.

And maybe add a test with your example with the expected result.

Afterwards you can open a pull request. Thanks for your participation 😄

riyueniao commented 1 week ago

Looks like | and + in a table cell are special cases. Which will cause the below code to create incorrect table cells.

if (char === "|" || char === "+") {
    // create a new cell with the current cell string
    this._cells.push(new TableCell(current_cell_str));
    // reset the current cell string
    current_cell_str = char;
}
riyueniao commented 1 week ago

Hi, I have fixed another issue by checking the table cell is valid using a regex.

+--------------------+----------+--------------------+
| Properties         | Earth    | Properties         |
+=============+======+==========+=============+======+
|             | min  | -89.2 °C |             | min  |
| Temperature +------|          | Temperature +------|
| 1961-1990   | mean | 14 °C    | 1961-1990   | mean |
|             +------+----------+             |      |
|             | max  | 56.7 °C  |             | max  |
+-------------+------+----------+-------------+------+

Following is the coverage result.

-----------------|---------|----------|---------|---------|--------------------------------------------------------------------------------------
File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|--------------------------------------------------------------------------------------
All files        |   56.23 |    96.24 |   73.86 |   56.23 |
 commands.ts     |     100 |      100 |     100 |     100 |
 commands.ts     |    9.67 |      100 |    12.5 |    9.67 | 22-68,71-105,107-150,152-200,202-259,262-288,291-310
 extension.ts    |     100 |      100 |     100 |     100 |
 table.ts        |     100 |      100 |     100 |     100 |
 table.ts        |    6.19 |        0 |       0 |    6.19 | 15-82,85-193,196-252,255-323
 table_cell.ts   |     100 |      100 |     100 |     100 |
 table_cell.ts   |    4.54 |       50 |       0 |    4.54 | 6-46,49-154
 table_column.ts |     100 |      100 |     100 |     100 |
 table_column.ts |   18.42 |        0 |       0 |   18.42 | 8-38
 table_row.ts    |     100 |      100 |     100 |     100 |
 table_row.ts    |    3.89 |        0 |       0 |    3.89 | 4-77
 text_utility.ts |     100 |      100 |     100 |     100 |
 text_utility.ts |   23.64 |       80 |   11.11 |   23.64 | 15-16,32-34,50-52,63-65,77-87,89-109,111-142,144-170,173-226,229-282,284-292,294-313
-----------------|---------|----------|---------|---------|--------------------------------------------------------------------------------------
AH-Hammi commented 1 week ago

Could you fork the repository to your own GitHub account and push the changes there? Then I will be able to review your code and check what you did, because I would really like to understand what you did with regex :smile:

riyueniao commented 4 days ago

You can check it with diff.log