Debian Codegraph @

extras/AsciiDoc/example.asciidoc

raw
1 = Original HighlightTreeprocessor Example
2 Tristano Ajmone <[email protected]>
3 v1, 2019-03-25
4 :toclevels: 5
5 :toc: left
6 :experimental: true
7 :icons: font
8 :linkattrs: true
9 :reproducible: true
10 :sectanchors:
11 // ===================
12 // Highlight Settings:
13 // ===================
14 :source-highlighter: highlight
15 :highlight-style: kellys
16
17 A demonstration of the original *HighlightTreeprocessor* extension published on the
18 link:https://github.com/asciidoctor/asciidoctor-extensions-lab[Asciidoctor Extensions Lab]
19 project.
20
21
22 == Highlighting Previews
23
24 A couple of examples of how the rendered code looks like.
25
26 Associated files:
27
28 * link:./highlight-treeprocessor.rb[`highlight-treeprocessor.rb`]
29
30
31
32 === Example 1
33
34
35 [source,purebasic]
36 ------------------
37 include::../langs-examples/ex-src/PureBasic.pb[]
38 ------------------
39
40 === Example 2: Line Numbers
41
42 Now we add the `linenum` option to enable line-numbering:
43
44 [source,alan,linenum]
45 ------------------
46 include::../langs-examples/ex-src/alan.alan[]
47 ------------------
48
49
50
51
52 == Usage Instructions
53
54
55 To enable the *HighlightTreeprocessor* extension you must invoke Asciidoctor with the `-r` (`--require`) option:
56
57 [source,bash]
58 ------------------------------------------------------------------
59 asciidoctor -r ./highlight-treeprocessor.rb your_document.asciidoc
60 ------------------------------------------------------------------
61
62 To enable using Highlight, you need to set the `source-highlighter` attribute to `highlight`.
63 You may do so via the command line, using the `-a` (`--attribute`) option:
64
65 [source,bash]
66 -----------------------------------
67 asciidoctor \
68 -r ./highlight-treeprocessor.rb \
69 -a source-highlighter=highlight \
70 your_document.asciidoc
71 -----------------------------------
72
73 or you can declare the attribute inside the document header:
74
75 ..............................
76 :source-highlighter: highlight
77 ..............................
78
79
80 === Highlight Options
81
82
83
84 ==== Theme and Style
85
86 The original extension exposes two attributes to set the Highlight theme and to control the CSS styling format:
87
88 [cols="4*<d",options="header"]
89 |==========
90 | attribute name
91 | allowed values
92 | default value
93 | Highlight option
94
95 | `highlight-style`
96 | any theme name
97 | `edit-eclipse`
98 | `--style=<value>`
99
100 | `highlight-css`
101 | `class`/`style`
102 | `class`
103 | _none_/`--inline-css`
104 |==========
105
106 The `highlight-style` attribute allows you to choose any Highlight theme by setting its value to the theme's filename (without the extension).
107 The selected theme must be inside Highlight `/themes/` folder.
108
109 NOTE: The *HighlightTreeprocessor* extension only allows you to pick a single theme per document.
110
111 By default, Asciidoctor will set `highlight-css` to `class`, so that Highlight will use class names to style the various syntax elements (which is also Highlight default behavior):
112
113 [source,html]
114 --------------------------------------------------------------------------------
115 <span class="hl kwa">require</span>
116 --------------------------------------------------------------------------------
117
118 whereas setting `highlight-css` to `style` will inline the CSS definitions into the tags, instead of using classes (i.e. Highlight is invoked with the `--inline-css` option):
119
120 [source,html]
121 --------------------------------------------------------------------------------
122 <span style="color:#62acce; font-weight:bold">require</span>
123 --------------------------------------------------------------------------------
124
125 Obviously, the latter solution is more verbose, so you're better off not setting the `highlight-css` attribute at all, and just stick to the extension default value (`class`).
126
127
128 WARNING: The `style` option fails to style the background color (i.e. Highlight `canvas`), probably due to the extension being very old and Highlight having changed tag/classes in the HTML output.
129
130 When `highlight-css` is set to `class`, the extension will get the CSS stylesheet of the `highlight-style` theme by invoking Highlight with the `-c stdout --print-style -s` option, and injects it at the end of the output HTML document:
131
132 .HTML Example
133 [source,css]
134 --------------------------------------------------------------------------------
135 <style>
136 /* Style definition file generated by highlight 3.49, http://www.andre-simon.de/ */
137 /* highlight theme: vim kellys */
138 body.hl { background-color:#2a2b2f; }
139 .listingblock pre.highlight { background-color:#2a2b2f; }
140 pre.highlight>code { color: #e1e0e5; }
141 .hl.num { color:#dabc7f; }
142 .hl.esc { color:#9ab2c8; }
143 .hl.str { color:#dabc7f; }
144 .hl.pps { color:#dabc7f; }
145 .hl.slc { color:#67686b; }
146 .hl.com { color:#67686b; }
147 .hl.ppc { color:#77cf63; }
148 .hl.opt { color:#e1e0e5; }
149 .hl.ipl { color:#c75e75; }
150 .hl.lin { color:#a3a362; }
151 .hl.kwa { color:#62acce; font-weight:bold; }
152 .hl.kwb { color:#e6ac32; }
153 .hl.kwc { color:#cf8563; }
154 .hl.kwd { color:#bb63cf; }
155 </style>
156 </body>
157 </html>
158 --------------------------------------------------------------------------------
159
160
161
162 ==== Line Numbering
163
164 Furthermore, you can enable line-numbering via the `linenums` option to the source block style of a listing block:
165
166 .AsciiDoc Example
167 .....................
168 [source,ruby,linenum]
169 ---------------------
170 require 'sinatra'
171
172 get '/hi' do
173 "Hello World!"
174 end
175 ---------------------
176 .....................
177
178
179 .Result Preview
180
181 [source,ruby,linenum]
182 ---------------------
183 require 'sinatra'
184
185 get '/hi' do
186 "Hello World!"
187 end
188 ---------------------
189
190 When `linenums` is used, Highlight is invoked with the `-l -j 2` options.
191
192
193
194 // EOF //