diff --git a/renoir/parsing/contents.py b/renoir/parsing/contents.py index cdb5601..fe883ca 100644 --- a/renoir/parsing/contents.py +++ b/renoir/parsing/contents.py @@ -117,9 +117,10 @@ def __init__(self, parent: Element): text=line, indent=0, original_indent=0, - ignore_reindent=False + ignore_reindent=False, + offset=idx ) - for line in self.parent.text.split('\n') + for idx, line in enumerate(self.parent.text.split('\n')) ] @property diff --git a/renoir/parsing/parsers.py b/renoir/parsing/parsers.py index fc39651..d9ce1b4 100644 --- a/renoir/parsing/parsers.py +++ b/renoir/parsing/parsers.py @@ -225,14 +225,22 @@ class IndentTemplateParser(TemplateParser): re_wspace = re.compile("^( *)") def parse_plain_block(self, ctx, element): + current_line, new_line = ctx.state.lines.end, False lines_element = element.split() ctx.update_lines_count(lines_element.linesn) + if ctx.state.lines.start != current_line: + new_line = True for line in lines_element.lines: + if line.offset: + new_line = True + if not new_line: + continue indent = len(self.re_wspace.search(line.text).group(0)) ctx.state.indent = indent ctx.state.offset = len(line.text) - indent line.text = line.text[indent:] line.indent = ctx.state.indent + new_line = False ctx._plain(WrappedNode, lines_element) diff --git a/tests/test_render.py b/tests/test_render.py index e4b38dd..a3e8c07 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -70,6 +70,11 @@ def templater_html_indent(): - foo - 1 - 1.2 + - bar: foo bar + - bar2: foo foo2 bar + - bar3: foo foo2 bar bar2 + - bar3: foo foo2 barbar2 + - bar4: foo foo2 barbar2 bar3 """ @@ -96,6 +101,11 @@ def test_plain(templater): - foo - foo: bar array: [] + - bar: foo bar + - bar2: foo foo2 bar + - bar3: foo foo2 bar bar2 + - bar3: foo foo2 barbar2 + - bar4: foo foo2 barbar2 bar3 inclusion: - inclusion_key: inclusion_val inclusion_nest: diff --git a/tests/yaml/basic.yaml b/tests/yaml/basic.yaml index 532a091..de269ee 100644 --- a/tests/yaml/basic.yaml +++ b/tests/yaml/basic.yaml @@ -17,3 +17,8 @@ obj: - foo - {{ =1 }} - {{ =2.4 / 2 }} + - bar: {{ ="foo" }} bar + - bar2: {{ ="foo" }} foo2 {{ ="bar" }} + - bar3: {{ ="foo" }} foo2 {{ ="bar" }} bar2 + - bar3: {{ ="foo" }} foo2 {{ ="bar" }}{{ ="bar2" }} + - bar4: {{ ="foo" }} foo2 {{ ="bar" }}{{ ="bar2" }} bar3 diff --git a/tests/yaml/blocks.yaml b/tests/yaml/blocks.yaml index b7df61d..34387fd 100644 --- a/tests/yaml/blocks.yaml +++ b/tests/yaml/blocks.yaml @@ -10,4 +10,9 @@ obj: - foo - foo: bar array: {{ block array }}[]{{ end }} + - bar: {{ ="foo" }} bar + - bar2: {{ ="foo" }} foo2 {{ ="bar" }} + - bar3: {{ ="foo" }} foo2 {{ ="bar" }} bar2 + - bar3: {{ ="foo" }} foo2 {{ ="bar" }}{{ ="bar2" }} + - bar4: {{ ="foo" }} foo2 {{ ="bar" }}{{ ="bar2" }} bar3 {{ include }}