From d74d5fd5fd436bf6d4ab584f6ce1121f6479d3d6 Mon Sep 17 00:00:00 2001 From: Sam'an Herman-Griffiths <100145229+sHermanGriffiths@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:09:24 -0500 Subject: [PATCH] Shg/linebreaks (#162) * stop filtering linebreaks from table cells Signed-off-by: Sam'an Herman-Griffiths (Innolitics) * flake8 Signed-off-by: Sam'an Herman-Griffiths (Innolitics) * modify tests to include linebreaks in table cell Signed-off-by: Sam'an Herman-Griffiths (Innolitics) --------- Signed-off-by: Sam'an Herman-Griffiths (Innolitics) --- n2y/blocks.py | 19 ------------------- tests/test_blocks.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/n2y/blocks.py b/n2y/blocks.py index e6a8151c..ea603338 100644 --- a/n2y/blocks.py +++ b/n2y/blocks.py @@ -16,7 +16,6 @@ Header, HorizontalRule, Image, - LineBreak, Link, Math, OrderedList, @@ -27,7 +26,6 @@ Row, RowHeadColumns, RowSpan, - Space, Str, Table, TableBody, @@ -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( ("", [], []), @@ -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): diff --git a/tests/test_blocks.py b/tests/test_blocks.py index 18290560..dace9ca0 100644 --- a/tests/test_blocks.py +++ b/tests/test_blocks.py @@ -20,6 +20,7 @@ Header, HorizontalRule, Image, + LineBreak, Link, Math, Meta, @@ -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")], ] }, @@ -573,7 +574,7 @@ def test_table_block(): AlignDefault(), RowSpan(1), ColSpan(1), - [Plain([Str("three")])], + [Plain([Str("three"), LineBreak(), Str("3.5")])], ), Cell( ("", [], []), @@ -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" )