Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add newline before super tables when rendering #179

Merged
merged 2 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Preserve the newlines before super tables when rendering. ([#178](https://github.com/sdispater/tomlkit/issues/178))

## [0.10.0] - 2022-02-18

### Fixed
Expand Down
16 changes: 16 additions & 0 deletions tests/test_toml_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tomlkit import parse
from tomlkit import ws
from tomlkit._utils import _utc
from tomlkit.api import document
from tomlkit.exceptions import NonExistentKey


Expand Down Expand Up @@ -927,3 +928,18 @@ def test_pop_add_whitespace_and_insert_table_work_togheter():
assert out["d"] == 4
assert "d" not in out["e"]
assert text == dedent(expected)


def test_add_newline_before_super_table():
doc = document()
doc["a"] = 1
doc["b"] = {"c": {}}
doc["d"] = {"e": {}}
expected = """\
a = 1

[b.c]

[d.e]
"""
assert doc.as_string() == dedent(expected)
2 changes: 2 additions & 0 deletions tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ def _render_table(
table.trivia.trail,
"\n" if "\n" not in table.trivia.trail and len(table.value) > 0 else "",
)
elif table.trivia.indent == "\n":
cur += table.trivia.indent

for k, v in table.value.body:
if isinstance(v, Table):
Expand Down