Skip to content

Commit

Permalink
Merge pull request python-poetry#179 from sdispater:fix/newline-befor…
Browse files Browse the repository at this point in the history
…e-super-table

Fix: Add newline before super tables when rendering
  • Loading branch information
frostming committed Feb 22, 2022
2 parents 09f1e7b + 093580a commit a4bb796
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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

0 comments on commit a4bb796

Please sign in to comment.