[ADD] таблицы по ГОСТ: подпись сверху и выравнивание колонок
Подпись «Таблица N —— Название» абзацем над таблицей превращается в float table[H] с \caption сверху (labelsep=emdash, name=Таблица, выключка влево), номер отбрасывается — нумерует LaTeX. Выравнивание колонок берётся из строки-разделителя GFM: :--- , :---: , ---: . Таблица без подписи по-прежнему рендерится голым tabular.
This commit is contained in:
+41
-2
@@ -33,7 +33,7 @@ def test_figure_with_caption(tmp_path) -> None:
|
||||
"![[images/antenna.png]]\n\nРисунок 1 — Антенна\n\n"
|
||||
"Данная антенна используется для ...\n"
|
||||
)
|
||||
assert "\\begin{figure}[ht]" in tex
|
||||
assert "\\begin{figure}[H]" in tex
|
||||
assert "\\centering" in tex
|
||||
assert (
|
||||
"\\includegraphics[width=0.8\\textwidth]{\\detokenize{images/antenna.png}}"
|
||||
@@ -45,7 +45,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}[ht]" in tex
|
||||
assert "\\begin{figure}[H]" in tex
|
||||
assert "\\caption{" not in tex
|
||||
assert "Обычный абзац после картинки." in tex
|
||||
|
||||
@@ -100,3 +100,42 @@ def _figure_block(tex: str) -> str:
|
||||
start = tex.index("\\begin{figure}")
|
||||
end = tex.index("\\end{figure}") + len("\\end{figure}")
|
||||
return tex[start:end]
|
||||
|
||||
|
||||
TABLE_MD = (
|
||||
"Таблица 1 —— Сравнение скорости\n\n"
|
||||
"| № Запуска | Python (сек) | C++ (сек) |\n"
|
||||
"| :--- | :---: | ---: |\n"
|
||||
"| **1** | 0.027852 | 0.000285 |\n"
|
||||
)
|
||||
|
||||
|
||||
def test_table_with_caption() -> None:
|
||||
tex = render(TABLE_MD)
|
||||
assert "\\begin{table}[H]" in tex
|
||||
assert "\\caption{Сравнение скорости}" in tex
|
||||
assert "\\begin{tabular}{|l|c|r|}" in tex
|
||||
assert "\\textbf{1} & 0.027852 & 0.000285 \\\\" in tex
|
||||
|
||||
|
||||
def test_table_caption_number_is_discarded() -> None:
|
||||
tex = render(TABLE_MD)
|
||||
block = _table_block(tex)
|
||||
assert "Таблица 1" not in block
|
||||
|
||||
|
||||
def test_table_without_caption_stays_bare() -> None:
|
||||
tex = render("| a | b |\n| --- | --- |\n| 1 | 2 |\n")
|
||||
assert "\\begin{table}" not in tex
|
||||
assert "\\begin{tabular}{|l|l|}" in tex
|
||||
|
||||
|
||||
def test_table_caption_paragraph_is_not_duplicated() -> None:
|
||||
tex = render(TABLE_MD)
|
||||
assert tex.count("Сравнение скорости") == 1
|
||||
|
||||
|
||||
def _table_block(tex: str) -> str:
|
||||
start = tex.index("\\begin{table}")
|
||||
end = tex.index("\\end{table}") + len("\\end{table}")
|
||||
return tex[start:end]
|
||||
|
||||
Reference in New Issue
Block a user