stmt/html: switch to backtick-delimited string for large multiline cases
This commit is contained in:
parent
68b554a6ec
commit
cdeea4c09c
@ -4,11 +4,16 @@ $header = "bar";
|
|||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
<h1><?=$header?></h1>
|
<h1><?=$header?></h1>
|
||||||
<ul>
|
<ul>
|
||||||
<?php for($i = 0; $i < 3; ++$i) { ?>
|
<?php for($i = 0; $i < 3; ++$i) { ?>
|
||||||
<li><?=$i?></li>
|
<li><?=$i?></li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
14
node.go
14
node.go
@ -379,9 +379,17 @@ func convert(n_ node.Node) (string, error) {
|
|||||||
|
|
||||||
case *stmt.InlineHtml:
|
case *stmt.InlineHtml:
|
||||||
// Convert into fmt.Print
|
// Convert into fmt.Print
|
||||||
// TODO the result from strconv.Quote is not that nice to maintain if there are multiple newlines
|
|
||||||
// Should convert it into a backtick-delimeted multiline string instead
|
var quoted string
|
||||||
return "fmt.Print(" + strconv.Quote(n.Value) + ")\n", nil // newline - standalone statement
|
if !strings.Contains(n.Value, "`") && strings.Count(n.Value, "\n") >= 3 { // TODO make the heuristic configurable
|
||||||
|
// Use backtick-delimited multiline string
|
||||||
|
quoted = "`" + n.Value + "`"
|
||||||
|
} else {
|
||||||
|
// Can't trivially represent it with backticks, or it's not multiline "enough" to bother - use full Go quoting
|
||||||
|
quoted = strconv.Quote(n.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return "fmt.Print(" + quoted + ")\n", nil // newline - standalone statement
|
||||||
|
|
||||||
case *stmt.Nop:
|
case *stmt.Nop:
|
||||||
return "", nil
|
return "", nil
|
||||||
|
Loading…
Reference in New Issue
Block a user