Skip to content

Commit 402d962

Browse files
Merge pull request #358 from adamtheturtle/file
Support the :file: role
2 parents c603094 + d5ab382 commit 402d962

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

sample/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Text Formatting
3535

3636
The builder supports keyboard shortcuts using the standard ``:kbd:`` role: Press :kbd:`Ctrl+C` to copy, :kbd:`Ctrl+V` to paste.
3737

38+
The builder supports file paths using the standard ``:file:`` role: Edit the :file:`config.py` file or check :file:`/etc/hosts`.
39+
3840
Admonitions
3941
~~~~~~~~~~~
4042

src/sphinx_notion/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ def _create_styled_text_from_node(*, node: nodes.Element) -> Text:
366366
isinstance(node, nodes.literal)
367367
or "text-mono" in classes
368368
or "kbd" in classes
369+
or "file" in classes
369370
)
370371
is_strikethrough = (
371372
isinstance(node, strike_node) or "text-strike" in classes
@@ -379,6 +380,7 @@ def _create_styled_text_from_node(*, node: nodes.Element) -> Text:
379380
"text-strike",
380381
"text-underline",
381382
"kbd",
383+
"file",
382384
*color_mapping.keys(),
383385
*bg_color_classes,
384386
}

tests/test_integration.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,37 @@ def test_kbd_role(
28472847
)
28482848

28492849

2850+
def test_file_role(
2851+
*,
2852+
make_app: Callable[..., SphinxTestApp],
2853+
tmp_path: Path,
2854+
) -> None:
2855+
"""The ``:file:`` role creates file path formatting.
2856+
2857+
File paths should be rendered as inline code.
2858+
"""
2859+
rst_content = """
2860+
Edit the :file:`config.py` file.
2861+
"""
2862+
2863+
normal_text1 = text(text="Edit the ")
2864+
file_text = text(text="config.py", code=True)
2865+
normal_text2 = text(text=" file.")
2866+
2867+
combined_text = normal_text1 + file_text + normal_text2
2868+
2869+
expected_paragraph = UnoParagraph(text=combined_text)
2870+
2871+
expected_objects: list[Block] = [expected_paragraph]
2872+
2873+
_assert_rst_converts_to_notion_objects(
2874+
rst_content=rst_content,
2875+
expected_objects=expected_objects,
2876+
make_app=make_app,
2877+
tmp_path=tmp_path,
2878+
)
2879+
2880+
28502881
def test_unsupported_node_types_in_rich_text(
28512882
*,
28522883
make_app: Callable[..., SphinxTestApp],

0 commit comments

Comments
 (0)