Skip to content

Commit 804bf17

Browse files
Merge pull request #296 from adamtheturtle/line-no
Add line numbers to all warnings
2 parents 2268fcb + 1ab7494 commit 804bf17

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/sphinx_notion/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,13 @@ def _create_styled_text_from_node(*, child: nodes.Element) -> Text:
370370
]
371371

372372
if unsupported_styles:
373-
_LOGGER.warning(
374-
"Unsupported text style classes: %s. "
375-
"Text will be rendered without styling.",
376-
", ".join(unsupported_styles),
373+
unsupported_style_msg = (
374+
"Unsupported text style classes: "
375+
f"{', '.join(unsupported_styles)}. "
376+
f"Text on line {child.parent.line} in {child.parent.source} will "
377+
"be rendered without styling."
377378
)
379+
_LOGGER.warning(unsupported_style_msg)
378380

379381
color: BGColor | Color | None = bg_color or text_color
380382
return text(
@@ -664,9 +666,15 @@ def _(
664666
_LOGGER.warning(msg=table_multiple_header_rows_msg)
665667

666668
if table_structure.num_stub_columns > 1:
669+
first_body_row = table_structure.body_rows[0]
670+
first_body_row_entry = first_body_row.children[0]
671+
first_body_row_paragraph = first_body_row_entry.children[0]
667672
table_more_than_one_stub_column_msg = (
668673
f"Tables with more than 1 stub column are not supported. "
669-
f"Found {table_structure.num_stub_columns} stub columns."
674+
f"Found {table_structure.num_stub_columns} stub columns "
675+
f"on table with first body row on line "
676+
f"{first_body_row_paragraph.line} in "
677+
f"{first_body_row_paragraph.source}."
670678
)
671679
_LOGGER.warning(msg=table_more_than_one_stub_column_msg)
672680

tests/test_integration.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,8 @@ def test_list_table_stub_columns_two(
19991999

20002000
expected_warning = (
20012001
"Tables with more than 1 stub column are not supported. "
2002-
"Found 2 stub columns."
2002+
"Found 2 stub columns on table with first body row on line 8 in "
2003+
f"{tmp_path / 'src' / 'index.rst'}."
20032004
)
20042005

20052006
table = UnoTable(n_rows=3, n_cols=3, header_row=True, header_col=True)
@@ -2330,7 +2331,8 @@ def test_text_styles_unsupported_color(
23302331

23312332
expected_warning = (
23322333
"Unsupported text style classes: text-cyan. "
2333-
"Text will be rendered without styling."
2334+
f"Text on line 1 in {tmp_path / 'src' / 'index.rst'} will be rendered "
2335+
"without styling."
23342336
)
23352337

23362338
normal_text = text(text="This is ")

0 commit comments

Comments
 (0)