Merge pull request #532 from wwsheng009/sui-add-raw-instruction

Sui page add s:raw command
This commit is contained in:
Max 2023-12-18 22:01:56 +08:00 committed by GitHub
commit 0ac09f0eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -176,6 +176,18 @@ func (parser *TemplateParser) parseElementAttrs(sel *goquery.Selection) {
}
}
// Check if the element attributes have the s:raw command.
// If true, the sub-node will output the raw data instead of the escaped value.
func checkIsRawElement(node *html.Node) bool {
if node.Parent != nil && len(node.Parent.Attr) > 0 {
for _, attr := range node.Parent.Attr {
if attr.Key == "s:raw" && attr.Val == "true" {
return true
}
}
}
return false
}
func (parser *TemplateParser) parseTextNode(node *html.Node) {
parser.sequence = parser.sequence + 1
res, hasStmt := parser.data.Replace(node.Data)
@ -184,6 +196,9 @@ func (parser *TemplateParser) parseTextNode(node *html.Node) {
bindings := strings.TrimSpace(node.Data)
key := fmt.Sprintf("%v", parser.sequence)
if bindings != "" {
if checkIsRawElement(node) {
node.Type = html.RawNode
}
node.Parent.Attr = append(node.Parent.Attr, []html.Attribute{
{Key: "s:bind", Val: bindings},
{Key: "s:key-text", Val: key},