diff --git a/vlib/v/parser/tmpl.v b/vlib/v/parser/tmpl.v index 1679e5b905..548e913f87 100644 --- a/vlib/v/parser/tmpl.v +++ b/vlib/v/parser/tmpl.v @@ -10,7 +10,7 @@ import strings const tmpl_str_start = "sb.write_string('" -const tmpl_str_end = "' ) " +const tmpl_str_end = "')\n" enum State { html @@ -78,14 +78,13 @@ mut sb := strings.new_builder($lstartlength)\n mut start_of_line_pos := 0 mut tline_number := -1 // keep the original line numbers, even after insert/delete ops on lines; `i` changes for i := 0; i < lines.len; i++ { - oline := lines[i] + line := lines[i] tline_number++ start_of_line_pos = end_of_line_pos - end_of_line_pos += oline.len + 1 + end_of_line_pos += line.len + 1 $if trace_tmpl ? { - eprintln('>>> tfile: $template_file, spos: ${start_of_line_pos:6}, epos:${end_of_line_pos:6}, fi: ${tline_number:5}, i: ${i:5}, line: $oline') + eprintln('>>> tfile: $template_file, spos: ${start_of_line_pos:6}, epos:${end_of_line_pos:6}, fi: ${tline_number:5}, i: ${i:5}, line: $line') } - line := oline.trim_space() if is_html_open_tag('style', line) { state = .css } else if line == '' { @@ -225,8 +224,8 @@ mut sb := strings.new_builder($lstartlength)\n } else { // HTML, may include `@var` // escaped by cgen, unless it's a `vweb.RawHtml` string - source.writeln(line.replace(r'@', r'$').replace(r'$$', r'@').replace(r'.$', - r'.@').replace(r"'", r"\'")) + source.writeln(line.replace_each([r'@', r'$', r'$$', r'@', r'.$', r'.@', r"'", r"\'", + '\\', parser.tmpl_str_end + 'sb.write_b(92)\n' + parser.tmpl_str_start])) } } source.writeln(parser.tmpl_str_end) diff --git a/vlib/v/tests/inout/file.html b/vlib/v/tests/inout/file.html index e7eb9366ed..91f1dd4e94 100644 --- a/vlib/v/tests/inout/file.html +++ b/vlib/v/tests/inout/file.html @@ -32,6 +32,16 @@ const classes = `header ${ isLargeScreen() ? '' :

@{title}

+
+                                  _
+                                 | |
+    _____  ____ _ _ __ ___  _ __ | | ___
+   / _ \ \/ / _` | '_ ` _ \| '_ \| |/ _ \
+  |  __/>  < (_| | | | | | | |_) | |  __/
+   \___/_/\_\__,_|_| |_| |_| .__/|_|\___|
+                           | |
+                           |_|
+
- \ No newline at end of file + diff --git a/vlib/v/tests/inout/tmpl_parse_html.out b/vlib/v/tests/inout/tmpl_parse_html.out index 132622d0e8..f772cc184e 100644 --- a/vlib/v/tests/inout/tmpl_parse_html.out +++ b/vlib/v/tests/inout/tmpl_parse_html.out @@ -8,8 +8,8 @@ color: green; } @keyframes mymove { -from {top: 0px;} -to {top: 200px;} + from {top: 0px;} + to {top: 200px;} }