tmpl: fix <div> inside <div>

pull/11565/head
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

@ -1,11 +1,19 @@
@include 'header.html'
Test <b>app</b>
<br>
<h1>@hello</h1>
<hr>
If demo: <br>
@if show
show = true
@end
<br><br>
For loop demo: <br>
@for number in numbers
@number <br>
@end

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

View File

@ -0,0 +1,5 @@
<b>embedded</b>
.embedded {
hello
}

View File

@ -35,8 +35,13 @@ const classes = `header ${ isLargeScreen() ? '' :
<h1>@{title}</h1>
<p>@title</p>
.hello {
<b>hi</b><br>
.hello2 {
<b>hi</b><br>
}
}
@include 'embedded.html'
<a href="@website.link">@website.link</a>
<a href="mailto:example@@@website.link">Email</a>
</header>

View File

@ -35,8 +35,17 @@ const classes = `header ${ isLargeScreen() ? '' :
<h1>TEST</h1>
<p>TEST</p>
<div class="hello">
<b>hi</b><br>
<div class="hello2">
<b>hi</b><br>
</div>
</div>
<b>embedded</b>
<div class="embedded">
hello
</div>
<a href="example.com">example.com</a>
<a href="mailto:example@example.com">Email</a>
</header>