1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tmpl: fix <div> inside <div>

This commit is contained in:
Alexander Medvednikov
2021-09-21 07:53:42 +03:00
parent b2ecca3966
commit f6bdc6b87e
5 changed files with 35 additions and 4 deletions

View File

@@ -198,15 +198,19 @@ mut sb := strings.new_builder($lstartlength)\n
class := line.find_between('span.', '{').trim_space()
source.writeln('<span class="$class">')
in_span = true
} else if state == .html && line.starts_with('.') && line.ends_with('{') {
} else if state == .html && line.trim_space().starts_with('.') && line.ends_with('{') {
// `.header {` => `<div class='header'>`
class := line.find_between('.', '{').trim_space()
trimmed := line.trim_space()
source.write_string(strings.repeat(`\t`, line.len - trimmed.len)) // add the necessary indent to keep <div><div><div> code clean
source.writeln('<div class="$class">')
} else if state == .html && line.starts_with('#') && line.ends_with('{') {
// `#header {` => `<div id='header'>`
class := line.find_between('#', '{').trim_space()
source.writeln('<div id="$class">')
} else if state == .html && line == '}' {
} else if state == .html && line.trim_space() == '}' {
trimmed := line.trim_space()
source.write_string(strings.repeat(`\t`, line.len - trimmed.len)) // add the necessary indent to keep <div><div><div> code clean
if in_span {
source.writeln('</span>')
in_span = false