github.com/coveo/gotemplate@v2.7.7+incompatible/template/razor_repl_literal.go (about) 1 package template 2 3 import ( 4 "fmt" 5 "strconv" 6 "strings" 7 ) 8 9 func protectMultiLineStrings(repl replacement, match string) string { 10 if strings.HasPrefix(match[1:], protectString) { 11 // We restore back the long string 12 index := must(strconv.Atoi(repl.re.FindStringSubmatch(match)[1])).(int) 13 restore := longStrings[index] 14 longStrings[index] = "" 15 return restore 16 } 17 if !strings.Contains(match, "\n") || strings.Contains(match, "``") { 18 // We do not have to protect lines without newline or non real multiline string 19 return match 20 } 21 // We save the long string in a buffer, they will be restored at the end of razor preprocessing 22 longStrings = append(longStrings, match) 23 return fmt.Sprintf("`%s%d`", protectString, len(longStrings)-1) 24 } 25 26 var longStrings []string 27 28 func protectEmail(repl replacement, match string) string { 29 if match[0] == '@' || match[0] == '#' { 30 // This is not an email 31 return match 32 } 33 return strings.Replace(match, "@", "@@", 1) 34 }