Skip to content

Commit

Permalink
Shg/linebreaks (#162)
Browse files Browse the repository at this point in the history
* stop filtering linebreaks from table cells

Signed-off-by: Sam'an Herman-Griffiths (Innolitics) <[email protected]>

* flake8

Signed-off-by: Sam'an Herman-Griffiths (Innolitics) <[email protected]>

* modify tests to include linebreaks in table cell

Signed-off-by: Sam'an Herman-Griffiths (Innolitics) <[email protected]>

---------

Signed-off-by: Sam'an Herman-Griffiths (Innolitics) <[email protected]>
  • Loading branch information
sHermanGriffiths authored Oct 31, 2023
1 parent 1d690d3 commit d74d5fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
19 changes: 0 additions & 19 deletions n2y/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Header,
HorizontalRule,
Image,
LineBreak,
Link,
Math,
OrderedList,
Expand All @@ -27,7 +26,6 @@
Row,
RowHeadColumns,
RowSpan,
Space,
Str,
Table,
TableBody,
Expand Down Expand Up @@ -673,7 +671,6 @@ def to_pandoc(self):
cells = []
for cell in self.cells:
pandoc = cell.to_pandoc()
pandoc = self.filter_linebreaks(pandoc)
cells.append(
Cell(
("", [], []),
Expand All @@ -685,22 +682,6 @@ def to_pandoc(self):
)
return Row(("", [], []), cells)

def filter_linebreaks(self, ast_list):
for i, ast in enumerate(ast_list):
# A BulletList contains an array of AST arrays, so it wouldn't have a __dict__ attribute
if isinstance(ast, list):
self.filter_linebreaks(ast)
continue

args = ast.__dict__["_args"]
if len(args) and isinstance(args[0], list):
self.filter_linebreaks(args[0])
continue

if isinstance(ast, LineBreak):
ast_list[i] = Space()
return ast_list


class ColumnListBlock(Block):
def __init__(self, client, notion_data, page, get_children=True):
Expand Down
12 changes: 8 additions & 4 deletions tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Header,
HorizontalRule,
Image,
LineBreak,
Link,
Math,
Meta,
Expand Down Expand Up @@ -505,7 +506,7 @@ def test_table_block():
"table_row",
{
"cells": [
[mock_rich_text("three")],
[mock_rich_text("three\n3.5")],
[mock_rich_text("four")],
]
},
Expand Down Expand Up @@ -573,7 +574,7 @@ def test_table_block():
AlignDefault(),
RowSpan(1),
ColSpan(1),
[Plain([Str("three")])],
[Plain([Str("three"), LineBreak(), Str("3.5")])],
),
Cell(
("", [], []),
Expand All @@ -591,10 +592,13 @@ def test_table_block():
)
assert (
markdown
== " header1 header2\n"
== " -------------------\n"
" header1 header2\n"
" --------- ---------\n"
" one two\n"
" three four\n"
"\n three\\ four\n"
" 3.5 \n "
"-------------------\n"
)


Expand Down

0 comments on commit d74d5fd

Please sign in to comment.