tmpl: enforce stricter line checking for html interpolation (#11413)
parent
bd10a63839
commit
905c292a81
|
@ -193,16 +193,16 @@ mut sb := strings.new_builder($lstartlength)\n
|
||||||
pos := line.index('@for') or { continue }
|
pos := line.index('@for') or { continue }
|
||||||
source.writeln('for ' + line[pos + 4..] + '{')
|
source.writeln('for ' + line[pos + 4..] + '{')
|
||||||
source.writeln(parser.tmpl_str_start)
|
source.writeln(parser.tmpl_str_start)
|
||||||
} else if state == .html && line.contains('span.') && line.ends_with('{') {
|
} else if state == .html && line.starts_with('span.') && line.ends_with('{') {
|
||||||
// `span.header {` => `<span class='header'>`
|
// `span.header {` => `<span class='header'>`
|
||||||
class := line.find_between('span.', '{').trim_space()
|
class := line.find_between('span.', '{').trim_space()
|
||||||
source.writeln('<span class="$class">')
|
source.writeln('<span class="$class">')
|
||||||
in_span = true
|
in_span = true
|
||||||
} else if state == .html && line.contains('.') && line.ends_with('{') {
|
} else if state == .html && line.starts_with('.') && line.ends_with('{') {
|
||||||
// `.header {` => `<div class='header'>`
|
// `.header {` => `<div class='header'>`
|
||||||
class := line.find_between('.', '{').trim_space()
|
class := line.find_between('.', '{').trim_space()
|
||||||
source.writeln('<div class="$class">')
|
source.writeln('<div class="$class">')
|
||||||
} else if state == .html && line.contains('#') && line.ends_with('{') {
|
} else if state == .html && line.starts_with('#') && line.ends_with('{') {
|
||||||
// `#header {` => `<div id='header'>`
|
// `#header {` => `<div id='header'>`
|
||||||
class := line.find_between('#', '{').trim_space()
|
class := line.find_between('#', '{').trim_space()
|
||||||
source.writeln('<div id="$class">')
|
source.writeln('<div id="$class">')
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
This is the main content:
|
This is the main content:
|
||||||
-------------------------
|
-------------------------
|
||||||
@content
|
@content
|
||||||
|
Name: @{p1.name}
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
@include './footer.md'
|
@include './footer.md'
|
||||||
|
|
|
@ -3,6 +3,7 @@ my header
|
||||||
This is the main content:
|
This is the main content:
|
||||||
-------------------------
|
-------------------------
|
||||||
some string
|
some string
|
||||||
|
Name: Peter
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
my footer
|
my footer
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
|
struct Person {
|
||||||
|
mut:
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
fn abc() string {
|
fn abc() string {
|
||||||
|
mut p1 := Person{}
|
||||||
|
p1.name = 'Peter'
|
||||||
content := 'some string'
|
content := 'some string'
|
||||||
return $tmpl('file.md')
|
return $tmpl('file.md')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue