tmpl: enforce stricter line checking for html interpolation (#11413)

pull/11426/head
Dialga 2021-09-07 11:21:23 +12:00 committed by GitHub
parent bd10a63839
commit 905c292a81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 3 deletions

View File

@ -193,16 +193,16 @@ mut sb := strings.new_builder($lstartlength)\n
pos := line.index('@for') or { continue }
source.writeln('for ' + line[pos + 4..] + '{')
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'>`
class := line.find_between('span.', '{').trim_space()
source.writeln('<span class="$class">')
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'>`
class := line.find_between('.', '{').trim_space()
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'>`
class := line.find_between('#', '{').trim_space()
source.writeln('<div id="$class">')

View File

@ -3,6 +3,7 @@
This is the main content:
-------------------------
@content
Name: @{p1.name}
-------------------------
@include './footer.md'

View File

@ -3,6 +3,7 @@ my header
This is the main content:
-------------------------
some string
Name: Peter
-------------------------
my footer

View File

@ -1,4 +1,11 @@
struct Person {
mut:
name string
}
fn abc() string {
mut p1 := Person{}
p1.name = 'Peter'
content := 'some string'
return $tmpl('file.md')
}