Skip to content

Commit 6b07f34

Browse files
Merge pull request #279 from adamtheturtle/title-reference
Handle title references
2 parents a824200 + 86d1dd9 commit 6b07f34

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/sphinx_notion/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ def _create_rich_text_from_children(*, node: nodes.Element) -> Text:
192192
strikethrough=isinstance(child, strike_node),
193193
color=_color_from_node(node=child),
194194
)
195+
elif isinstance(child, nodes.title_reference):
196+
# We match the behavior of the HTML builder here.
197+
# If you render ``A `B``` in HTML, it will render as
198+
# ``A <i>B</i>``.
199+
new_text = text(
200+
text=child.astext(),
201+
italic=True,
202+
)
195203
else:
196204
new_text = text(
197205
text=child.astext(),

tests/test_integration.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,8 +2581,7 @@ def test_nested_task_list(
25812581
* [x] Task B2
25822582
* [ ] Task B3
25832583
2584-
A rogue paragraph with a reference to
2585-
the `parent task_list <task_list_example>`.
2584+
A rogue paragraph.
25862585
25872586
- A list item without a checkbox.
25882587
- [ ] Another bullet point.
@@ -2603,11 +2602,7 @@ def test_nested_task_list(
26032602
# The rogue paragraph is nested within Task B
26042603
# Note: The actual output has the text split across multiple rich text
26052604
# segments
2606-
rogue_paragraph = UnoParagraph(
2607-
text=text(text="A rogue paragraph with a reference to\nthe ")
2608-
+ text(text="parent task_list <task_list_example>")
2609-
+ text(text=".")
2610-
)
2605+
rogue_paragraph = UnoParagraph(text=text(text="A rogue paragraph."))
26112606
task_b.append(blocks=[rogue_paragraph])
26122607

26132608
# Regular bullet list items should be nested within Task B as bullet items
@@ -2668,3 +2663,25 @@ def test_task_list_quote(
26682663
tmp_path=tmp_path,
26692664
extensions=("sphinx_notion", "sphinx_immaterial.task_lists"),
26702665
)
2666+
2667+
2668+
def test_inline_single_backticks(
2669+
*,
2670+
make_app: Callable[..., SphinxTestApp],
2671+
tmp_path: Path,
2672+
) -> None:
2673+
"""
2674+
Reproduces a bug where we got confused by mismatching blocks.
2675+
"""
2676+
rst_content = """
2677+
A `B`
2678+
"""
2679+
expected_objects: list[Block] = [
2680+
UnoParagraph(text=text(text="A ") + text(text="B", italic=True)),
2681+
]
2682+
_assert_rst_converts_to_notion_objects(
2683+
rst_content=rst_content,
2684+
expected_objects=expected_objects,
2685+
make_app=make_app,
2686+
tmp_path=tmp_path,
2687+
)

0 commit comments

Comments
 (0)