Debian Codegraph @

tests/testit/test-hilight.md

raw symbols SCIP
1 # hi_latex() works without prompts
2
3 ```{r}
4 hi_latex('1+1')
5 hi_latex(' 1 + 1')
6 hi_latex(c(' if (TRUE ){', 'foo && bar}'))
7 ```
8 ```
9 \hlnum{1}\hlopt{+}\hlnum{1}
10 \hlnum{1} \hlopt{+} \hlnum{1}
11 \hlkwa{if} \hldef{(}\hlnum{TRUE} \hldef{)\{}
12 \hldef{foo} \hlopt{&&} \hldef{bar\}}
13 ```
14
15 # hi_latex() works with prompts
16
17 ```{r}
18 hi_latex('1+1', prompt = TRUE)
19 hi_latex(c(' if (TRUE ){', 'foo && bar}'), prompt = TRUE)
20 ```
21 ```
22 \hldef{> }\hlnum{1}\hlopt{+}\hlnum{1}
23 \hldef{> } \hlkwa{if} \hldef{(}\hlnum{TRUE} \hldef{)\{}
24 \hldef{+ }\hldef{foo} \hlopt{&&} \hldef{bar\}}
25 ```
26
27 # hi_latex() preserves blank lines
28
29 ```{r}
30 hi_latex(c('1+1', '', 'foo(x=3) # comm'))
31 ```
32 ```
33 \hlnum{1}\hlopt{+}\hlnum{1}
34
35 \hlkwd{foo}\hldef{(}\hlkwc{x}\hldef{=}\hlnum{3}\hldef{)} \hlcom{# comm}
36 ```
37
38 # the fallback method recognizes comments, functions and strings
39
40 ```{r}
41 hi_latex('1+1 # a comment', fallback = TRUE)
42 hi_latex('paste("STRING", \'string\')', fallback = TRUE)
43 ```
44 ```
45 1+1 \hlcom{# a comment}
46 \hlkwd{paste}(\hlsng{"STRING"}, \hlsng{'string'})
47 ```
48
49 # the fallback mode is used when the code does not parse
50
51 ```{r}
52 has_warning(res <- hi_latex('1+1+ # comment'))
53 res
54 ```
55 ```
56 [1] TRUE
57 1+1+ \hlcom{# comment}
58 ```
59
60 # hilight() works even if code only contains comments
61
62 ```{r}
63 hi_latex('# only comments')
64 ```
65 ```
66 \hlcom{# only comments}
67 ```
68
69 # the right arrow -> is preserved
70
71 ```{r}
72 hi_latex('1 ->x # foo')
73 ```
74 ```
75 \hlnum{1} \hlkwb{->}\hldef{x} \hlcom{# foo}
76 ```
77
78 # blank lines before/after code are preserved
79
80 ```{r}
81 hi_latex(c('', '', '1'))
82 hi_latex(c('', '', '1', ''))
83 ```
84 ```
85
86
87 \hlnum{1}
88
89
90 \hlnum{1}
91
92 ```
93
94 # custom markup also works
95
96 ```{r}
97 hi_html('1+ 1')
98 my_cmd = cmd_html
99 my_cmd['NUM_CONST', 1] = '<span class="my num">'
100 hi_html('1+ 1', markup = my_cmd)
101 rm(my_cmd)
102 ```
103 ```
104 <span class="hl num">1</span><span class="hl opt">+</span> <span class="hl num">1</span>
105 <span class="my num">1</span><span class="hl opt">+</span> <span class="my num">1</span>
106 ```