[FIX] рисунки, таблицы и листинги плавают: нет пустых страниц и разрывов рамки

This commit is contained in:
Arseny
2026-09-02 13:10:18 +03:00
parent a3d41af022
commit 2a0333c673
5 changed files with 35 additions and 15 deletions
+21 -9
View File
@@ -48,7 +48,7 @@ def test_figure_with_caption(tmp_path) -> None:
"![[images/antenna.png]]\n\nРисунок 1 — Антенна\n\n"
"Данная антенна используется для ...\n"
)
assert "\\begin{figure}[H]" in tex
assert "\\begin{figure}[ht]" in tex
assert "\\centering" in tex
assert (
"\\includegraphics[width=0.8\\textwidth]{\\detokenize{images/antenna.png}}"
@@ -60,7 +60,7 @@ def test_figure_with_caption(tmp_path) -> None:
def test_figure_without_caption() -> None:
tex = render("![[images/photo.png]]\n\nОбычный абзац после картинки.\n")
assert "\\begin{figure}[H]" in tex
assert "\\begin{figure}[ht]" in tex
assert "\\caption{" not in tex
assert "Обычный абзац после картинки." in tex
@@ -127,7 +127,7 @@ TABLE_MD = (
def test_table_with_caption() -> None:
tex = render(TABLE_MD)
assert "\\begin{table}[H]" in tex
assert "\\begin{table}[ht]" in tex
assert "\\caption{Сравнение скорости}" in tex
assert "\\begin{tabularx}{\\textwidth}" in tex
assert "\\textbf{1} & 0.027852 & 0.000285 \\\\" in tex
@@ -334,7 +334,7 @@ LISTING_MD = (
def test_listing_with_caption() -> None:
tex = render(LISTING_MD)
assert "caption={Потокобезопасная очередь}" in tex
assert "language=[modern]C++" in tex
assert "language={[modern]C++}" in tex
assert "class ThreadSafeQueue {};" in tex
@@ -350,14 +350,14 @@ def test_listing_caption_paragraph_is_not_duplicated() -> None:
def test_listing_without_caption_stays_bare() -> None:
tex = render("```cpp\nint main() {}\n```\n")
assert "\\begin{lstlisting}[language=[modern]C++]" in tex
assert "\\begin{lstlisting}[language={[modern]C++}]" in tex
assert "caption=" not in tex
def test_listing_caption_without_language() -> None:
tex = render("Листинг 2 —— Формат строки\n\n```\nid,freq,power\n```\n")
assert "caption={Формат строки}" in tex
assert "language=" not in tex
assert "language={" not in tex
def test_paragraph_starting_with_listing_word_is_not_a_caption() -> None:
@@ -369,12 +369,12 @@ def test_paragraph_starting_with_listing_word_is_not_a_caption() -> None:
def test_listing_language_is_mapped_to_listings_name() -> None:
"""listings не знает 'cpp', только 'C++'."""
tex = render("```cpp\nint x;\n```\n")
assert "language=[modern]C++" in tex
assert "language={[modern]C++}" in tex
def test_listing_unsupported_language_falls_back_to_plain() -> None:
tex = render("```yaml\nkey: value\n```\n")
assert "language=" not in tex
assert "language={" not in tex
assert "key: value" in tex
@@ -485,4 +485,16 @@ def test_abbreviation_table_has_no_extra_column_padding() -> None:
def test_cpp_uses_extended_dialect() -> None:
"""Встроенный C++ в listings не знает auto, nullptr и override."""
tex = body(render("```cpp\nauto x = nullptr;\n```\n"))
assert "language=[modern]C++" in tex
assert "language={[modern]C++}" in tex
def test_captioned_listing_floats() -> None:
"""Неплавающий листинг рвётся между страницами с незамкнутой рамкой."""
tex = body(render(LISTING_MD))
assert "float=htbp" in tex
def test_bare_listing_does_not_float() -> None:
"""Фрагмент без подписи — часть абзаца, ему плавать незачем."""
tex = body(render("```cpp\nint x;\n```\n"))
assert "float=" not in tex