aboutsummaryrefslogtreecommitdiff
path: root/examples/wrap/wrap.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-06 22:26:12 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-06 22:26:12 -0400
commit3406515a44b13d0c290c28ac42bd364ce27560c7 (patch)
tree38000658e651ad19b9c8c2590df8fd6bb6faa4d7 /examples/wrap/wrap.tm
parentd8afa73368cdff38125fa1f7d17ad5ce54c84def (diff)
Make string escapes more normal: "\n" for newline, etc. Backticks can be
used to put in literal code without escape sequences.
Diffstat (limited to 'examples/wrap/wrap.tm')
-rw-r--r--examples/wrap/wrap.tm10
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/wrap/wrap.tm b/examples/wrap/wrap.tm
index 1a29701f..bae01739 100644
--- a/examples/wrap/wrap.tm
+++ b/examples/wrap/wrap.tm
@@ -11,15 +11,15 @@ HELP := "
--hyphen='-': The text to use for hyphenation
"
-UNICODE_HYPHEN := \{hyphen}
+UNICODE_HYPHEN := "\{hyphen}"
func unwrap(text:Text, preserve_paragraphs=yes, hyphen=UNICODE_HYPHEN -> Text)
if preserve_paragraphs
paragraphs := text.split($/{2+ nl}/)
if paragraphs.length > 1
- return \n\n.join([unwrap(p, hyphen=hyphen, preserve_paragraphs=no) for p in paragraphs])
+ return "\n\n".join([unwrap(p, hyphen=hyphen, preserve_paragraphs=no) for p in paragraphs])
- return text.replace($/$(hyphen)$(\n)/, "")
+ return text.replace("$(hyphen)\n", "")
func wrap(text:Text, width:Int, min_split=3, hyphen="-" -> Text)
if width <= 0
@@ -69,7 +69,7 @@ func wrap(text:Text, width:Int, min_split=3, hyphen="-" -> Text)
if line != ""
lines.insert(line)
- return \n.join(lines)
+ return "\n".join(lines)
func _can_fit_word(line:Text, letters:[Text], width:Int -> Bool; inline)
if line == ""
@@ -99,4 +99,4 @@ func main(files:[Path], width=80, inplace=no, min_split=3, rewrap=yes, hyphen=UN
wrap(paragraph, width=width, min_split=min_split, hyphen=hyphen)
)
- out.write(\n\n.join(wrapped_paragraphs[]) ++ \n)
+ out.write("\n\n".join(wrapped_paragraphs[]) ++ "\n")