File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed
Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -349,3 +349,20 @@ Sphinx ``toctree``\s are hidden
349349 .. toctree ::
350350
351351 other
352+
353+ Line Blocks
354+ ~~~~~~~~~~~~
355+
356+ .. rest-example ::
357+
358+ The builder supports line blocks using pipe characters to preserve line breaks:
359+
360+ Nothing in between
361+
362+ |
363+
364+ Now something in between
365+
366+ | This is a line block
367+ | with multiple lines
368+ | preserved exactly as written
Original file line number Diff line number Diff line change @@ -225,6 +225,15 @@ def _process_rich_text_node(child: nodes.Node) -> Text:
225225 raise ValueError (unsupported_child_type_msg )
226226
227227
228+ @beartype
229+ @_process_rich_text_node .register
230+ def _ (child : nodes .line ) -> Text :
231+ """
232+ Process line nodes by creating rich text.
233+ """
234+ return _create_styled_text_from_node (child = child ) + "\n "
235+
236+
228237@beartype
229238@_process_rich_text_node .register
230239def _ (child : nodes .reference ) -> Text :
@@ -1497,6 +1506,23 @@ def _(
14971506 return []
14981507
14991508
1509+ @beartype
1510+ @_process_node_to_blocks .register
1511+ def _ (
1512+ node : nodes .line_block ,
1513+ * ,
1514+ section_level : int ,
1515+ ) -> list [Block ]:
1516+ """
1517+ Process line block nodes by creating separate paragraph blocks for each
1518+ line.
1519+ """
1520+ del section_level
1521+
1522+ line_text = _create_rich_text_from_children (node = node )
1523+ return [UnoParagraph (text = line_text )]
1524+
1525+
15001526@beartype
15011527class NotionTranslator (NodeVisitor ):
15021528 """
Original file line number Diff line number Diff line change @@ -3076,3 +3076,37 @@ def test_embed_and_video(
30763076 # We explain in the README that this is necessary.
30773077 confoverrides = {"suppress_warnings" : ["app.add_directive" ]},
30783078 )
3079+
3080+
3081+ def test_line_block (
3082+ * ,
3083+ make_app : Callable [..., SphinxTestApp ],
3084+ tmp_path : Path ,
3085+ ) -> None :
3086+ """
3087+ Line blocks (created with pipe character) become empty Notion paragraph
3088+ blocks.
3089+ """
3090+ rst_content = """
3091+ | This is a line block
3092+ | with multiple lines
3093+ | preserved exactly as written
3094+ """
3095+
3096+ expected_objects : list [Block ] = [
3097+ UnoParagraph (
3098+ text = text (text = "This is a line block" )
3099+ + text (text = "\n " )
3100+ + text (text = "with multiple lines" )
3101+ + text (text = "\n " )
3102+ + text (text = "preserved exactly as written" )
3103+ + text (text = "\n " )
3104+ ),
3105+ ]
3106+
3107+ _assert_rst_converts_to_notion_objects (
3108+ rst_content = rst_content ,
3109+ expected_objects = expected_objects ,
3110+ make_app = make_app ,
3111+ tmp_path = tmp_path ,
3112+ )
You can’t perform that action at this time.
0 commit comments