Debian Codegraph @

terps/tads/tads3/test/data/spec2text.t

raw
1 #include <tads.h>
2
3 main(args)
4 {
5 local strs = [
6 'This is a test of the specialsToText() conversion process.',
7 'These first strings have no special characters, but we\'ll get '
8 + 'to that presently.',
9 'We have some \ \ quoted spaces \ \ in this one.',
10 'Mixing \ \ quoted and \ \ \ unquoted spaces.',
11 'This one has some <q>quote <q>markups</q> end quote</q>.',
12 'Let\'s try <q>quote ',
13 '<q>markups</q>',
14 'end quote</q> across elements!',
15 'Some newline conversions: newline\nblank\bthree newlines\n\n\n'
16 + 'three blanks\b\b\bnewline-blank-newline-blank\n\b\n\b',
17 'A tag across lines: <a href="test',
18 '<link>">hyperlinked text here</',
19 'a>',
20 'Caps flag: \^<q>in quotes</q>, nocaps: \v<a href=\'link',
21 '-<across>-lines\'>ALL CAPS</a>',
22 'BR with HEIGHT attributes... first, height=0<br height=0>\n'
23 + 'Now height=1<br height=1>'
24 + 'And height=2<br height=2>'
25 + 'And now a height=0 at the start of a line\n<br height=0>'
26 + 'And height=2 at start of line\n<br height=2>',
27 'Tabs:\none\ttwo\tthree\tfour\tfive\tsix\n'
28 + '\ta\tb\tc\td\n'
29 + 'hello\tgoodbye\tthat should be all',
30 'Some entity markups: &quot;Quotes&quot;, &ldquo;Curly '
31 + 'Quotes&rdquo;, &lsquo;Single Curlies&rsquo;, &lt;angle '
32 + 'brackets&gt; &amp; and such, nb&nbsp;spaces.'
33 ];
34
35 local st = new TadsObject();
36 foreach (local str in strs)
37 {
38 "Src:\ \ <<quoteAll(str)>><br>
39 Disp: <<str.htmlify()>><br>
40 s2t:\ \ <<quoteAll(str.specialsToText(st))>><br><br>";
41 }
42 }
43
44 quoteAll(str)
45 {
46 return str.htmlify().findReplace(
47 ['\n', '\b', '\t', ' ', '\ ', '\v', '\^'],
48 ['\\n', '\\b', '\\t', '\ ', '\\\ ', '\\v', '\\^']);
49 }