diff --git a/import2ledger/template.py b/import2ledger/template.py index 2554d2c..9b7cf10 100644 --- a/import2ledger/template.py +++ b/import2ledger/template.py @@ -165,7 +165,7 @@ class AccountSplitter: account_s = account.format_map(template_vars) amount_s = babel.numbers.format_currency(amount, template_vars['currency'], amt_fmt) sep_len = max(2, self.TARGET_ACCTLINE_LEN - len(account_s) - len(amount_s)) - yield ' {}{}{}\n{}'.format( + yield '\n {}{}{}{}'.format( account_s, ' ' * sep_len, amount_s, metadata.format_map(template_vars), ) @@ -214,14 +214,12 @@ class Template: amount_expr = line[match.end():] self.splitter.add(account, amount_expr) self.format_funcs.append(self.splitter.render_next) - if metadata: - self._add_str_func(metadata) - if not metadata[-1].endswith('\n'): - self.format_funcs.append('\n'.format_map) + self._add_str_func(metadata) + self.format_funcs.append('\n'.format_map) def _nonblank_lines(self, s): for line in s.splitlines(True): - line = line.lstrip() + line = line.strip() if line: yield line @@ -234,12 +232,12 @@ class Template: if self.PAYEE_LINE_RE.match(line1): yield '\n' + line1 else: - yield '\n{date} {payee}\n' + yield '\n{date} {payee}' yield line1 yield from lines def _add_str_func(self, str_seq): - str_flat = ''.join(' ' + s for s in str_seq) + str_flat = ''.join('\n ' + s for s in str_seq) if not str_flat: pass elif self.splitter.is_empty():