1
+ import test from 'ava' ;
2
+ import { Liquid } from 'liquidjs' ;
3
+ import { liquidHighlight } from './highlight.js' ;
4
+
5
+ test ( "should escape HTML" , async t => {
6
+ const liquid = new Liquid ( { } ) ;
7
+ liquid . plugin ( liquidHighlight ) ;
8
+
9
+ const result = await liquid . parseAndRender ( `
10
+ {%- highlight -%}
11
+ <h1>Hello World</h1>
12
+ {%- endhighlight -%}
13
+ ` ) ;
14
+ t . notRegex ( result , / < h 1 > H e l l o W o r l d < \/ h 1 > / ) ;
15
+ t . regex ( result , / & l t ; h 1 & g t ; / ) ;
16
+ } ) ;
17
+
18
+ test ( "should evaluate inner liquid" , async t => {
19
+ const liquid = new Liquid ( { } ) ;
20
+ liquid . plugin ( liquidHighlight ) ;
21
+
22
+ const result = await liquid . parseAndRender ( `
23
+ {%- highlight -%}
24
+ <h1>Hello {{ test }}</h1>
25
+ {%- endhighlight -%}
26
+ ` , { test : "Bookshop" } ) ;
27
+ t . regex ( result , / & l t ; h 1 & g t ; H e l l o B o o k s h o p & l t ; \/ h 1 & g t ; / ) ;
28
+ } ) ;
29
+
30
+ test ( "should respect raw tags" , async t => {
31
+ const liquid = new Liquid ( { } ) ;
32
+ liquid . plugin ( liquidHighlight ) ;
33
+
34
+ const result = await liquid . parseAndRender ( `
35
+ {%- highlight -%}
36
+ {% raw %}<h1>Hello {{ test }}</h1>{% endraw %}
37
+ {%- endhighlight -%}
38
+ ` , { test : "Bookshop" } ) ;
39
+ t . regex ( result , / & l t ; h 1 & g t ; H e l l o { { t e s t } } & l t ; \/ h 1 & g t ; / ) ;
40
+ } ) ;
41
+
42
+ test ( "should handle no language" , async t => {
43
+ const liquid = new Liquid ( { } ) ;
44
+ liquid . plugin ( liquidHighlight ) ;
45
+
46
+ const result = await liquid . parseAndRender ( `{% highlight %}{% endhighlight %}` ) ;
47
+ t . regex ( result , / < c o d e > / ) ;
48
+ } ) ;
49
+
50
+ test ( "should handle language" , async t => {
51
+ const liquid = new Liquid ( { } ) ;
52
+ liquid . plugin ( liquidHighlight ) ;
53
+
54
+ const result = await liquid . parseAndRender ( `{% highlight ruby %}{% endhighlight %}` ) ;
55
+ t . regex ( result , / < c o d e c l a s s = " l a n g u a g e - r u b y " d a t a - l a n g = " r u b y " > / ) ;
56
+ } ) ;
0 commit comments