tmpl: don't trim whitespace and escape \ (#11393)
parent
2cfc6e007d
commit
87f38bf6e7
|
@ -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 == '</style>' {
|
||||
|
@ -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)
|
||||
|
|
|
@ -32,6 +32,16 @@ const classes = `header ${ isLargeScreen() ? '' :
|
|||
<header>
|
||||
<h1>@{title}</h1>
|
||||
</header>
|
||||
<pre>
|
||||
_
|
||||
| |
|
||||
_____ ____ _ _ __ ___ _ __ | | ___
|
||||
/ _ \ \/ / _` | '_ ` _ \| '_ \| |/ _ \
|
||||
| __/> < (_| | | | | | | |_) | | __/
|
||||
\___/_/\_\__,_|_| |_| |_| .__/|_|\___|
|
||||
| |
|
||||
|_|
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -8,8 +8,8 @@ color: green;
|
|||
}
|
||||
|
||||
@keyframes mymove {
|
||||
from {top: 0px;}
|
||||
to {top: 200px;}
|
||||
from {top: 0px;}
|
||||
to {top: 200px;}
|
||||
}
|
||||
</style>
|
||||
<style media="print">
|
||||
|
@ -32,6 +32,16 @@ const classes = `header ${ isLargeScreen() ? '' :
|
|||
<header>
|
||||
<h1>TEST</h1>
|
||||
</header>
|
||||
<pre>
|
||||
_
|
||||
| |
|
||||
_____ ____ _ _ __ ___ _ __ | | ___
|
||||
/ _ \ \/ / _` | '_ ` _ \| '_ \| |/ _ \
|
||||
| __/> < (_| | | | | | | |_) | | __/
|
||||
\___/_/\_\__,_|_| |_| |_| .__/|_|\___|
|
||||
| |
|
||||
|_|
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue