Spacing#
Basic access#
Spacing (whitespace, tab, or newline) can be accessed in the similar way as other optional properties, through raw_spacing_before, spacing_before, raw_spacing_after, and spacing_after.
Note
Indentation is NOT considered as spacing here.
file = p.parse('''\
2000-01-01 open Assets:Foo
\t
2000-01-02close Assets:Foo
''', models.File)
open, close = file.directives
Read:
(close.spacing_before, close.raw_spacing_before)
('\n\n\t\n\n',
(<Newline: '\n'>,
<Newline: '\n'>,
<Whitespace: '\t'>,
<Newline: '\n'>,
<Newline: '\n'>))
(close.raw_date.spacing_after, close.raw_date.raw_spacing_after)
('', ())
Write:
close.spacing_before = '\n\n'
_print_model(file)
2000-01-01 open Assets:Foo
2000-01-02close Assets:Foo
Ownership#
Unlikely other models, spacing has no ownership. In the example above, the space between open and close can be accessed through both open.spacing_after and close.spacing_before.
(open.raw_spacing_after, close.raw_spacing_before)
((<Newline: '\n'>, <Newline: '\n'>), (<Newline: '\n'>, <Newline: '\n'>))