Debian Codegraph @

example_test.go

raw symbols SCIP
1 package syntaxhighlight_test
2
3 import (
4 "fmt"
5 "os"
6
7 "github.com/sourcegraph/syntaxhighlight"
8 )
9
10 func Example() {
11 src := []byte(`
12 /* hello, world! */
13 var a = 3;
14
15 // b is a cool function
16 function b() {
17 return 7;
18 }`)
19
20 highlighted, err := syntaxhighlight.AsHTML(src)
21 if err != nil {
22 fmt.Println(err)
23 os.Exit(1)
24 }
25
26 fmt.Println(string(highlighted))
27
28 // Output:
29 // <span class="com">/* hello, world! */</span>
30 // <span class="kwd">var</span> <span class="pln">a</span> <span class="pun">=</span> <span class="dec">3</span><span class="pun">;</span>
31 //
32 // <span class="com">// b is a cool function</span>
33 // <span class="kwd">function</span> <span class="pln">b</span><span class="pun">(</span><span class="pun">)</span> <span class="pun">{</span>
34 // <span class="kwd">return</span> <span class="dec">7</span><span class="pun">;</span>
35 // <span class="pun">}</span>
36 }