codnar 0.1.68 → 0.1.73
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +17 -0
- data/codnar.html +1368 -527
- data/doc/system.markdown +56 -15
- data/lib/codnar.rb +6 -0
- data/lib/codnar/configuration/code.rb +87 -0
- data/lib/codnar/configuration/comments.rb +234 -0
- data/lib/codnar/configuration/documentation.rb +65 -0
- data/lib/codnar/configuration/highlighting.rb +107 -0
- data/lib/codnar/data/contents.js +2 -1
- data/lib/codnar/haddock.rb +72 -0
- data/lib/codnar/rake/split_task.rb +6 -0
- data/lib/codnar/scanner.rb +34 -11
- data/lib/codnar/split_configurations.rb +4 -382
- data/lib/codnar/string_extensions.rb +4 -3
- data/lib/codnar/version.rb +1 -1
- data/test/expand_haddock.rb +23 -0
- data/test/expand_rdoc.rb +2 -2
- data/test/format_comment_configurations.rb +1 -1
- data/test/run_weave.rb +2 -3
- data/test/split_code.rb +1 -1
- data/test/split_combined_configurations.rb +1 -1
- data/test/{split_complex_comment_configurations.rb → split_delimited_comment_configurations.rb} +11 -11
- data/test/split_denoted_comment_configurations.rb +62 -0
- data/test/split_documentation.rb +1 -1
- data/test/split_documentation_configurations.rb +1 -1
- metadata +16 -7
data/ChangeLog
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
2012-03-18 Oren Ben-Kiki <github-oren@ben-kiki.org>
|
2
|
+
|
3
|
+
* Fix JS comment.
|
4
|
+
* Fix JS issue; remove unneeded files.
|
5
|
+
|
6
|
+
2012-01-07 Oren Ben-Kiki <github-oren@ben-kiki.org>
|
7
|
+
|
8
|
+
* Add support for Haddock comments.
|
9
|
+
|
10
|
+
2012-01-04 Oren Ben-Kiki <github-oren@ben-kiki.org>
|
11
|
+
|
12
|
+
* Support additional ("denoted") kind of comments.
|
13
|
+
|
14
|
+
2011-09-23 Oren Ben-Kiki <github-oren@ben-kiki.org>
|
15
|
+
|
16
|
+
* Add support for CodeRay syntax highlighting.
|
17
|
+
|
1
18
|
2011-09-13 Oren Ben-Kiki <github-oren@ben-kiki.org>
|
2
19
|
|
3
20
|
* Add support for GraphViz documentation.
|
data/codnar.html
CHANGED
@@ -678,14 +678,14 @@ This module contains all the code narrator code.
|
|
678
678
|
<div class='rdoc comment markup'>
|
679
679
|
<p>
|
680
680
|
This version number. The third number is automatically updated to track the
|
681
|
-
number of Git commits by running <
|
681
|
+
number of Git commits by running <code>rake version</code>.
|
682
682
|
</p>
|
683
683
|
</div>
|
684
684
|
</td>
|
685
685
|
</tr>
|
686
686
|
</table>
|
687
687
|
<pre class='ruby code syntax'>
|
688
|
-
<span class="Type">VERSION</span> = <span class="Special">"</span><span class="Constant">0.1.
|
688
|
+
<span class="Type">VERSION</span> = <span class="Special">"</span><span class="Constant">0.1.73</span><span class="Special">"</span>
|
689
689
|
|
690
690
|
end
|
691
691
|
</pre>
|
@@ -1018,7 +1018,9 @@ equal to [ “indentation”, “payload” ].
|
|
1018
1018
|
</li><li>
|
1019
1019
|
<p>
|
1020
1020
|
The kind field of a transition can be ommitted; by default it is assumed to
|
1021
|
-
be identical to the pattern kind.
|
1021
|
+
be identical to the pattern kind. If it ends up <tt>nil</tt>, this
|
1022
|
+
indicates that there’s no kind assigned by the pattern, and the current
|
1023
|
+
line should be classified again by the next state.
|
1022
1024
|
</p>
|
1023
1025
|
</li><li>
|
1024
1026
|
<p>
|
@@ -1250,6 +1252,31 @@ Fill in the name field for state or pattern object.
|
|
1250
1252
|
<div class="chunk html">
|
1251
1253
|
<pre class='ruby code syntax'>
|
1252
1254
|
|
1255
|
+
</pre>
|
1256
|
+
<table class='layout'>
|
1257
|
+
<tr>
|
1258
|
+
<td class='indentation'>
|
1259
|
+
<pre></pre>
|
1260
|
+
</td>
|
1261
|
+
<td class='html'>
|
1262
|
+
<div class='rdoc comment markup'>
|
1263
|
+
<p>
|
1264
|
+
A pattern that matches any line and extracts no data; is meant to be used
|
1265
|
+
for catch-all transitions that transfer the scanning to a different state.
|
1266
|
+
It is used if no explicit pattern is specified in a transition (that is,
|
1267
|
+
you can think of this as the <tt>nil</tt> pattern).
|
1268
|
+
</p>
|
1269
|
+
</div>
|
1270
|
+
</td>
|
1271
|
+
</tr>
|
1272
|
+
</table>
|
1273
|
+
<pre class='ruby code syntax'>
|
1274
|
+
<span class="Type">CATCH_ALL_PATTERN</span> = {
|
1275
|
+
<span class="Special">"</span><span class="Constant">kind</span><span class="Special">"</span> => <span class="Constant">nil</span>,
|
1276
|
+
<span class="Special">"</span><span class="Constant">groups</span><span class="Special">"</span> => [],
|
1277
|
+
<span class="Special">"</span><span class="Constant">regexp</span><span class="Special">"</span> => <span class="Special">//</span>
|
1278
|
+
}
|
1279
|
+
|
1253
1280
|
</pre>
|
1254
1281
|
<table class='layout'>
|
1255
1282
|
<tr>
|
@@ -1269,7 +1296,7 @@ Expand all the shorthands used in the state.
|
|
1269
1296
|
<span class="PreProc">def</span> <span class="Identifier">expand_state_shorthands</span>(name, state)
|
1270
1297
|
fill_name(name, state, <span class="Special">"</span><span class="Constant">State</span><span class="Special">"</span>)
|
1271
1298
|
state.transitions.each <span class="Statement">do</span> |<span class="Identifier">transition</span>|
|
1272
|
-
pattern = transition.pattern = lookup(<span class="Identifier">@syntax</span>.patterns, <span class="Special">"</span><span class="Constant">pattern</span><span class="Special">"</span>, transition.pattern)
|
1299
|
+
pattern = transition.pattern = lookup(<span class="Identifier">@syntax</span>.patterns, <span class="Special">"</span><span class="Constant">pattern</span><span class="Special">"</span>, transition.pattern || <span class="Type">CATCH_ALL_PATTERN</span>)
|
1273
1300
|
transition.kind ||= pattern.andand.kind
|
1274
1301
|
transition.next_state = lookup(<span class="Identifier">@syntax</span>.states, <span class="Special">"</span><span class="Constant">state</span><span class="Special">"</span>, transition.next_state || state)
|
1275
1302
|
<span class="Statement">end</span>
|
@@ -1428,10 +1455,51 @@ Scan the next file line.
|
|
1428
1455
|
</table>
|
1429
1456
|
<pre class='ruby code syntax'>
|
1430
1457
|
<span class="PreProc">def</span> <span class="Identifier">scan_line</span>(line)
|
1458
|
+
<span class="Statement">until</span> state_classified_line(line)
|
1459
|
+
</pre>
|
1460
|
+
<table class='layout'>
|
1461
|
+
<tr>
|
1462
|
+
<td class='indentation'>
|
1463
|
+
<pre> </pre>
|
1464
|
+
</td>
|
1465
|
+
<td class='html'>
|
1466
|
+
<div class='rdoc comment markup'>
|
1467
|
+
<p>
|
1468
|
+
Do nothing
|
1469
|
+
</p>
|
1470
|
+
</div>
|
1471
|
+
</td>
|
1472
|
+
</tr>
|
1473
|
+
</table>
|
1474
|
+
<pre class='ruby code syntax'>
|
1475
|
+
end
|
1476
|
+
end
|
1477
|
+
|
1478
|
+
</pre>
|
1479
|
+
<table class='layout'>
|
1480
|
+
<tr>
|
1481
|
+
<td class='indentation'>
|
1482
|
+
<pre></pre>
|
1483
|
+
</td>
|
1484
|
+
<td class='html'>
|
1485
|
+
<div class='rdoc comment markup'>
|
1486
|
+
<p>
|
1487
|
+
Scan the current line using the current state transitions. Return true if
|
1488
|
+
the line was classified, of false if we need to try and classify it again
|
1489
|
+
using the updated (next) state.
|
1490
|
+
</p>
|
1491
|
+
</div>
|
1492
|
+
</td>
|
1493
|
+
</tr>
|
1494
|
+
</table>
|
1495
|
+
<pre class='ruby code syntax'>
|
1496
|
+
<span class="PreProc">def</span> <span class="Identifier">state_classified_line</span>(line)
|
1431
1497
|
<span class="Identifier">@state</span>.transitions.each <span class="Statement">do</span> |<span class="Identifier">transition</span>|
|
1432
|
-
|
1498
|
+
match = transition.pattern.andand.regexp.andand.match(line) <span class="Statement">if</span> transition.next_state
|
1499
|
+
<span class="Statement">return</span> classify_matching_line(line, transition, match) <span class="Statement">if</span> match
|
1433
1500
|
<span class="Statement">end</span>
|
1434
|
-
|
1501
|
+
classify_error_line(line, <span class="Identifier">@state</span>.name)
|
1502
|
+
<span class="Statement">return</span> <span class="Constant">true</span>
|
1435
1503
|
<span class="PreProc">end</span>
|
1436
1504
|
|
1437
1505
|
</pre>
|
@@ -1476,15 +1544,15 @@ Handle a file line, only if it matches the pattern.
|
|
1476
1544
|
</tr>
|
1477
1545
|
</table>
|
1478
1546
|
<pre class='ruby code syntax'>
|
1479
|
-
<span class="PreProc">def</span> <span class="Identifier">classify_matching_line</span>(line, transition)
|
1480
|
-
|
1481
|
-
|
1482
|
-
<span class="
|
1547
|
+
<span class="PreProc">def</span> <span class="Identifier">classify_matching_line</span>(line, transition, match)
|
1548
|
+
<span class="Identifier">@state</span> = transition.next_state
|
1549
|
+
kind = transition.kind
|
1550
|
+
<span class="Statement">return</span> <span class="Constant">false</span> <span class="Statement">unless</span> kind <span class="Comment"># A +nil+ kind indicates the next state will classify the line.</span>
|
1551
|
+
<span class="Identifier">@lines</span> << <span class="Type">Scanner</span>.extracted_groups(match, transition.pattern.groups || []).update({
|
1483
1552
|
<span class="Special">"</span><span class="Constant">line</span><span class="Special">"</span> => line,
|
1484
|
-
<span class="Special">"</span><span class="Constant">kind</span><span class="Special">"</span> =>
|
1553
|
+
<span class="Special">"</span><span class="Constant">kind</span><span class="Special">"</span> => kind,
|
1485
1554
|
<span class="Special">"</span><span class="Constant">number</span><span class="Special">"</span> => <span class="Identifier">@errors</span>.line_number
|
1486
1555
|
})
|
1487
|
-
<span class="Identifier">@state</span> = transition.next_state
|
1488
1556
|
<span class="Statement">return</span> <span class="Constant">true</span>
|
1489
1557
|
<span class="PreProc">end</span>
|
1490
1558
|
|
@@ -1530,7 +1598,7 @@ Handle a file line that couldn’t be classified.
|
|
1530
1598
|
</tr>
|
1531
1599
|
</table>
|
1532
1600
|
<pre class='ruby code syntax'>
|
1533
|
-
<span class="PreProc">def</span> <span class="Identifier">
|
1601
|
+
<span class="PreProc">def</span> <span class="Identifier">classify_error_line</span>(line, state_name)
|
1534
1602
|
<span class="Identifier">@lines</span> << {
|
1535
1603
|
<span class="Special">"</span><span class="Constant">line</span><span class="Special">"</span> => line,
|
1536
1604
|
<span class="Special">"</span><span class="Constant">indentation</span><span class="Special">"</span> => line.indentation,
|
@@ -2941,12 +3009,12 @@ Test expanding RDoc text.
|
|
2941
3009
|
<span class="PreProc">end</span>
|
2942
3010
|
|
2943
3011
|
<span class="PreProc">def</span> <span class="Identifier">test_strong_text</span>
|
2944
|
-
<span class="Type">Codnar</span>::<span class="Type">RDoc</span>.to_html(<span class="Special">"</span><span class="Constant">*text*</span><span class="Special">"</span>).should == <span class="Special">"</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Constant"><
|
3012
|
+
<span class="Type">Codnar</span>::<span class="Type">RDoc</span>.to_html(<span class="Special">"</span><span class="Constant">*text*</span><span class="Special">"</span>).should == <span class="Special">"</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Constant"><strong>text</strong></span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Special">"</span>
|
2945
3013
|
<span class="PreProc">end</span>
|
2946
3014
|
|
2947
3015
|
<span class="PreProc">def</span> <span class="Identifier">test_indented_pre</span>
|
2948
3016
|
<span class="Type">Codnar</span>::<span class="Type">RDoc</span>.to_html(<span class="Special">"</span><span class="Constant">base</span><span class="Special">\n</span><span class="Constant"> indented</span><span class="Special">\n</span><span class="Constant"> more</span><span class="Special">\n</span><span class="Constant">back</span><span class="Special">\n</span><span class="Special">"</span>).should \
|
2949
|
-
== <span class="Special">"</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Constant">base</span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Constant"><pre>
|
3017
|
+
== <span class="Special">"</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Constant">base</span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Constant"><pre>indented</span><span class="Special">\n</span><span class="Constant"> more</pre></span><span class="Special">\n</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Constant">back</span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Special">"</span>
|
2950
3018
|
<span class="PreProc">end</span>
|
2951
3019
|
|
2952
3020
|
<span class="PreProc">end</span>
|
@@ -3229,20 +3297,22 @@ end
|
|
3229
3297
|
</div>
|
3230
3298
|
</p>
|
3231
3299
|
</li>
|
3232
|
-
|
3300
|
+
<li>
|
3233
3301
|
<p>
|
3234
|
-
|
3235
|
-
|
3302
|
+
Haddock, a specific markup syntax used in comments to document Haskell code.
|
3303
|
+
Here is a simple test that demonstrates using Haddock:
|
3236
3304
|
</p>
|
3237
3305
|
<p>
|
3238
3306
|
<div class="named_with_containers chunk">
|
3239
3307
|
<div class="chunk name">
|
3240
|
-
<a name="
|
3241
|
-
<span>
|
3308
|
+
<a name="test-expand-haddock-rb">
|
3309
|
+
<span>test/expand_haddock.rb</span>
|
3242
3310
|
</a>
|
3243
3311
|
</div>
|
3244
3312
|
<div class="chunk html">
|
3245
3313
|
<pre class='ruby code syntax'>
|
3314
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar</span><span class="Special">"</span>
|
3315
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">test/spec</span><span class="Special">"</span>
|
3246
3316
|
|
3247
3317
|
</pre>
|
3248
3318
|
<table class='layout'>
|
@@ -3253,176 +3323,164 @@ messy. We therefore clean it up:
|
|
3253
3323
|
<td class='html'>
|
3254
3324
|
<div class='rdoc comment markup'>
|
3255
3325
|
<p>
|
3256
|
-
|
3257
|
-
empty lines for no apparent reason. Cleaning it up seems to be safe enough,
|
3258
|
-
and eliminates the ugly additional vertical space in the final HTML.
|
3326
|
+
Test expanding Haddock text.
|
3259
3327
|
</p>
|
3260
3328
|
</div>
|
3261
3329
|
</td>
|
3262
3330
|
</tr>
|
3263
3331
|
</table>
|
3264
3332
|
<pre class='ruby code syntax'>
|
3265
|
-
<span class="PreProc">
|
3266
|
-
|
3267
|
-
|
3268
|
-
|
3269
|
-
|
3270
|
-
|
3271
|
-
<span class="PreProc">
|
3333
|
+
<span class="PreProc">class</span> <span class="Type">TestExpandHaddock</span> < <span class="Type">Test</span>::<span class="Type">Unit</span>::<span class="Type">TestCase</span>
|
3334
|
+
|
3335
|
+
<span class="PreProc">def</span> <span class="Identifier">test_normal_text</span>
|
3336
|
+
<span class="Type">Codnar</span>::<span class="Type">Haddock</span>.to_html(<span class="Special">"</span><span class="Constant">normal</span><span class="Special">"</span>).should == <span class="Special">"</span><span class="Constant"><p>normal</span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Special">"</span>
|
3337
|
+
<span class="PreProc">end</span>
|
3338
|
+
|
3339
|
+
<span class="PreProc">def</span> <span class="Identifier">test_identifier_text</span>
|
3340
|
+
<span class="Type">Codnar</span>::<span class="Type">Haddock</span>.to_html(<span class="Special">"</span><span class="Constant">'Int'</span><span class="Special">"</span>).should == <span class="Special">"</span><span class="Constant"><p><code>Int</code></span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Special">"</span>
|
3341
|
+
<span class="PreProc">end</span>
|
3342
|
+
|
3343
|
+
<span class="PreProc">def</span> <span class="Identifier">test_emphasis_text</span>
|
3344
|
+
<span class="Type">Codnar</span>::<span class="Type">Haddock</span>.to_html(<span class="Special">"</span><span class="Constant">/emphasis/</span><span class="Special">"</span>).should == <span class="Special">"</span><span class="Constant"><p><em>emphasis</em></span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Special">"</span>
|
3345
|
+
<span class="PreProc">end</span>
|
3346
|
+
|
3347
|
+
<span class="PreProc">def</span> <span class="Identifier">test_code_text</span>
|
3348
|
+
<span class="Type">Codnar</span>::<span class="Type">Haddock</span>.to_html(<span class="Special">"</span><span class="Constant">@code@</span><span class="Special">"</span>).should == <span class="Special">"</span><span class="Constant"><pre>code</pre></span><span class="Special">\n</span><span class="Special">"</span>
|
3349
|
+
<span class="PreProc">end</span>
|
3272
3350
|
|
3351
|
+
<span class="PreProc">end</span>
|
3273
3352
|
</pre>
|
3274
3353
|
</div>
|
3275
|
-
<div class="chunk containers">
|
3276
|
-
<span class="chunk containers header">Contained in:</span>
|
3277
|
-
<ul class="chunk containers">
|
3278
|
-
<li class="chunk container">
|
3279
|
-
<a class="chunk container" href="#lib-codnar-string-extensions-rb">lib/codnar/string_extensions.rb</a>
|
3280
|
-
</li>
|
3281
|
-
</ul>
|
3282
|
-
</div>
|
3283
3354
|
</div>
|
3284
3355
|
</p>
|
3285
|
-
<h4>Generating diagrams using GraphViz</h4>
|
3286
|
-
<p>
|
3287
|
-
If you have <code>graphviz</code> installed, it is possible to use it to generate SVG
|
3288
|
-
diagrams that can be embedded directly into the HTML. This is implemented as an
|
3289
|
-
additional formatter; in principle, you this allows embeding the GraphViz
|
3290
|
-
directives directly in the code, but in practice people prefer keeping the
|
3291
|
-
diagrams as separate files.
|
3292
|
-
</p>
|
3293
|
-
<p>
|
3294
|
-
We pre-process the GraphViz directives using the <code>m4</code> macro processor. This
|
3295
|
-
allows dramatically reducing the amount of repeated boilerplate in the diagram
|
3296
|
-
definitions, by defining macros for node and edge styles and, if desired, more
|
3297
|
-
advanced techniques.
|
3298
|
-
</p>
|
3299
3356
|
<p>
|
3300
|
-
|
3357
|
+
And here is the implementation:
|
3301
3358
|
</p>
|
3302
3359
|
<p>
|
3303
3360
|
<div class="named_with_containers chunk">
|
3304
3361
|
<div class="chunk name">
|
3305
|
-
<a name="
|
3306
|
-
<span>
|
3362
|
+
<a name="lib-codnar-haddock-rb">
|
3363
|
+
<span>lib/codnar/haddock.rb</span>
|
3307
3364
|
</a>
|
3308
3365
|
</div>
|
3309
3366
|
<div class="chunk html">
|
3310
3367
|
<pre class='ruby code syntax'>
|
3311
|
-
<span class="PreProc">
|
3312
|
-
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">test/spec</span><span class="Special">"</span>
|
3368
|
+
<span class="PreProc">module</span> <span class="Type">Codnar</span>
|
3313
3369
|
|
3314
3370
|
</pre>
|
3315
|
-
<table class='layout'>
|
3371
|
+
<table class='layout'>
|
3316
3372
|
<tr>
|
3317
3373
|
<td class='indentation'>
|
3318
|
-
<pre
|
3374
|
+
<pre> </pre>
|
3319
3375
|
</td>
|
3320
3376
|
<td class='html'>
|
3321
3377
|
<div class='rdoc comment markup'>
|
3322
3378
|
<p>
|
3323
|
-
|
3379
|
+
Convert Haddoc to HTML.
|
3324
3380
|
</p>
|
3325
3381
|
</div>
|
3326
3382
|
</td>
|
3327
3383
|
</tr>
|
3328
3384
|
</table>
|
3329
3385
|
<pre class='ruby code syntax'>
|
3330
|
-
<span class="PreProc">class</span> <span class="Type">
|
3386
|
+
<span class="PreProc">class</span> <span class="Type">Haddock</span>
|
3331
3387
|
|
3332
|
-
<span class="Type">MINIMAL_DIAGRAM_SVG</span> = <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( svg</span>
|
3333
|
-
</pre>
|
3334
|
-
<pre class='svg code syntax'>
|
3335
|
-
<span class="Identifier"><</span><span class="Identifier">svg</span><span class="Identifier"> </span><span class="Type">width</span>=<span class="Constant">"62pt"</span><span class="Identifier"> </span><span class="Type">height</span>=<span class="Constant">"116pt"</span>
|
3336
|
-
<span class="Identifier"> </span><span class="Type">viewBox</span>=<span class="Constant">"0.00 0.00 62.00 116.00"</span><span class="Identifier"> </span><span class="Type">xmlns</span>=<span class="Constant">"<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg</a>"</span><span class="Identifier"> </span><span class="Type">xmlns</span><span class="Comment">:</span><span class="Type">xlink</span>=<span class="Constant">"<a href="http://www.w3.org/1999/xlink">http://www.w3.org/1999/xlink</a>"</span><span class="Identifier">></span>
|
3337
|
-
<span class="Identifier"><</span><span class="Identifier">g</span><span class="Identifier"> </span><span class="Type">id</span>=<span class="Constant">"graph1"</span><span class="Identifier"> </span><span class="Type">class</span>=<span class="Constant">"graph"</span><span class="Identifier"> </span><span class="Type">transform</span>=<span class="Constant">"scale(1 1) rotate(0) translate(4 112)"</span><span class="Identifier">></span>
|
3338
|
-
<span class="Identifier"><</span><span class="Identifier">title</span><span class="Identifier">></span>_anonymous_0<span class="Identifier"></title></span>
|
3339
|
-
<span class="Identifier"><</span><span class="Identifier">polygon</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"white"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"white"</span><span class="Identifier"> </span><span class="Type">points</span>=<span class="Constant">"-4,5 -4,-112 59,-112 59,5 -4,5"</span><span class="Identifier">/></span>
|
3340
|
-
<span class="Comment"><!</span><span class="Comment">-- A --</span><span class="Comment">></span>
|
3341
|
-
<span class="Identifier"><</span><span class="Identifier">g</span><span class="Identifier"> </span><span class="Type">id</span>=<span class="Constant">"node1"</span><span class="Identifier"> </span><span class="Type">class</span>=<span class="Constant">"node"</span><span class="Identifier">><</span><span class="Identifier">title</span><span class="Identifier">></span>A<span class="Identifier"></title></span>
|
3342
|
-
<span class="Identifier"><</span><span class="Identifier">ellipse</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"none"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">cx</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">cy</span>=<span class="Constant">"-90"</span><span class="Identifier"> </span><span class="Type">rx</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">ry</span>=<span class="Constant">"18"</span><span class="Identifier">/></span>
|
3343
|
-
<span class="Identifier"><</span><span class="Identifier">text</span><span class="Identifier"> </span><span class="Type">text-anchor</span>=<span class="Constant">"middle"</span><span class="Identifier"> </span><span class="Type">x</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">y</span>=<span class="Constant">"-85.4"</span><span class="Identifier"> </span><span class="Type">font-family</span>=<span class="Constant">"Times New Roman,serif"</span><span class="Identifier"> </span><span class="Type">font-size</span>=<span class="Constant">"14.00"</span><span class="Identifier">></span>A<span class="Identifier"></text></span>
|
3344
|
-
<span class="Identifier"></g></span>
|
3345
|
-
<span class="Comment"><!</span><span class="Comment">-- B --</span><span class="Comment">></span>
|
3346
|
-
<span class="Identifier"><</span><span class="Identifier">g</span><span class="Identifier"> </span><span class="Type">id</span>=<span class="Constant">"node3"</span><span class="Identifier"> </span><span class="Type">class</span>=<span class="Constant">"node"</span><span class="Identifier">><</span><span class="Identifier">title</span><span class="Identifier">></span>B<span class="Identifier"></title></span>
|
3347
|
-
<span class="Identifier"><</span><span class="Identifier">ellipse</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"none"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">cx</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">cy</span>=<span class="Constant">"-18"</span><span class="Identifier"> </span><span class="Type">rx</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">ry</span>=<span class="Constant">"18"</span><span class="Identifier">/></span>
|
3348
|
-
<span class="Identifier"><</span><span class="Identifier">text</span><span class="Identifier"> </span><span class="Type">text-anchor</span>=<span class="Constant">"middle"</span><span class="Identifier"> </span><span class="Type">x</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">y</span>=<span class="Constant">"-13.4"</span><span class="Identifier"> </span><span class="Type">font-family</span>=<span class="Constant">"Times New Roman,serif"</span><span class="Identifier"> </span><span class="Type">font-size</span>=<span class="Constant">"14.00"</span><span class="Identifier">></span>B<span class="Identifier"></text></span>
|
3349
|
-
<span class="Identifier"></g></span>
|
3350
|
-
<span class="Comment"><!</span><span class="Comment">-- A&#45;&gt;B --</span><span class="Comment">></span>
|
3351
|
-
<span class="Identifier"><</span><span class="Identifier">g</span><span class="Identifier"> </span><span class="Type">id</span>=<span class="Constant">"edge2"</span><span class="Identifier"> </span><span class="Type">class</span>=<span class="Constant">"edge"</span><span class="Identifier">><</span><span class="Identifier">title</span><span class="Identifier">></span>A<span class="Type">&</span><span class="Statement">#45</span><span class="Type">;&</span><span class="Statement">gt</span><span class="Type">;</span>B<span class="Identifier"></title></span>
|
3352
|
-
<span class="Identifier"><</span><span class="Identifier">path</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"none"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">d</span>=<span class="Constant">"M27,-71.8314C27,-64.131 27,-54.9743 27,-46.4166"</span><span class="Identifier">/></span>
|
3353
|
-
<span class="Identifier"><</span><span class="Identifier">polygon</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">points</span>=<span class="Constant">"30.5001,-46.4132 27,-36.4133 23.5001,-46.4133 30.5001,-46.4132"</span><span class="Identifier">/></span>
|
3354
|
-
<span class="Identifier"></g></span>
|
3355
|
-
<span class="Identifier"></g></span>
|
3356
|
-
<span class="Identifier"></svg></span>
|
3357
|
-
EOF
|
3358
3388
|
</pre>
|
3389
|
+
<table class='layout'>
|
3390
|
+
<tr>
|
3391
|
+
<td class='indentation'>
|
3392
|
+
<pre> </pre>
|
3393
|
+
</td>
|
3394
|
+
<td class='html'>
|
3395
|
+
<div class='rdoc comment markup'>
|
3396
|
+
<p>
|
3397
|
+
Process a Haddock String and return the resulting HTML.
|
3398
|
+
</p>
|
3399
|
+
</div>
|
3400
|
+
</td>
|
3401
|
+
</tr>
|
3402
|
+
</table>
|
3359
3403
|
<pre class='ruby code syntax'>
|
3360
|
-
|
3404
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">to_html</span>(haddock)
|
3405
|
+
with_temporary_directory <span class="Statement">do</span> |<span class="Identifier">path</span>|
|
3406
|
+
write_temporary_file(path, haddock)
|
3407
|
+
run_haddock(path)
|
3408
|
+
html = read_html_file(path)
|
3409
|
+
clean_html(html)
|
3410
|
+
<span class="Statement">end</span>
|
3411
|
+
<span class="PreProc">end</span>
|
3361
3412
|
|
3362
|
-
<span class="
|
3363
|
-
diagram = <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( dot</span>
|
3364
|
-
</pre>
|
3365
|
-
<pre class='dot code syntax'>
|
3366
|
-
<span class="Identifier">define</span><span class="Statement">(</span>`<span class="Identifier">X</span>', `<span class="Identifier">A</span>'<span class="Statement">)</span>
|
3367
|
-
<span class="Statement">digraph</span> <span class="Statement">{</span>
|
3368
|
-
<span class="Identifier">X</span> <span class="Statement">-></span> <span class="Identifier">B</span><span class="Statement">;</span>
|
3369
|
-
<span class="Statement">}</span>
|
3370
|
-
<span class="Identifier">EOF</span>
|
3371
|
-
</pre>
|
3372
|
-
<pre class='ruby code syntax'>
|
3373
|
-
<span class="Comment">#! ))) dot</span>
|
3374
|
-
<span class="Type">Codnar</span>::<span class="Type">GraphViz</span>.to_html(diagram).should == <span class="Type">MINIMAL_DIAGRAM_SVG</span>
|
3375
|
-
end
|
3413
|
+
<span class="Statement">protected</span>
|
3376
3414
|
|
3377
|
-
<span class="PreProc">def</span> <span class="Identifier">test_invalid_diagram</span>
|
3378
|
-
diagram = <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( dot</span>
|
3379
|
-
</pre>
|
3380
|
-
<pre class='dot code syntax'>
|
3381
|
-
<span class="Statement">digraph</span> <span class="Statement">{</span>
|
3382
|
-
<span class="Identifier">A</span> <span class="Statement">-></span>
|
3383
|
-
<span class="Identifier">EOF</span>
|
3384
3415
|
</pre>
|
3416
|
+
<table class='layout'>
|
3417
|
+
<tr>
|
3418
|
+
<td class='indentation'>
|
3419
|
+
<pre> </pre>
|
3420
|
+
</td>
|
3421
|
+
<td class='html'>
|
3422
|
+
<div class='rdoc comment markup'>
|
3423
|
+
<p>
|
3424
|
+
Run a block using a temporary directory, that is then removed. TODO: This
|
3425
|
+
should be in some more generic place.
|
3426
|
+
</p>
|
3427
|
+
</div>
|
3428
|
+
</td>
|
3429
|
+
</tr>
|
3430
|
+
</table>
|
3385
3431
|
<pre class='ruby code syntax'>
|
3386
|
-
<span class="
|
3387
|
-
|
3388
|
-
|
3432
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">with_temporary_directory</span>
|
3433
|
+
path = create_temporary_directory
|
3434
|
+
result = <span class="Statement">yield</span> path
|
3435
|
+
<span class="Type">FileUtils</span>.rm_rf(path)
|
3436
|
+
<span class="Statement">return</span> result
|
3437
|
+
<span class="PreProc">end</span>
|
3389
3438
|
|
3390
|
-
end
|
3391
3439
|
</pre>
|
3392
|
-
|
3393
|
-
|
3394
|
-
|
3440
|
+
<table class='layout'>
|
3441
|
+
<tr>
|
3442
|
+
<td class='indentation'>
|
3443
|
+
<pre> </pre>
|
3444
|
+
</td>
|
3445
|
+
<td class='html'>
|
3446
|
+
<div class='rdoc comment markup'>
|
3395
3447
|
<p>
|
3396
|
-
|
3448
|
+
Create a temporary directory to run Haddock in.
|
3397
3449
|
</p>
|
3398
|
-
<p>
|
3399
|
-
<div class="named_with_containers chunk">
|
3400
|
-
<div class="chunk name">
|
3401
|
-
<a name="lib-codnar-graphviz-rb">
|
3402
|
-
<span>lib/codnar/graphviz.rb</span>
|
3403
|
-
</a>
|
3404
3450
|
</div>
|
3405
|
-
|
3451
|
+
</td>
|
3452
|
+
</tr>
|
3453
|
+
</table>
|
3406
3454
|
<pre class='ruby code syntax'>
|
3407
|
-
<span class="PreProc">
|
3455
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">create_temporary_directory</span>
|
3456
|
+
file = <span class="Type">Tempfile</span>.open(<span class="Special">"</span><span class="Constant">dir</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">.</span><span class="Special">"</span>)
|
3457
|
+
path = file.path
|
3458
|
+
<span class="Type">File</span>.delete(path)
|
3459
|
+
<span class="Type">Dir</span>.mkdir(path)
|
3460
|
+
<span class="Statement">return</span> path
|
3461
|
+
<span class="PreProc">end</span>
|
3408
3462
|
|
3409
3463
|
</pre>
|
3410
|
-
|
3464
|
+
<table class='layout'>
|
3411
3465
|
<tr>
|
3412
3466
|
<td class='indentation'>
|
3413
|
-
<pre>
|
3467
|
+
<pre> </pre>
|
3414
3468
|
</td>
|
3415
3469
|
<td class='html'>
|
3416
3470
|
<div class='rdoc comment markup'>
|
3417
3471
|
<p>
|
3418
|
-
|
3472
|
+
Minimal header to insert before the Haddock String to trick Haddock into
|
3473
|
+
generating HTML from it.
|
3419
3474
|
</p>
|
3420
3475
|
</div>
|
3421
3476
|
</td>
|
3422
3477
|
</tr>
|
3423
3478
|
</table>
|
3424
3479
|
<pre class='ruby code syntax'>
|
3425
|
-
|
3480
|
+
<span class="Type">HADDOCK_HEADER</span> = <<-<span class="Special">EOF</span>.unindent
|
3481
|
+
<span class="Constant"> module Wrapper where</span>
|
3482
|
+
<span class="Constant"> -- $doc</span>
|
3483
|
+
<span class="Constant"> </span><span class="Special">EOF</span>
|
3426
3484
|
|
3427
3485
|
</pre>
|
3428
3486
|
<table class='layout'>
|
@@ -3433,26 +3491,21 @@ Generate diagrams using GraphViz.
|
|
3433
3491
|
<td class='html'>
|
3434
3492
|
<div class='rdoc comment markup'>
|
3435
3493
|
<p>
|
3436
|
-
|
3437
|
-
|
3438
|
-
to allow cutting down on the boilerplate (repeating the same styles in many
|
3439
|
-
nodes etc.). This should not be harmful for diagrams that do not use M4
|
3440
|
-
commands.
|
3494
|
+
Write the Haddock String into a wrapper Haskell file so we’ll be able to
|
3495
|
+
run Haddock to generate HTML from it.
|
3441
3496
|
</p>
|
3442
3497
|
</div>
|
3443
3498
|
</td>
|
3444
3499
|
</tr>
|
3445
3500
|
</table>
|
3446
3501
|
<pre class='ruby code syntax'>
|
3447
|
-
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">
|
3448
|
-
|
3449
|
-
|
3450
|
-
|
3451
|
-
<span class="Statement">
|
3502
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">write_temporary_file</span>(path, haddock)
|
3503
|
+
<span class="Type">File</span>.open(path + <span class="Special">"</span><span class="Constant">/wrapper.hs</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">w</span><span class="Special">"</span>) <span class="Statement">do</span> |<span class="Identifier">file</span>|
|
3504
|
+
file.write(<span class="Type">HADDOCK_HEADER</span>)
|
3505
|
+
file.write(<span class="Special">"</span><span class="Constant">-- </span><span class="Special">"</span> + haddock.gsub(<span class="Special">"</span><span class="Special">\n</span><span class="Special">"</span>, <span class="Special">"</span><span class="Special">\n</span><span class="Constant">-- </span><span class="Special">"</span>))
|
3506
|
+
<span class="Statement">end</span>
|
3452
3507
|
<span class="PreProc">end</span>
|
3453
3508
|
|
3454
|
-
<span class="Statement">protected</span>
|
3455
|
-
|
3456
3509
|
</pre>
|
3457
3510
|
<table class='layout'>
|
3458
3511
|
<tr>
|
@@ -3462,16 +3515,15 @@ commands.
|
|
3462
3515
|
<td class='html'>
|
3463
3516
|
<div class='rdoc comment markup'>
|
3464
3517
|
<p>
|
3465
|
-
|
3518
|
+
Run Haddock to convert the wrapper Haskell file into HTML documentation.
|
3466
3519
|
</p>
|
3467
3520
|
</div>
|
3468
3521
|
</td>
|
3469
3522
|
</tr>
|
3470
3523
|
</table>
|
3471
3524
|
<pre class='ruby code syntax'>
|
3472
|
-
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">
|
3473
|
-
|
3474
|
-
stdin.close
|
3525
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">run_haddock</span>(path)
|
3526
|
+
system(<span class="Special">"</span><span class="Constant">cd </span><span class="Special">#{</span>path<span class="Special">}</span><span class="Constant"> && haddock --html wrapper.hs > haddock.out 2>&1</span><span class="Special">"</span>)
|
3475
3527
|
<span class="PreProc">end</span>
|
3476
3528
|
|
3477
3529
|
</pre>
|
@@ -3483,17 +3535,15 @@ Send the diagram to the commands pipe.
|
|
3483
3535
|
<td class='html'>
|
3484
3536
|
<div class='rdoc comment markup'>
|
3485
3537
|
<p>
|
3486
|
-
|
3487
|
-
them, and they will be handled by the formatter wrapping code.
|
3538
|
+
Read the HTML generated by Haddock.
|
3488
3539
|
</p>
|
3489
3540
|
</div>
|
3490
3541
|
</td>
|
3491
3542
|
</tr>
|
3492
3543
|
</table>
|
3493
3544
|
<pre class='ruby code syntax'>
|
3494
|
-
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">
|
3495
|
-
|
3496
|
-
<span class="Statement">raise</span> errors.sub(<span class="Special">/</span><span class="Constant">Error: <stdin>:</span><span class="Special">\d</span><span class="Special">+</span><span class="Constant">: </span><span class="Special">/</span>, <span class="Special">""</span>) <span class="Statement">if</span> errors != <span class="Special">""</span>
|
3545
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">read_html_file</span>(path)
|
3546
|
+
<span class="Statement">return</span> <span class="Type">File</span>.read(path + <span class="Special">"</span><span class="Constant">/Wrapper.html</span><span class="Special">"</span>)
|
3497
3547
|
<span class="PreProc">end</span>
|
3498
3548
|
|
3499
3549
|
</pre>
|
@@ -3505,15 +3555,18 @@ them, and they will be handled by the formatter wrapping code.
|
|
3505
3555
|
<td class='html'>
|
3506
3556
|
<div class='rdoc comment markup'>
|
3507
3557
|
<p>
|
3508
|
-
|
3558
|
+
Extract the clean generated HTML from Haddock’s output.
|
3509
3559
|
</p>
|
3510
3560
|
</div>
|
3511
3561
|
</td>
|
3512
3562
|
</tr>
|
3513
3563
|
</table>
|
3514
3564
|
<pre class='ruby code syntax'>
|
3515
|
-
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">
|
3516
|
-
|
3565
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">clean_html</span>(html)
|
3566
|
+
html.gsub!(<span class="Special">"</span><span class="Special">\r\n</span><span class="Special">"</span>, <span class="Special">"</span><span class="Special">\n</span><span class="Special">"</span>)
|
3567
|
+
html.sub!(<span class="Special">/</span><span class="Special">.</span><span class="Special">*</span><span class="Constant"><div class="doc"></span><span class="Special">/m</span>, <span class="Special">''</span>)
|
3568
|
+
html.sub!(<span class="Special">/</span><span class="Constant"><</span><span class="Special">\/</span><span class="Constant">div><</span><span class="Special">\/</span><span class="Constant">div><</span><span class="Special">\/</span><span class="Constant">div><div id="footer"></span><span class="Special">.</span><span class="Special">*</span><span class="Special">/m</span>, <span class="Special">"</span><span class="Special">\n</span><span class="Special">"</span>)
|
3569
|
+
<span class="Statement">return</span> html
|
3517
3570
|
<span class="PreProc">end</span>
|
3518
3571
|
|
3519
3572
|
end
|
@@ -3523,20 +3576,83 @@ end
|
|
3523
3576
|
</div>
|
3524
3577
|
</div>
|
3525
3578
|
</p>
|
3526
|
-
|
3579
|
+
</li>
|
3580
|
+
</ul>
|
3527
3581
|
<p>
|
3528
|
-
|
3529
|
-
|
3530
|
-
a command-line tool. However, what it lacks in speed it compensates for in
|
3531
|
-
scope; almost any language you can think of has a GVim syntax highlighting
|
3532
|
-
definition. Here is a simple test that demonstrates using GVim for syntax
|
3533
|
-
highlighting:
|
3582
|
+
In all cases, the HTML generated by the markup format conversion is a bit
|
3583
|
+
messy. We therefore clean it up:
|
3534
3584
|
</p>
|
3535
3585
|
<p>
|
3536
3586
|
<div class="named_with_containers chunk">
|
3537
3587
|
<div class="chunk name">
|
3538
|
-
<a name="
|
3539
|
-
<span>
|
3588
|
+
<a name="clean-html">
|
3589
|
+
<span>Clean HTML</span>
|
3590
|
+
</a>
|
3591
|
+
</div>
|
3592
|
+
<div class="chunk html">
|
3593
|
+
<pre class='ruby code syntax'>
|
3594
|
+
|
3595
|
+
</pre>
|
3596
|
+
<table class='layout'>
|
3597
|
+
<tr>
|
3598
|
+
<td class='indentation'>
|
3599
|
+
<pre></pre>
|
3600
|
+
</td>
|
3601
|
+
<td class='html'>
|
3602
|
+
<div class='rdoc comment markup'>
|
3603
|
+
<p>
|
3604
|
+
Clean HTML generated by markup formatters. Such HTML tends to have extra
|
3605
|
+
empty lines for no apparent reason. Cleaning it up seems to be safe enough,
|
3606
|
+
and eliminates the ugly additional vertical space in the final HTML.
|
3607
|
+
</p>
|
3608
|
+
</div>
|
3609
|
+
</td>
|
3610
|
+
</tr>
|
3611
|
+
</table>
|
3612
|
+
<pre class='ruby code syntax'>
|
3613
|
+
<span class="PreProc">def</span> <span class="Identifier">clean_markup_html</span>
|
3614
|
+
<span class="Statement">return</span> gsub(<span class="Special">"</span><span class="Special">\r\n</span><span class="Special">"</span>, <span class="Special">"</span><span class="Special">\n</span><span class="Special">"</span>) \
|
3615
|
+
.gsub(<span class="Special">/</span><span class="Special">\n</span><span class="Special">*</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Special">*</span><span class="Special">/</span>, <span class="Special">"</span><span class="Special">\n</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Special">"</span>) \
|
3616
|
+
.gsub(<span class="Special">/</span><span class="Special">\n</span><span class="Special">*</span><span class="Constant"><</span><span class="Special">\/</span><span class="Constant">p></span><span class="Special">\n</span><span class="Special">*</span><span class="Special">/</span>, <span class="Special">"</span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Special">"</span>) \
|
3617
|
+
.gsub(<span class="Special">/</span><span class="Special">\n</span><span class="Special">*</span><span class="Constant"><pre></span><span class="Special">\n</span><span class="Special">+</span><span class="Special">/</span>, <span class="Special">"</span><span class="Special">\n</span><span class="Constant"><pre></span><span class="Special">\n</span><span class="Special">"</span>) \
|
3618
|
+
.gsub(<span class="Special">/</span><span class="Special">\n</span><span class="Special">+</span><span class="Constant"><</span><span class="Special">\/</span><span class="Constant">pre></span><span class="Special">\n</span><span class="Special">*</span><span class="Special">/</span>, <span class="Special">"</span><span class="Special">\n</span><span class="Constant"></pre></span><span class="Special">\n</span><span class="Special">"</span>) \
|
3619
|
+
.sub(<span class="Special">/</span><span class="Special">^</span><span class="Special">\n</span><span class="Special">*</span><span class="Special">/</span>, <span class="Special">""</span>)
|
3620
|
+
<span class="PreProc">end</span>
|
3621
|
+
|
3622
|
+
</pre>
|
3623
|
+
</div>
|
3624
|
+
<div class="chunk containers">
|
3625
|
+
<span class="chunk containers header">Contained in:</span>
|
3626
|
+
<ul class="chunk containers">
|
3627
|
+
<li class="chunk container">
|
3628
|
+
<a class="chunk container" href="#lib-codnar-string-extensions-rb">lib/codnar/string_extensions.rb</a>
|
3629
|
+
</li>
|
3630
|
+
</ul>
|
3631
|
+
</div>
|
3632
|
+
</div>
|
3633
|
+
</p>
|
3634
|
+
<h4>Generating diagrams using GraphViz</h4>
|
3635
|
+
<p>
|
3636
|
+
If you have <code>graphviz</code> installed, it is possible to use it to generate SVG
|
3637
|
+
diagrams that can be embedded directly into the HTML. This is implemented as an
|
3638
|
+
additional formatter; in principle, you this allows embeding the GraphViz
|
3639
|
+
directives directly in the code, but in practice people prefer keeping the
|
3640
|
+
diagrams as separate files.
|
3641
|
+
</p>
|
3642
|
+
<p>
|
3643
|
+
We pre-process the GraphViz directives using the <code>m4</code> macro processor. This
|
3644
|
+
allows dramatically reducing the amount of repeated boilerplate in the diagram
|
3645
|
+
definitions, by defining macros for node and edge styles and, if desired, more
|
3646
|
+
advanced techniques.
|
3647
|
+
</p>
|
3648
|
+
<p>
|
3649
|
+
Here is a simple test that demonstrates generating SVG from a GraphViz diagram:
|
3650
|
+
</p>
|
3651
|
+
<p>
|
3652
|
+
<div class="named_with_containers chunk">
|
3653
|
+
<div class="chunk name">
|
3654
|
+
<a name="test-graphviz-diagrams-rb">
|
3655
|
+
<span>test/graphviz_diagrams.rb</span>
|
3540
3656
|
</a>
|
3541
3657
|
</div>
|
3542
3658
|
<div class="chunk html">
|
@@ -3560,56 +3676,64 @@ Test highlighting syntax using GVim.
|
|
3560
3676
|
</tr>
|
3561
3677
|
</table>
|
3562
3678
|
<pre class='ruby code syntax'>
|
3563
|
-
<span class="PreProc">class</span> <span class="Type">
|
3564
|
-
|
3565
|
-
<span class="PreProc">def</span> <span class="Identifier">setup</span>
|
3566
|
-
<span class="Type">Codnar</span>::<span class="Type">GVim</span>.force_recompute = <span class="Constant">true</span>
|
3567
|
-
<span class="PreProc">end</span>
|
3679
|
+
<span class="PreProc">class</span> <span class="Type">TestGraphVizDiagrams</span> < <span class="Type">Test</span>::<span class="Type">Unit</span>::<span class="Type">TestCase</span>
|
3568
3680
|
|
3569
|
-
<span class="
|
3570
|
-
|
3571
|
-
|
3681
|
+
<span class="Type">MINIMAL_DIAGRAM_SVG</span> = <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( svg</span>
|
3682
|
+
</pre>
|
3683
|
+
<pre class='svg code syntax'>
|
3684
|
+
<span class="Identifier"><</span><span class="Identifier">svg</span><span class="Identifier"> </span><span class="Type">width</span>=<span class="Constant">"62pt"</span><span class="Identifier"> </span><span class="Type">height</span>=<span class="Constant">"116pt"</span>
|
3685
|
+
<span class="Identifier"> </span><span class="Type">viewBox</span>=<span class="Constant">"0.00 0.00 62.00 116.00"</span><span class="Identifier"> </span><span class="Type">xmlns</span>=<span class="Constant">"<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg</a>"</span><span class="Identifier"> </span><span class="Type">xmlns</span><span class="Comment">:</span><span class="Type">xlink</span>=<span class="Constant">"<a href="http://www.w3.org/1999/xlink">http://www.w3.org/1999/xlink</a>"</span><span class="Identifier">></span>
|
3686
|
+
<span class="Identifier"><</span><span class="Identifier">g</span><span class="Identifier"> </span><span class="Type">id</span>=<span class="Constant">"graph1"</span><span class="Identifier"> </span><span class="Type">class</span>=<span class="Constant">"graph"</span><span class="Identifier"> </span><span class="Type">transform</span>=<span class="Constant">"scale(1 1) rotate(0) translate(4 112)"</span><span class="Identifier">></span>
|
3687
|
+
<span class="Identifier"><</span><span class="Identifier">title</span><span class="Identifier">></span>_anonymous_0<span class="Identifier"></title></span>
|
3688
|
+
<span class="Identifier"><</span><span class="Identifier">polygon</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"white"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"white"</span><span class="Identifier"> </span><span class="Type">points</span>=<span class="Constant">"-4,5 -4,-112 59,-112 59,5 -4,5"</span><span class="Identifier">/></span>
|
3689
|
+
<span class="Comment"><!</span><span class="Comment">-- A --</span><span class="Comment">></span>
|
3690
|
+
<span class="Identifier"><</span><span class="Identifier">g</span><span class="Identifier"> </span><span class="Type">id</span>=<span class="Constant">"node1"</span><span class="Identifier"> </span><span class="Type">class</span>=<span class="Constant">"node"</span><span class="Identifier">><</span><span class="Identifier">title</span><span class="Identifier">></span>A<span class="Identifier"></title></span>
|
3691
|
+
<span class="Identifier"><</span><span class="Identifier">ellipse</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"none"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">cx</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">cy</span>=<span class="Constant">"-90"</span><span class="Identifier"> </span><span class="Type">rx</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">ry</span>=<span class="Constant">"18"</span><span class="Identifier">/></span>
|
3692
|
+
<span class="Identifier"><</span><span class="Identifier">text</span><span class="Identifier"> </span><span class="Type">text-anchor</span>=<span class="Constant">"middle"</span><span class="Identifier"> </span><span class="Type">x</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">y</span>=<span class="Constant">"-85.4"</span><span class="Identifier"> </span><span class="Type">font-family</span>=<span class="Constant">"Times New Roman,serif"</span><span class="Identifier"> </span><span class="Type">font-size</span>=<span class="Constant">"14.00"</span><span class="Identifier">></span>A<span class="Identifier"></text></span>
|
3693
|
+
<span class="Identifier"></g></span>
|
3694
|
+
<span class="Comment"><!</span><span class="Comment">-- B --</span><span class="Comment">></span>
|
3695
|
+
<span class="Identifier"><</span><span class="Identifier">g</span><span class="Identifier"> </span><span class="Type">id</span>=<span class="Constant">"node3"</span><span class="Identifier"> </span><span class="Type">class</span>=<span class="Constant">"node"</span><span class="Identifier">><</span><span class="Identifier">title</span><span class="Identifier">></span>B<span class="Identifier"></title></span>
|
3696
|
+
<span class="Identifier"><</span><span class="Identifier">ellipse</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"none"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">cx</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">cy</span>=<span class="Constant">"-18"</span><span class="Identifier"> </span><span class="Type">rx</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">ry</span>=<span class="Constant">"18"</span><span class="Identifier">/></span>
|
3697
|
+
<span class="Identifier"><</span><span class="Identifier">text</span><span class="Identifier"> </span><span class="Type">text-anchor</span>=<span class="Constant">"middle"</span><span class="Identifier"> </span><span class="Type">x</span>=<span class="Constant">"27"</span><span class="Identifier"> </span><span class="Type">y</span>=<span class="Constant">"-13.4"</span><span class="Identifier"> </span><span class="Type">font-family</span>=<span class="Constant">"Times New Roman,serif"</span><span class="Identifier"> </span><span class="Type">font-size</span>=<span class="Constant">"14.00"</span><span class="Identifier">></span>B<span class="Identifier"></text></span>
|
3698
|
+
<span class="Identifier"></g></span>
|
3699
|
+
<span class="Comment"><!</span><span class="Comment">-- A&#45;&gt;B --</span><span class="Comment">></span>
|
3700
|
+
<span class="Identifier"><</span><span class="Identifier">g</span><span class="Identifier"> </span><span class="Type">id</span>=<span class="Constant">"edge2"</span><span class="Identifier"> </span><span class="Type">class</span>=<span class="Constant">"edge"</span><span class="Identifier">><</span><span class="Identifier">title</span><span class="Identifier">></span>A<span class="Type">&</span><span class="Statement">#45</span><span class="Type">;&</span><span class="Statement">gt</span><span class="Type">;</span>B<span class="Identifier"></title></span>
|
3701
|
+
<span class="Identifier"><</span><span class="Identifier">path</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"none"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">d</span>=<span class="Constant">"M27,-71.8314C27,-64.131 27,-54.9743 27,-46.4166"</span><span class="Identifier">/></span>
|
3702
|
+
<span class="Identifier"><</span><span class="Identifier">polygon</span><span class="Identifier"> </span><span class="Type">fill</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">stroke</span>=<span class="Constant">"black"</span><span class="Identifier"> </span><span class="Type">points</span>=<span class="Constant">"30.5001,-46.4132 27,-36.4133 23.5001,-46.4133 30.5001,-46.4132"</span><span class="Identifier">/></span>
|
3703
|
+
<span class="Identifier"></g></span>
|
3704
|
+
<span class="Identifier"></g></span>
|
3705
|
+
<span class="Identifier"></svg></span>
|
3706
|
+
EOF
|
3707
|
+
</pre>
|
3708
|
+
<pre class='ruby code syntax'>
|
3709
|
+
<span class="Comment">#! ))) svg</span>
|
3572
3710
|
|
3573
|
-
<span class="PreProc">def</span> <span class="Identifier">
|
3574
|
-
|
3575
|
-
<span class="Constant"> def foo</span>
|
3576
|
-
<span class="Constant"> return bar = baz</span>
|
3577
|
-
<span class="Constant"> end</span>
|
3578
|
-
<span class="Constant"> </span><span class="Special">EOF</span>
|
3579
|
-
<span class="Type">Codnar</span>::<span class="Type">GVim</span>.cached_syntax_to_html(ruby, <span class="Special">"</span><span class="Constant">ruby</span><span class="Special">"</span>).should == <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( html</span>
|
3711
|
+
<span class="PreProc">def</span> <span class="Identifier">test_valid_diagram</span>
|
3712
|
+
diagram = <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( dot</span>
|
3580
3713
|
</pre>
|
3581
|
-
<pre class='
|
3582
|
-
<span class="Identifier"
|
3583
|
-
<span class="
|
3584
|
-
|
3585
|
-
<span class="
|
3586
|
-
|
3587
|
-
<span class="Identifier"></</span><span class="Statement">font</span><span class="Identifier">></span>
|
3588
|
-
<span class="Identifier"></</span><span class="Statement">div</span><span class="Identifier">></span>
|
3589
|
-
EOF
|
3714
|
+
<pre class='dot code syntax'>
|
3715
|
+
<span class="Identifier">define</span><span class="Statement">(</span>`<span class="Identifier">X</span>', `<span class="Identifier">A</span>'<span class="Statement">)</span>
|
3716
|
+
<span class="Statement">digraph</span> <span class="Statement">{</span>
|
3717
|
+
<span class="Identifier">X</span> <span class="Statement">-></span> <span class="Identifier">B</span><span class="Statement">;</span>
|
3718
|
+
<span class="Statement">}</span>
|
3719
|
+
<span class="Identifier">EOF</span>
|
3590
3720
|
</pre>
|
3591
3721
|
<pre class='ruby code syntax'>
|
3592
|
-
<span class="Comment">#! )))
|
3722
|
+
<span class="Comment">#! ))) dot</span>
|
3723
|
+
<span class="Type">Codnar</span>::<span class="Type">GraphViz</span>.to_html(diagram).should == <span class="Type">MINIMAL_DIAGRAM_SVG</span>
|
3593
3724
|
end
|
3594
3725
|
|
3595
|
-
<span class="PreProc">def</span> <span class="Identifier">
|
3596
|
-
|
3597
|
-
<span class="Constant"> def foo</span>
|
3598
|
-
<span class="Constant"> return bar = baz</span>
|
3599
|
-
<span class="Constant"> end</span>
|
3600
|
-
<span class="Constant"> </span><span class="Special">EOF</span>
|
3601
|
-
<span class="Type">Codnar</span>::<span class="Type">GVim</span>.cached_syntax_to_html(ruby, <span class="Special">"</span><span class="Constant">ruby</span><span class="Special">"</span>, [ <span class="Special">"</span><span class="Constant">+:let html_use_css=1</span><span class="Special">"</span> ]).should == <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( html</span>
|
3726
|
+
<span class="PreProc">def</span> <span class="Identifier">test_invalid_diagram</span>
|
3727
|
+
diagram = <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( dot</span>
|
3602
3728
|
</pre>
|
3603
|
-
<pre class='
|
3604
|
-
<span class="
|
3605
|
-
|
3606
|
-
|
3607
|
-
<span class="Identifier"><</span><span class="Statement">span</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">"PreProc"</span><span class="Identifier">></span>end<span class="Identifier"></</span><span class="Statement">span</span><span class="Identifier">></span>
|
3608
|
-
<span class="Identifier"></</span><span class="Statement">pre</span><span class="Identifier">></span>
|
3609
|
-
EOF
|
3729
|
+
<pre class='dot code syntax'>
|
3730
|
+
<span class="Statement">digraph</span> <span class="Statement">{</span>
|
3731
|
+
<span class="Identifier">A</span> <span class="Statement">-></span>
|
3732
|
+
<span class="Identifier">EOF</span>
|
3610
3733
|
</pre>
|
3611
3734
|
<pre class='ruby code syntax'>
|
3612
|
-
<span class="Comment">#! )))
|
3735
|
+
<span class="Comment">#! ))) dot</span>
|
3736
|
+
<span class="Statement">lambda</span> { <span class="Type">Codnar</span>::<span class="Type">GraphViz</span>.to_html(diagram) }.should.raise
|
3613
3737
|
end
|
3614
3738
|
|
3615
3739
|
end
|
@@ -3623,8 +3747,8 @@ And here is the implementation:
|
|
3623
3747
|
<p>
|
3624
3748
|
<div class="named_with_containers chunk">
|
3625
3749
|
<div class="chunk name">
|
3626
|
-
<a name="lib-codnar-
|
3627
|
-
<span>lib/codnar/
|
3750
|
+
<a name="lib-codnar-graphviz-rb">
|
3751
|
+
<span>lib/codnar/graphviz.rb</span>
|
3628
3752
|
</a>
|
3629
3753
|
</div>
|
3630
3754
|
<div class="chunk html">
|
@@ -3640,14 +3764,14 @@ And here is the implementation:
|
|
3640
3764
|
<td class='html'>
|
3641
3765
|
<div class='rdoc comment markup'>
|
3642
3766
|
<p>
|
3643
|
-
|
3767
|
+
Generate diagrams using GraphViz.
|
3644
3768
|
</p>
|
3645
3769
|
</div>
|
3646
3770
|
</td>
|
3647
3771
|
</tr>
|
3648
3772
|
</table>
|
3649
3773
|
<pre class='ruby code syntax'>
|
3650
|
-
<span class="PreProc">class</span> <span class="Type">
|
3774
|
+
<span class="PreProc">class</span> <span class="Type">GraphViz</span>
|
3651
3775
|
|
3652
3776
|
</pre>
|
3653
3777
|
<table class='layout'>
|
@@ -3658,22 +3782,26 @@ Syntax highlight using GVim.
|
|
3658
3782
|
<td class='html'>
|
3659
3783
|
<div class='rdoc comment markup'>
|
3660
3784
|
<p>
|
3661
|
-
Convert a
|
3662
|
-
|
3663
|
-
|
3664
|
-
|
3785
|
+
Convert a string containing a GraphViz diagram into SVG suitable for
|
3786
|
+
embedding into the HTML documentation. We pre-process the diagram using M4
|
3787
|
+
to allow cutting down on the boilerplate (repeating the same styles in many
|
3788
|
+
nodes etc.). This should not be harmful for diagrams that do not use M4
|
3789
|
+
commands.
|
3665
3790
|
</p>
|
3666
3791
|
</div>
|
3667
3792
|
</td>
|
3668
3793
|
</tr>
|
3669
3794
|
</table>
|
3670
3795
|
<pre class='ruby code syntax'>
|
3671
|
-
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">
|
3672
|
-
|
3673
|
-
|
3674
|
-
|
3796
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">to_html</span>(diagram)
|
3797
|
+
stdin, stdout, stderr = <span class="Type">Open3</span>.popen3(<span class="Special">"</span><span class="Constant">m4 | dot -Tsvg</span><span class="Special">"</span>)
|
3798
|
+
write_diagram(stdin, diagram)
|
3799
|
+
check_for_errors(stderr)
|
3800
|
+
<span class="Statement">return</span> clean_output(stdout)
|
3675
3801
|
<span class="PreProc">end</span>
|
3676
3802
|
|
3803
|
+
<span class="Statement">protected</span>
|
3804
|
+
|
3677
3805
|
</pre>
|
3678
3806
|
<table class='layout'>
|
3679
3807
|
<tr>
|
@@ -3683,17 +3811,17 @@ details).
|
|
3683
3811
|
<td class='html'>
|
3684
3812
|
<div class='rdoc comment markup'>
|
3685
3813
|
<p>
|
3686
|
-
|
3687
|
-
HTML.
|
3814
|
+
Send the diagram to the commands pipe.
|
3688
3815
|
</p>
|
3689
3816
|
</div>
|
3690
3817
|
</td>
|
3691
3818
|
</tr>
|
3692
3819
|
</table>
|
3693
3820
|
<pre class='ruby code syntax'>
|
3694
|
-
<span class="
|
3695
|
-
|
3696
|
-
|
3821
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">write_diagram</span>(stdin, diagram)
|
3822
|
+
stdin.write(diagram)
|
3823
|
+
stdin.close
|
3824
|
+
<span class="PreProc">end</span>
|
3697
3825
|
|
3698
3826
|
</pre>
|
3699
3827
|
<table class='layout'>
|
@@ -3704,16 +3832,17 @@ HTML.
|
|
3704
3832
|
<td class='html'>
|
3705
3833
|
<div class='rdoc comment markup'>
|
3706
3834
|
<p>
|
3707
|
-
|
3708
|
-
|
3835
|
+
Ensure we got no processing errors from either m4 or dot. If we did, raise
|
3836
|
+
them, and they will be handled by the formatter wrapping code.
|
3709
3837
|
</p>
|
3710
3838
|
</div>
|
3711
3839
|
</td>
|
3712
3840
|
</tr>
|
3713
3841
|
</table>
|
3714
3842
|
<pre class='ruby code syntax'>
|
3715
|
-
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">
|
3716
|
-
|
3843
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">check_for_errors</span>(stderr)
|
3844
|
+
errors = stderr.read
|
3845
|
+
<span class="Statement">raise</span> errors.sub(<span class="Special">/</span><span class="Constant">Error: <stdin>:</span><span class="Special">\d</span><span class="Special">+</span><span class="Constant">: </span><span class="Special">/</span>, <span class="Special">""</span>) <span class="Statement">if</span> errors != <span class="Special">""</span>
|
3717
3846
|
<span class="PreProc">end</span>
|
3718
3847
|
|
3719
3848
|
</pre>
|
@@ -3725,55 +3854,275 @@ version exists.
|
|
3725
3854
|
<td class='html'>
|
3726
3855
|
<div class='rdoc comment markup'>
|
3727
3856
|
<p>
|
3728
|
-
|
3729
|
-
classes to mark keywords, identifiers, and so on. See the GVim
|
3730
|
-
documentation for details. The commands array allows configuring the way
|
3731
|
-
that GVim will format the output. For example:
|
3732
|
-
</p>
|
3733
|
-
<ul><li>
|
3734
|
-
<p>
|
3735
|
-
The command <tt>"+:colorscheme <name>"</tt> will override
|
3736
|
-
the default color scheme used.
|
3737
|
-
</p>
|
3738
|
-
</li><li>
|
3739
|
-
<p>
|
3740
|
-
The command <tt>"+:let html_use_css=1"</tt> will just annotate
|
3741
|
-
each HTML tag with a CSS class, instead of embedding some specific style
|
3742
|
-
directly into the tag. In this case the colorscheme and background are
|
3743
|
-
ignored; you will need to provide your own CSS stylesheet as part of the
|
3744
|
-
final woven document to style the marked-up words.
|
3745
|
-
</p>
|
3746
|
-
</li></ul>
|
3747
|
-
<p>
|
3748
|
-
Additional commands may be useful; GVim provides a full scripting
|
3749
|
-
environment so there is no theoretical limit to what can be done here.
|
3750
|
-
</p>
|
3751
|
-
<p>
|
3752
|
-
Since GVim is as slow as molasses to start up, we cache the results of
|
3753
|
-
highlighting the syntax of each code fragment in a directory called
|
3754
|
-
<tt>.gvim-cache</tt>, which can appear at the current working directory or
|
3755
|
-
in any of its parents.
|
3857
|
+
Clean the SVG we got to make it suitable for embedding in HTML.
|
3756
3858
|
</p>
|
3757
3859
|
</div>
|
3758
3860
|
</td>
|
3759
3861
|
</tr>
|
3760
3862
|
</table>
|
3761
3863
|
<pre class='ruby code syntax'>
|
3762
|
-
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">
|
3763
|
-
|
3764
|
-
<span class="Statement">return</span> <span class="Identifier">@cache</span>[data]
|
3864
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">clean_output</span>(stdout)
|
3865
|
+
<span class="Statement">return</span> stdout.read.sub(<span class="Special">/</span><span class="Special">.</span><span class="Special">*</span><span class="Constant"><svg</span><span class="Special">/m</span>, <span class="Special">"</span><span class="Constant"><svg</span><span class="Special">"</span>).gsub(<span class="Special">/</span><span class="Special">\r</span><span class="Special">/</span>, <span class="Special">""</span>)
|
3765
3866
|
<span class="PreProc">end</span>
|
3766
3867
|
|
3868
|
+
end
|
3869
|
+
|
3870
|
+
end
|
3767
3871
|
</pre>
|
3768
|
-
|
3769
|
-
|
3770
|
-
|
3771
|
-
<
|
3772
|
-
</td>
|
3773
|
-
<td class='html'>
|
3774
|
-
<div class='rdoc comment markup'>
|
3872
|
+
</div>
|
3873
|
+
</div>
|
3874
|
+
</p>
|
3875
|
+
<h4>Syntax highlighting using GVIM</h4>
|
3775
3876
|
<p>
|
3776
|
-
|
3877
|
+
If you have GVim istalled, it is possible to use it to generate syntax
|
3878
|
+
highlighting. This is a <em>slow</em> operation, as GVim was never meant to be used as
|
3879
|
+
a command-line tool. However, what it lacks in speed it compensates for in
|
3880
|
+
scope; almost any language you can think of has a GVim syntax highlighting
|
3881
|
+
definition. Here is a simple test that demonstrates using GVim for syntax
|
3882
|
+
highlighting:
|
3883
|
+
</p>
|
3884
|
+
<p>
|
3885
|
+
<div class="named_with_containers chunk">
|
3886
|
+
<div class="chunk name">
|
3887
|
+
<a name="test-gvim-highlight-syntax-rb">
|
3888
|
+
<span>test/gvim_highlight_syntax.rb</span>
|
3889
|
+
</a>
|
3890
|
+
</div>
|
3891
|
+
<div class="chunk html">
|
3892
|
+
<pre class='ruby code syntax'>
|
3893
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar</span><span class="Special">"</span>
|
3894
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">test/spec</span><span class="Special">"</span>
|
3895
|
+
|
3896
|
+
</pre>
|
3897
|
+
<table class='layout'>
|
3898
|
+
<tr>
|
3899
|
+
<td class='indentation'>
|
3900
|
+
<pre></pre>
|
3901
|
+
</td>
|
3902
|
+
<td class='html'>
|
3903
|
+
<div class='rdoc comment markup'>
|
3904
|
+
<p>
|
3905
|
+
Test highlighting syntax using GVim.
|
3906
|
+
</p>
|
3907
|
+
</div>
|
3908
|
+
</td>
|
3909
|
+
</tr>
|
3910
|
+
</table>
|
3911
|
+
<pre class='ruby code syntax'>
|
3912
|
+
<span class="PreProc">class</span> <span class="Type">TestGVimHighlightSyntax</span> < <span class="Type">Test</span>::<span class="Type">Unit</span>::<span class="Type">TestCase</span>
|
3913
|
+
|
3914
|
+
<span class="PreProc">def</span> <span class="Identifier">setup</span>
|
3915
|
+
<span class="Type">Codnar</span>::<span class="Type">GVim</span>.force_recompute = <span class="Constant">true</span>
|
3916
|
+
<span class="PreProc">end</span>
|
3917
|
+
|
3918
|
+
<span class="PreProc">def</span> <span class="Identifier">teardown</span>
|
3919
|
+
<span class="Type">Codnar</span>::<span class="Type">GVim</span>.force_recompute = <span class="Constant">false</span>
|
3920
|
+
<span class="PreProc">end</span>
|
3921
|
+
|
3922
|
+
<span class="PreProc">def</span> <span class="Identifier">test_ruby_no_css</span>
|
3923
|
+
ruby = <<-<span class="Special">EOF</span>.unindent
|
3924
|
+
<span class="Constant"> def foo</span>
|
3925
|
+
<span class="Constant"> return bar = baz</span>
|
3926
|
+
<span class="Constant"> end</span>
|
3927
|
+
<span class="Constant"> </span><span class="Special">EOF</span>
|
3928
|
+
<span class="Type">Codnar</span>::<span class="Type">GVim</span>.cached_syntax_to_html(ruby, <span class="Special">"</span><span class="Constant">ruby</span><span class="Special">"</span>).should == <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( html</span>
|
3929
|
+
</pre>
|
3930
|
+
<pre class='html code syntax'>
|
3931
|
+
<span class="Identifier"><</span><span class="Statement">div</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'ruby code syntax'</span><span class="Identifier"> </span><span class="Type">bgcolor</span><span class="Identifier">=</span><span class="Constant">"#ffffff"</span><span class="Identifier"> </span><span class="Type">text</span><span class="Identifier">=</span><span class="Constant">"#000000"</span><span class="Identifier">></span>
|
3932
|
+
<span class="Identifier"><</span><span class="Statement">font</span><span class="Identifier"> </span><span class="Type">face</span><span class="Identifier">=</span><span class="Constant">"monospace"</span><span class="Identifier">></span>
|
3933
|
+
<span class="Identifier"><</span><span class="Statement">font</span><span class="Identifier"> </span><span class="Type">color</span><span class="Identifier">=</span><span class="Constant">"#ff40ff"</span><span class="Identifier">></span>def<span class="Identifier"></</span><span class="Statement">font</span><span class="Identifier">></span><span class="Special">&nbsp;</span><span class="Identifier"><</span><span class="Statement">font</span><span class="Identifier"> </span><span class="Type">color</span><span class="Identifier">=</span><span class="Constant">"#00ffff"</span><span class="Identifier">></span>foo<span class="Identifier"></</span><span class="Statement">font</span><span class="Identifier">></span><span class="Identifier"><</span><span class="Statement">br</span><span class="Identifier"> /></span>
|
3934
|
+
<span class="Special">&nbsp;&nbsp;</span><span class="Identifier"><</span><span class="Statement">font</span><span class="Identifier"> </span><span class="Type">color</span><span class="Identifier">=</span><span class="Constant">"#ffff00"</span><span class="Identifier">></span>return<span class="Identifier"></</span><span class="Statement">font</span><span class="Identifier">></span><span class="Special">&nbsp;</span>bar = baz<span class="Identifier"><</span><span class="Statement">br</span><span class="Identifier"> /></span>
|
3935
|
+
<span class="Identifier"><</span><span class="Statement">font</span><span class="Identifier"> </span><span class="Type">color</span><span class="Identifier">=</span><span class="Constant">"#ff40ff"</span><span class="Identifier">></span>end<span class="Identifier"></</span><span class="Statement">font</span><span class="Identifier">></span><span class="Identifier"><</span><span class="Statement">br</span><span class="Identifier"> /></span>
|
3936
|
+
<span class="Identifier"></</span><span class="Statement">font</span><span class="Identifier">></span>
|
3937
|
+
<span class="Identifier"></</span><span class="Statement">div</span><span class="Identifier">></span>
|
3938
|
+
EOF
|
3939
|
+
</pre>
|
3940
|
+
<pre class='ruby code syntax'>
|
3941
|
+
<span class="Comment">#! ))) html</span>
|
3942
|
+
end
|
3943
|
+
|
3944
|
+
<span class="PreProc">def</span> <span class="Identifier">test_ruby_css</span>
|
3945
|
+
ruby = <<-<span class="Special">EOF</span>.unindent
|
3946
|
+
<span class="Constant"> def foo</span>
|
3947
|
+
<span class="Constant"> return bar = baz</span>
|
3948
|
+
<span class="Constant"> end</span>
|
3949
|
+
<span class="Constant"> </span><span class="Special">EOF</span>
|
3950
|
+
<span class="Type">Codnar</span>::<span class="Type">GVim</span>.cached_syntax_to_html(ruby, <span class="Special">"</span><span class="Constant">ruby</span><span class="Special">"</span>, [ <span class="Special">"</span><span class="Constant">+:let html_use_css=1</span><span class="Special">"</span> ]).should == <<-<span class="Special">EOF</span>.unindent <span class="Comment">#! ((( html</span>
|
3951
|
+
</pre>
|
3952
|
+
<pre class='html code syntax'>
|
3953
|
+
<span class="Identifier"><</span><span class="Statement">pre</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'ruby code syntax'</span><span class="Identifier">></span>
|
3954
|
+
<span class="Identifier"><</span><span class="Statement">span</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">"PreProc"</span><span class="Identifier">></span>def<span class="Identifier"></</span><span class="Statement">span</span><span class="Identifier">></span> <span class="Identifier"><</span><span class="Statement">span</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">"Identifier"</span><span class="Identifier">></span>foo<span class="Identifier"></</span><span class="Statement">span</span><span class="Identifier">></span>
|
3955
|
+
<span class="Identifier"><</span><span class="Statement">span</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">"Statement"</span><span class="Identifier">></span>return<span class="Identifier"></</span><span class="Statement">span</span><span class="Identifier">></span> bar = baz
|
3956
|
+
<span class="Identifier"><</span><span class="Statement">span</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">"PreProc"</span><span class="Identifier">></span>end<span class="Identifier"></</span><span class="Statement">span</span><span class="Identifier">></span>
|
3957
|
+
<span class="Identifier"></</span><span class="Statement">pre</span><span class="Identifier">></span>
|
3958
|
+
EOF
|
3959
|
+
</pre>
|
3960
|
+
<pre class='ruby code syntax'>
|
3961
|
+
<span class="Comment">#! ))) html</span>
|
3962
|
+
end
|
3963
|
+
|
3964
|
+
end
|
3965
|
+
</pre>
|
3966
|
+
</div>
|
3967
|
+
</div>
|
3968
|
+
</p>
|
3969
|
+
<p>
|
3970
|
+
And here is the implementation:
|
3971
|
+
</p>
|
3972
|
+
<p>
|
3973
|
+
<div class="named_with_containers chunk">
|
3974
|
+
<div class="chunk name">
|
3975
|
+
<a name="lib-codnar-gvim-rb">
|
3976
|
+
<span>lib/codnar/gvim.rb</span>
|
3977
|
+
</a>
|
3978
|
+
</div>
|
3979
|
+
<div class="chunk html">
|
3980
|
+
<pre class='ruby code syntax'>
|
3981
|
+
<span class="PreProc">module</span> <span class="Type">Codnar</span>
|
3982
|
+
|
3983
|
+
</pre>
|
3984
|
+
<table class='layout'>
|
3985
|
+
<tr>
|
3986
|
+
<td class='indentation'>
|
3987
|
+
<pre> </pre>
|
3988
|
+
</td>
|
3989
|
+
<td class='html'>
|
3990
|
+
<div class='rdoc comment markup'>
|
3991
|
+
<p>
|
3992
|
+
Syntax highlight using GVim.
|
3993
|
+
</p>
|
3994
|
+
</div>
|
3995
|
+
</td>
|
3996
|
+
</tr>
|
3997
|
+
</table>
|
3998
|
+
<pre class='ruby code syntax'>
|
3999
|
+
<span class="PreProc">class</span> <span class="Type">GVim</span>
|
4000
|
+
|
4001
|
+
</pre>
|
4002
|
+
<table class='layout'>
|
4003
|
+
<tr>
|
4004
|
+
<td class='indentation'>
|
4005
|
+
<pre> </pre>
|
4006
|
+
</td>
|
4007
|
+
<td class='html'>
|
4008
|
+
<div class='rdoc comment markup'>
|
4009
|
+
<p>
|
4010
|
+
Convert a sequence of classified code lines to HTML using GVim syntax
|
4011
|
+
highlighting. The commands array allows configuring the way that GVim will
|
4012
|
+
format the output (see the <tt>cached_syntax_to_html</tt> method for
|
4013
|
+
details).
|
4014
|
+
</p>
|
4015
|
+
</div>
|
4016
|
+
</td>
|
4017
|
+
</tr>
|
4018
|
+
</table>
|
4019
|
+
<pre class='ruby code syntax'>
|
4020
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">lines_to_html</span>(lines, syntax, commands = [])
|
4021
|
+
<span class="Statement">return</span> <span class="Type">Formatter</span>.merge_lines(lines, <span class="Special">"</span><span class="Constant">html</span><span class="Special">"</span>) <span class="Statement">do</span> |<span class="Identifier">payload</span>|
|
4022
|
+
<span class="Type">GVim</span>.cached_syntax_to_html(payload + <span class="Special">"</span><span class="Special">\n</span><span class="Special">"</span>, syntax, commands).chomp
|
4023
|
+
<span class="Statement">end</span>
|
4024
|
+
<span class="PreProc">end</span>
|
4025
|
+
|
4026
|
+
</pre>
|
4027
|
+
<table class='layout'>
|
4028
|
+
<tr>
|
4029
|
+
<td class='indentation'>
|
4030
|
+
<pre> </pre>
|
4031
|
+
</td>
|
4032
|
+
<td class='html'>
|
4033
|
+
<div class='rdoc comment markup'>
|
4034
|
+
<p>
|
4035
|
+
The cache used for speeding up recomputing the same syntax highlighting
|
4036
|
+
HTML.
|
4037
|
+
</p>
|
4038
|
+
</div>
|
4039
|
+
</td>
|
4040
|
+
</tr>
|
4041
|
+
</table>
|
4042
|
+
<pre class='ruby code syntax'>
|
4043
|
+
<span class="Identifier">@cache</span> = <span class="Type">Cache</span>.new(<span class="Special">"</span><span class="Constant">.gvim-cache</span><span class="Special">"</span>) <span class="Statement">do</span> |<span class="Identifier">data</span>|
|
4044
|
+
<span class="Type">GVim</span>.uncached_syntax_to_html(data.text, data.syntax, data.commands)
|
4045
|
+
<span class="Statement">end</span>
|
4046
|
+
|
4047
|
+
</pre>
|
4048
|
+
<table class='layout'>
|
4049
|
+
<tr>
|
4050
|
+
<td class='indentation'>
|
4051
|
+
<pre> </pre>
|
4052
|
+
</td>
|
4053
|
+
<td class='html'>
|
4054
|
+
<div class='rdoc comment markup'>
|
4055
|
+
<p>
|
4056
|
+
Force recomputation of the syntax highlighting HTML, even if a cached
|
4057
|
+
version exists.
|
4058
|
+
</p>
|
4059
|
+
</div>
|
4060
|
+
</td>
|
4061
|
+
</tr>
|
4062
|
+
</table>
|
4063
|
+
<pre class='ruby code syntax'>
|
4064
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">force_recompute=</span>(force_recompute)
|
4065
|
+
<span class="Identifier">@cache</span>.force_recompute = force_recompute
|
4066
|
+
<span class="PreProc">end</span>
|
4067
|
+
|
4068
|
+
</pre>
|
4069
|
+
<table class='layout'>
|
4070
|
+
<tr>
|
4071
|
+
<td class='indentation'>
|
4072
|
+
<pre> </pre>
|
4073
|
+
</td>
|
4074
|
+
<td class='html'>
|
4075
|
+
<div class='rdoc comment markup'>
|
4076
|
+
<p>
|
4077
|
+
Highlight syntax of text using GVim. This uses the GVim standard CSS
|
4078
|
+
classes to mark keywords, identifiers, and so on. See the GVim
|
4079
|
+
documentation for details. The commands array allows configuring the way
|
4080
|
+
that GVim will format the output. For example:
|
4081
|
+
</p>
|
4082
|
+
<ul><li>
|
4083
|
+
<p>
|
4084
|
+
The command <tt>"+:colorscheme <name>"</tt> will override
|
4085
|
+
the default color scheme used.
|
4086
|
+
</p>
|
4087
|
+
</li><li>
|
4088
|
+
<p>
|
4089
|
+
The command <tt>"+:let html_use_css=1"</tt> will just annotate
|
4090
|
+
each HTML tag with a CSS class, instead of embedding some specific style
|
4091
|
+
directly into the tag. In this case the colorscheme and background are
|
4092
|
+
ignored; you will need to provide your own CSS stylesheet as part of the
|
4093
|
+
final woven document to style the marked-up words.
|
4094
|
+
</p>
|
4095
|
+
</li></ul>
|
4096
|
+
<p>
|
4097
|
+
Additional commands may be useful; GVim provides a full scripting
|
4098
|
+
environment so there is no theoretical limit to what can be done here.
|
4099
|
+
</p>
|
4100
|
+
<p>
|
4101
|
+
Since GVim is as slow as molasses to start up, we cache the results of
|
4102
|
+
highlighting the syntax of each code fragment in a directory called
|
4103
|
+
<tt>.gvim-cache</tt>, which can appear at the current working directory or
|
4104
|
+
in any of its parents.
|
4105
|
+
</p>
|
4106
|
+
</div>
|
4107
|
+
</td>
|
4108
|
+
</tr>
|
4109
|
+
</table>
|
4110
|
+
<pre class='ruby code syntax'>
|
4111
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">cached_syntax_to_html</span>(text, syntax, commands = [])
|
4112
|
+
data = { <span class="Special">"</span><span class="Constant">text</span><span class="Special">"</span> => text, <span class="Special">"</span><span class="Constant">syntax</span><span class="Special">"</span> => syntax, <span class="Special">"</span><span class="Constant">commands</span><span class="Special">"</span> => commands }
|
4113
|
+
<span class="Statement">return</span> <span class="Identifier">@cache</span>[data]
|
4114
|
+
<span class="PreProc">end</span>
|
4115
|
+
|
4116
|
+
</pre>
|
4117
|
+
<table class='layout'>
|
4118
|
+
<tr>
|
4119
|
+
<td class='indentation'>
|
4120
|
+
<pre> </pre>
|
4121
|
+
</td>
|
4122
|
+
<td class='html'>
|
4123
|
+
<div class='rdoc comment markup'>
|
4124
|
+
<p>
|
4125
|
+
Highlight syntax of text using GVim, without caching. This is <b>slow</b>
|
3777
4126
|
(measured in seconds), due to GVim’s start-up tim. See the
|
3778
4127
|
<tt>cached_syntax_to_html</tt> method for a faster variant and
|
3779
4128
|
functionality details.
|
@@ -4619,7 +4968,7 @@ Test splitting code files.
|
|
4619
4968
|
<span class="Identifier"><</span><span class="Statement">td</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'html'</span><span class="Identifier">></span>
|
4620
4969
|
<span class="Identifier"><</span><span class="Statement">div</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'rdoc rdoc markup'</span><span class="Identifier">></span>
|
4621
4970
|
<span class="Identifier"><</span><span class="Statement">p</span><span class="Identifier">></span>
|
4622
|
-
This is <span class="Identifier"><</span><span class="Statement">
|
4971
|
+
This is <span class="Identifier"><</span><span class="Statement">strong</span><span class="Identifier">></span><span class="htmlBold">rdoc</span><span class="Identifier"></</span><span class="Statement">strong</span><span class="Identifier">></span>.
|
4623
4972
|
<span class="Identifier"></</span><span class="Statement">p</span><span class="Identifier">></span>
|
4624
4973
|
<span class="Identifier"></</span><span class="Statement">div</span><span class="Identifier">></span>
|
4625
4974
|
<span class="Identifier"></</span><span class="Statement">td</span><span class="Identifier">></span>
|
@@ -4834,7 +5183,7 @@ Test “splitting” documentation files.
|
|
4834
5183
|
<span class="Special">"</span><span class="Constant">containers</span><span class="Special">"</span> => [],
|
4835
5184
|
<span class="Special">"</span><span class="Constant">contained</span><span class="Special">"</span> => [],
|
4836
5185
|
<span class="Special">"</span><span class="Constant">locations</span><span class="Special">"</span> => [ { <span class="Special">"</span><span class="Constant">file</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">rdoc.rdoc</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">line</span><span class="Special">"</span> => <span class="Constant">1</span> } ],
|
4837
|
-
<span class="Special">"</span><span class="Constant">html</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant"><div class='rdoc rdoc markup'></span><span class="Special">\n</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Constant"><
|
5186
|
+
<span class="Special">"</span><span class="Constant">html</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant"><div class='rdoc rdoc markup'></span><span class="Special">\n</span><span class="Constant"><p></span><span class="Special">\n</span><span class="Constant"><strong>foo</strong> bar</span><span class="Special">\n</span><span class="Constant"></p></span><span class="Special">\n</span><span class="Constant"></div></span><span class="Special">"</span>
|
4838
5187
|
} ]
|
4839
5188
|
<span class="PreProc">end</span>
|
4840
5189
|
|
@@ -4939,69 +5288,14 @@ Application.
|
|
4939
5288
|
<pre class='ruby code syntax'>
|
4940
5289
|
<span class="PreProc">module</span> <span class="Type">Configuration</span>
|
4941
5290
|
|
4942
|
-
</
|
4943
|
-
<
|
4944
|
-
<
|
4945
|
-
</
|
4946
|
-
|
5291
|
+
<span class="PreProc">include</span> <span class="Type">Documentation</span>
|
5292
|
+
<span class="PreProc">include</span> <span class="Type">Code</span>
|
5293
|
+
<span class="PreProc">include</span> <span class="Type">Comments</span>
|
5294
|
+
<span class="PreProc">include</span> <span class="Type">Highlighting</span>
|
5295
|
+
|
5296
|
+
<span class="PreProc">end</span>
|
4947
5297
|
|
4948
|
-
|
4949
|
-
<pre class='nested chunk'>
|
4950
|
-
<a class='nested chunk' href='#source-code-lines-classification-configurations'>Source code lines classification configurations</a>
|
4951
|
-
</pre>
|
4952
|
-
<pre class='ruby code syntax'>
|
4953
|
-
|
4954
|
-
</pre>
|
4955
|
-
<pre class='nested chunk'>
|
4956
|
-
<a class='nested chunk' href='#nested-foreign-syntax-code-islands-configurations'>Nested foreign syntax code islands configurations</a>
|
4957
|
-
</pre>
|
4958
|
-
<pre class='ruby code syntax'>
|
4959
|
-
|
4960
|
-
</pre>
|
4961
|
-
<pre class='nested chunk'>
|
4962
|
-
<a class='nested chunk' href='#simple-comment-classification-configurations'>Simple comment classification configurations</a>
|
4963
|
-
</pre>
|
4964
|
-
<pre class='ruby code syntax'>
|
4965
|
-
|
4966
|
-
</pre>
|
4967
|
-
<pre class='nested chunk'>
|
4968
|
-
<a class='nested chunk' href='#complex-comment-classification-configurations'>Complex comment classification configurations</a>
|
4969
|
-
</pre>
|
4970
|
-
<pre class='ruby code syntax'>
|
4971
|
-
|
4972
|
-
</pre>
|
4973
|
-
<pre class='nested chunk'>
|
4974
|
-
<a class='nested chunk' href='#comment-formatting-configurations'>Comment formatting configurations</a>
|
4975
|
-
</pre>
|
4976
|
-
<pre class='ruby code syntax'>
|
4977
|
-
|
4978
|
-
</pre>
|
4979
|
-
<pre class='nested chunk'>
|
4980
|
-
<a class='nested chunk' href='#gvim-syntax-highlighting-formatting-configurations'>GVim syntax highlighting formatting configurations</a>
|
4981
|
-
</pre>
|
4982
|
-
<pre class='ruby code syntax'>
|
4983
|
-
|
4984
|
-
</pre>
|
4985
|
-
<pre class='nested chunk'>
|
4986
|
-
<a class='nested chunk' href='#coderay-syntax-highlighting-formatting-configurations'>CodeRay syntax highlighting formatting configurations</a>
|
4987
|
-
</pre>
|
4988
|
-
<pre class='ruby code syntax'>
|
4989
|
-
|
4990
|
-
</pre>
|
4991
|
-
<pre class='nested chunk'>
|
4992
|
-
<a class='nested chunk' href='#sunlight-syntax-highlighting-formatting-configurations'>Sunlight syntax highlighting formatting configurations</a>
|
4993
|
-
</pre>
|
4994
|
-
<pre class='ruby code syntax'>
|
4995
|
-
|
4996
|
-
</pre>
|
4997
|
-
<pre class='nested chunk'>
|
4998
|
-
<a class='nested chunk' href='#chunk-splitting-configurations'>Chunk splitting configurations</a>
|
4999
|
-
</pre>
|
5000
|
-
<pre class='ruby code syntax'>
|
5001
|
-
|
5002
|
-
end
|
5003
|
-
|
5004
|
-
end
|
5298
|
+
end
|
5005
5299
|
</pre>
|
5006
5300
|
</div>
|
5007
5301
|
</div>
|
@@ -5323,7 +5617,7 @@ Test the built-in split documentation configurations.
|
|
5323
5617
|
<pre class='html code syntax'>
|
5324
5618
|
<span class="Identifier"><</span><span class="Statement">div</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'rdoc doc markup'</span><span class="Identifier">></span>
|
5325
5619
|
<span class="Identifier"><</span><span class="Statement">p</span><span class="Identifier">></span>
|
5326
|
-
This is a <span class="Identifier"><</span><span class="Statement">
|
5620
|
+
This is a <span class="Identifier"><</span><span class="Statement">strong</span><span class="Identifier">></span><span class="htmlBold">marked-up</span><span class="Identifier"></</span><span class="Statement">strong</span><span class="Identifier">></span> file.
|
5327
5621
|
<span class="Identifier"></</span><span class="Statement">p</span><span class="Identifier">></span>
|
5328
5622
|
<span class="Identifier"></</span><span class="Statement">div</span><span class="Identifier">></span>
|
5329
5623
|
EOF
|
@@ -5380,18 +5674,39 @@ And here are the actual configurations:
|
|
5380
5674
|
<p>
|
5381
5675
|
<div class="named_with_containers chunk">
|
5382
5676
|
<div class="chunk name">
|
5383
|
-
<a name="documentation-
|
5384
|
-
<span>
|
5677
|
+
<a name="lib-codnar-configuration-documentation-rb">
|
5678
|
+
<span>lib/codnar/configuration/documentation.rb</span>
|
5385
5679
|
</a>
|
5386
5680
|
</div>
|
5387
5681
|
<div class="chunk html">
|
5388
5682
|
<pre class='ruby code syntax'>
|
5683
|
+
<span class="PreProc">module</span> <span class="Type">Codnar</span>
|
5684
|
+
|
5685
|
+
<span class="PreProc">module</span> <span class="Type">Configuration</span>
|
5389
5686
|
|
5390
5687
|
</pre>
|
5391
|
-
<table class='layout'>
|
5688
|
+
<table class='layout'>
|
5392
5689
|
<tr>
|
5393
5690
|
<td class='indentation'>
|
5394
|
-
<pre
|
5691
|
+
<pre> </pre>
|
5692
|
+
</td>
|
5693
|
+
<td class='html'>
|
5694
|
+
<div class='rdoc comment markup'>
|
5695
|
+
<p>
|
5696
|
+
Configurations for “splitting” documentation files.
|
5697
|
+
</p>
|
5698
|
+
</div>
|
5699
|
+
</td>
|
5700
|
+
</tr>
|
5701
|
+
</table>
|
5702
|
+
<pre class='ruby code syntax'>
|
5703
|
+
<span class="PreProc">module</span> <span class="Type">Documentation</span>
|
5704
|
+
|
5705
|
+
</pre>
|
5706
|
+
<table class='layout'>
|
5707
|
+
<tr>
|
5708
|
+
<td class='indentation'>
|
5709
|
+
<pre> </pre>
|
5395
5710
|
</td>
|
5396
5711
|
<td class='html'>
|
5397
5712
|
<div class='rdoc comment markup'>
|
@@ -5410,25 +5725,25 @@ processing on the input. It isn’t the most useful configuration.
|
|
5410
5725
|
</tr>
|
5411
5726
|
</table>
|
5412
5727
|
<pre class='ruby code syntax'>
|
5413
|
-
<span class="Type">SPLIT_HTML_DOCUMENTATION</span> = {
|
5414
|
-
|
5415
|
-
|
5416
|
-
|
5417
|
-
|
5418
|
-
|
5419
|
-
|
5420
|
-
|
5421
|
-
|
5422
|
-
|
5423
|
-
|
5424
|
-
|
5425
|
-
}
|
5728
|
+
<span class="Type">SPLIT_HTML_DOCUMENTATION</span> = {
|
5729
|
+
<span class="Special">"</span><span class="Constant">formatters</span><span class="Special">"</span> => {
|
5730
|
+
<span class="Special">"</span><span class="Constant">doc</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.cast_lines(lines, 'html')</span><span class="Special">"</span>,
|
5731
|
+
},
|
5732
|
+
<span class="Special">"</span><span class="Constant">syntax</span><span class="Special">"</span> => {
|
5733
|
+
<span class="Special">"</span><span class="Constant">patterns</span><span class="Special">"</span> => {
|
5734
|
+
<span class="Special">"</span><span class="Constant">doc</span><span class="Special">"</span> => { <span class="Special">"</span><span class="Constant">regexp</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">^(.*)$</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">groups</span><span class="Special">"</span> => [ <span class="Special">"</span><span class="Constant">payload</span><span class="Special">"</span> ] },
|
5735
|
+
},
|
5736
|
+
<span class="Special">"</span><span class="Constant">states</span><span class="Special">"</span> => {
|
5737
|
+
<span class="Special">"</span><span class="Constant">start</span><span class="Special">"</span> => { <span class="Special">"</span><span class="Constant">transitions</span><span class="Special">"</span> => [ { <span class="Special">"</span><span class="Constant">pattern</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">doc</span><span class="Special">"</span> } ] },
|
5738
|
+
},
|
5739
|
+
},
|
5740
|
+
}
|
5426
5741
|
|
5427
5742
|
</pre>
|
5428
|
-
<table class='layout'>
|
5743
|
+
<table class='layout'>
|
5429
5744
|
<tr>
|
5430
5745
|
<td class='indentation'>
|
5431
|
-
<pre
|
5746
|
+
<pre> </pre>
|
5432
5747
|
</td>
|
5433
5748
|
<td class='html'>
|
5434
5749
|
<div class='rdoc comment markup'>
|
@@ -5441,17 +5756,17 @@ preserved by escaping it and wrapping it in an HTML pre element.
|
|
5441
5756
|
</tr>
|
5442
5757
|
</table>
|
5443
5758
|
<pre class='ruby code syntax'>
|
5444
|
-
<span class="Type">SPLIT_PRE_DOCUMENTATION</span> = <span class="Type">SPLIT_HTML_DOCUMENTATION</span>.deep_merge(
|
5445
|
-
|
5446
|
-
|
5447
|
-
|
5448
|
-
)
|
5759
|
+
<span class="Type">SPLIT_PRE_DOCUMENTATION</span> = <span class="Type">SPLIT_HTML_DOCUMENTATION</span>.deep_merge(
|
5760
|
+
<span class="Special">"</span><span class="Constant">formatters</span><span class="Special">"</span> => {
|
5761
|
+
<span class="Special">"</span><span class="Constant">doc</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.lines_to_pre_html(lines, :class => :doc)</span><span class="Special">"</span>,
|
5762
|
+
}
|
5763
|
+
)
|
5449
5764
|
|
5450
5765
|
</pre>
|
5451
|
-
<table class='layout'>
|
5766
|
+
<table class='layout'>
|
5452
5767
|
<tr>
|
5453
5768
|
<td class='indentation'>
|
5454
|
-
<pre
|
5769
|
+
<pre> </pre>
|
5455
5770
|
</td>
|
5456
5771
|
<td class='html'>
|
5457
5772
|
<div class='rdoc comment markup'>
|
@@ -5463,18 +5778,18 @@ preserved by escaping it and wrapping it in an HTML pre element.
|
|
5463
5778
|
</tr>
|
5464
5779
|
</table>
|
5465
5780
|
<pre class='ruby code syntax'>
|
5466
|
-
<span class="Type">SPLIT_RDOC_DOCUMENTATION</span> = <span class="Type">SPLIT_HTML_DOCUMENTATION</span>.deep_merge(
|
5467
|
-
|
5468
|
-
|
5469
|
-
|
5470
|
-
|
5471
|
-
)
|
5781
|
+
<span class="Type">SPLIT_RDOC_DOCUMENTATION</span> = <span class="Type">SPLIT_HTML_DOCUMENTATION</span>.deep_merge(
|
5782
|
+
<span class="Special">"</span><span class="Constant">formatters</span><span class="Special">"</span> => {
|
5783
|
+
<span class="Special">"</span><span class="Constant">doc</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.markup_lines_to_html(lines, Codnar::RDoc, 'rdoc')</span><span class="Special">"</span>,
|
5784
|
+
<span class="Special">"</span><span class="Constant">unindented_html</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.unindented_lines_to_html(lines)</span><span class="Special">"</span>,
|
5785
|
+
}
|
5786
|
+
)
|
5472
5787
|
|
5473
5788
|
</pre>
|
5474
|
-
<table class='layout'>
|
5789
|
+
<table class='layout'>
|
5475
5790
|
<tr>
|
5476
5791
|
<td class='indentation'>
|
5477
|
-
<pre
|
5792
|
+
<pre> </pre>
|
5478
5793
|
</td>
|
5479
5794
|
<td class='html'>
|
5480
5795
|
<div class='rdoc comment markup'>
|
@@ -5486,18 +5801,18 @@ preserved by escaping it and wrapping it in an HTML pre element.
|
|
5486
5801
|
</tr>
|
5487
5802
|
</table>
|
5488
5803
|
<pre class='ruby code syntax'>
|
5489
|
-
<span class="Type">SPLIT_MARKDOWN_DOCUMENTATION</span> = <span class="Type">SPLIT_HTML_DOCUMENTATION</span>.deep_merge(
|
5490
|
-
|
5491
|
-
|
5492
|
-
|
5493
|
-
|
5494
|
-
)
|
5804
|
+
<span class="Type">SPLIT_MARKDOWN_DOCUMENTATION</span> = <span class="Type">SPLIT_HTML_DOCUMENTATION</span>.deep_merge(
|
5805
|
+
<span class="Special">"</span><span class="Constant">formatters</span><span class="Special">"</span> => {
|
5806
|
+
<span class="Special">"</span><span class="Constant">doc</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.markup_lines_to_html(lines, Codnar::Markdown, 'markdown')</span><span class="Special">"</span>,
|
5807
|
+
<span class="Special">"</span><span class="Constant">unindented_html</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.unindented_lines_to_html(lines)</span><span class="Special">"</span>,
|
5808
|
+
}
|
5809
|
+
)
|
5495
5810
|
|
5496
5811
|
</pre>
|
5497
|
-
<table class='layout'>
|
5812
|
+
<table class='layout'>
|
5498
5813
|
<tr>
|
5499
5814
|
<td class='indentation'>
|
5500
|
-
<pre
|
5815
|
+
<pre> </pre>
|
5501
5816
|
</td>
|
5502
5817
|
<td class='html'>
|
5503
5818
|
<div class='rdoc comment markup'>
|
@@ -5509,30 +5824,82 @@ preserved by escaping it and wrapping it in an HTML pre element.
|
|
5509
5824
|
</tr>
|
5510
5825
|
</table>
|
5511
5826
|
<pre class='ruby code syntax'>
|
5512
|
-
<span class="Type">SPLIT_GRAPHVIZ_DOCUMENTATION</span> = <span class="Type">SPLIT_HTML_DOCUMENTATION</span>.deep_merge(
|
5513
|
-
|
5514
|
-
|
5515
|
-
|
5516
|
-
|
5517
|
-
)
|
5827
|
+
<span class="Type">SPLIT_GRAPHVIZ_DOCUMENTATION</span> = <span class="Type">SPLIT_HTML_DOCUMENTATION</span>.deep_merge(
|
5828
|
+
<span class="Special">"</span><span class="Constant">formatters</span><span class="Special">"</span> => {
|
5829
|
+
<span class="Special">"</span><span class="Constant">doc</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.markup_lines_to_html(lines, Codnar::GraphViz, 'graphviz')</span><span class="Special">"</span>,
|
5830
|
+
<span class="Special">"</span><span class="Constant">unindented_html</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.unindented_lines_to_html(lines)</span><span class="Special">"</span>,
|
5831
|
+
}
|
5832
|
+
)
|
5833
|
+
|
5834
|
+
end
|
5835
|
+
|
5836
|
+
end
|
5518
5837
|
|
5838
|
+
end
|
5519
5839
|
</pre>
|
5520
5840
|
</div>
|
5521
|
-
<div class="chunk containers">
|
5522
|
-
<span class="chunk containers header">Contained in:</span>
|
5523
|
-
<ul class="chunk containers">
|
5524
|
-
<li class="chunk container">
|
5525
|
-
<a class="chunk container" href="#lib-codnar-split-configurations-rb">lib/codnar/split_configurations.rb</a>
|
5526
|
-
</li>
|
5527
|
-
</ul>
|
5528
|
-
</div>
|
5529
5841
|
</div>
|
5530
5842
|
</p>
|
5531
5843
|
<h4>Source code lines classification</h4>
|
5532
5844
|
<p>
|
5533
5845
|
Splitting source code files is a more complex affair, which does typically
|
5534
|
-
require combining several configurations.
|
5535
|
-
|
5846
|
+
require combining several configurations.
|
5847
|
+
</p>
|
5848
|
+
<p>
|
5849
|
+
<div class="named_with_containers chunk">
|
5850
|
+
<div class="chunk name">
|
5851
|
+
<a name="lib-codnar-configuration-code-rb">
|
5852
|
+
<span>lib/codnar/configuration/code.rb</span>
|
5853
|
+
</a>
|
5854
|
+
</div>
|
5855
|
+
<div class="chunk html">
|
5856
|
+
<pre class='ruby code syntax'>
|
5857
|
+
<span class="PreProc">module</span> <span class="Type">Codnar</span>
|
5858
|
+
|
5859
|
+
<span class="PreProc">module</span> <span class="Type">Configuration</span>
|
5860
|
+
|
5861
|
+
</pre>
|
5862
|
+
<table class='layout'>
|
5863
|
+
<tr>
|
5864
|
+
<td class='indentation'>
|
5865
|
+
<pre> </pre>
|
5866
|
+
</td>
|
5867
|
+
<td class='html'>
|
5868
|
+
<div class='rdoc comment markup'>
|
5869
|
+
<p>
|
5870
|
+
Configurations for splitting source code.
|
5871
|
+
</p>
|
5872
|
+
</div>
|
5873
|
+
</td>
|
5874
|
+
</tr>
|
5875
|
+
</table>
|
5876
|
+
<pre class='ruby code syntax'>
|
5877
|
+
<span class="PreProc">module</span> <span class="Type">Code</span>
|
5878
|
+
|
5879
|
+
</pre>
|
5880
|
+
<pre class='nested chunk'>
|
5881
|
+
<a class='nested chunk' href='#source-code-lines-classification-configurations'>Source code lines classification configurations</a>
|
5882
|
+
</pre>
|
5883
|
+
<pre class='ruby code syntax'>
|
5884
|
+
|
5885
|
+
</pre>
|
5886
|
+
<pre class='nested chunk'>
|
5887
|
+
<a class='nested chunk' href='#nested-foreign-syntax-code-islands-configurations'>Nested foreign syntax code islands configurations</a>
|
5888
|
+
</pre>
|
5889
|
+
<pre class='ruby code syntax'>
|
5890
|
+
|
5891
|
+
end
|
5892
|
+
|
5893
|
+
end
|
5894
|
+
|
5895
|
+
end
|
5896
|
+
</pre>
|
5897
|
+
</div>
|
5898
|
+
</div>
|
5899
|
+
</p>
|
5900
|
+
<p>
|
5901
|
+
The basic configuration marks all lines as belonging to some code syntax, as a
|
5902
|
+
single chunk:
|
5536
5903
|
</p>
|
5537
5904
|
<p>
|
5538
5905
|
<div class="named_with_containers chunk">
|
@@ -5591,7 +5958,7 @@ configuration(s).
|
|
5591
5958
|
<span class="chunk containers header">Contained in:</span>
|
5592
5959
|
<ul class="chunk containers">
|
5593
5960
|
<li class="chunk container">
|
5594
|
-
<a class="chunk container" href="#lib-codnar-
|
5961
|
+
<a class="chunk container" href="#lib-codnar-configuration-code-rb">lib/codnar/configuration/code.rb</a>
|
5595
5962
|
</li>
|
5596
5963
|
</ul>
|
5597
5964
|
</div>
|
@@ -5674,7 +6041,7 @@ nested code may not contain deeper nested code using a third syntax.
|
|
5674
6041
|
<span class="chunk containers header">Contained in:</span>
|
5675
6042
|
<ul class="chunk containers">
|
5676
6043
|
<li class="chunk container">
|
5677
|
-
<a class="chunk container" href="#lib-codnar-
|
6044
|
+
<a class="chunk container" href="#lib-codnar-configuration-code-rb">lib/codnar/configuration/code.rb</a>
|
5678
6045
|
</li>
|
5679
6046
|
</ul>
|
5680
6047
|
</div>
|
@@ -5768,41 +6135,343 @@ Test combinations of the built-in split code configurations.
|
|
5768
6135
|
<span class="Identifier"><</span><span class="Statement">pre</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'ruby code syntax'</span><span class="Identifier">></span>
|
5769
6136
|
</pre>
|
5770
6137
|
<pre class='ruby code syntax'>
|
5771
|
-
<span <span class="PreProc">class</span>="<span class="Type">Comment</span>"><span class="Comment"># ))) html</span></span>
|
5772
|
-
</pre>
|
5773
|
-
<span class="Type">EOF</span>
|
6138
|
+
<span <span class="PreProc">class</span>="<span class="Type">Comment</span>"><span class="Comment"># ))) html</span></span>
|
6139
|
+
</pre>
|
6140
|
+
<span class="Type">EOF</span>
|
6141
|
+
|
6142
|
+
<span class="PreProc">def</span> <span class="Identifier">test_island_code</span>
|
6143
|
+
check_split_file(<span class="Type">ISLAND_CODE</span>, <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_SOURCE_CODE</span>.call(<span class="Special">"</span><span class="Constant">ruby</span><span class="Special">"</span>),
|
6144
|
+
<span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">FORMAT_CODE_GVIM_CSS</span>.call(<span class="Special">"</span><span class="Constant">ruby</span><span class="Special">"</span>),
|
6145
|
+
<span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_NESTED_CODE</span>.call(<span class="Special">"</span><span class="Constant">ruby</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">html</span><span class="Special">"</span>),
|
6146
|
+
<span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">FORMAT_CODE_GVIM_CSS</span>.call(<span class="Special">"</span><span class="Constant">html</span><span class="Special">"</span>)) <span class="Statement">do</span> |<span class="Identifier">path</span>|
|
6147
|
+
[ {
|
6148
|
+
<span class="Special">"</span><span class="Constant">name</span><span class="Special">"</span> => path,
|
6149
|
+
<span class="Special">"</span><span class="Constant">locations</span><span class="Special">"</span> => [ { <span class="Special">"</span><span class="Constant">file</span><span class="Special">"</span> => path, <span class="Special">"</span><span class="Constant">line</span><span class="Special">"</span> => <span class="Constant">1</span> } ],
|
6150
|
+
<span class="Special">"</span><span class="Constant">containers</span><span class="Special">"</span> => [],
|
6151
|
+
<span class="Special">"</span><span class="Constant">contained</span><span class="Special">"</span> => [],
|
6152
|
+
<span class="Special">"</span><span class="Constant">html</span><span class="Special">"</span> => <span class="Type">ISLAND_HTML</span>
|
6153
|
+
} ]
|
6154
|
+
<span class="Statement">end</span>
|
6155
|
+
<span class="PreProc">end</span>
|
6156
|
+
|
6157
|
+
<span class="PreProc">end</span>
|
6158
|
+
</pre>
|
6159
|
+
</div>
|
6160
|
+
</div>
|
6161
|
+
</p>
|
6162
|
+
<h4>Classifying comment lines</h4>
|
6163
|
+
<p>
|
6164
|
+
Classifying comment lines is the most complex part of splitting source code
|
6165
|
+
files, requiring the use of one or more configurations specific to the language
|
6166
|
+
used.
|
6167
|
+
</p>
|
6168
|
+
<p>
|
6169
|
+
<div class="named_with_containers chunk">
|
6170
|
+
<div class="chunk name">
|
6171
|
+
<a name="lib-codnar-configuration-comments-rb">
|
6172
|
+
<span>lib/codnar/configuration/comments.rb</span>
|
6173
|
+
</a>
|
6174
|
+
</div>
|
6175
|
+
<div class="chunk html">
|
6176
|
+
<pre class='ruby code syntax'>
|
6177
|
+
<span class="PreProc">module</span> <span class="Type">Codnar</span>
|
6178
|
+
|
6179
|
+
<span class="PreProc">module</span> <span class="Type">Configuration</span>
|
6180
|
+
|
6181
|
+
</pre>
|
6182
|
+
<table class='layout'>
|
6183
|
+
<tr>
|
6184
|
+
<td class='indentation'>
|
6185
|
+
<pre> </pre>
|
6186
|
+
</td>
|
6187
|
+
<td class='html'>
|
6188
|
+
<div class='rdoc comment markup'>
|
6189
|
+
<p>
|
6190
|
+
Configurations for splitting source code with comments.
|
6191
|
+
</p>
|
6192
|
+
</div>
|
6193
|
+
</td>
|
6194
|
+
</tr>
|
6195
|
+
</table>
|
6196
|
+
<pre class='ruby code syntax'>
|
6197
|
+
<span class="PreProc">module</span> <span class="Type">Comments</span>
|
6198
|
+
|
6199
|
+
</pre>
|
6200
|
+
<pre class='nested chunk'>
|
6201
|
+
<a class='nested chunk' href='#simple-comment-classification-configurations'>Simple comment classification configurations</a>
|
6202
|
+
</pre>
|
6203
|
+
<pre class='ruby code syntax'>
|
6204
|
+
|
6205
|
+
</pre>
|
6206
|
+
<pre class='nested chunk'>
|
6207
|
+
<a class='nested chunk' href='#denoted-comment-classification-configurations'>Denoted comment classification configurations</a>
|
6208
|
+
</pre>
|
6209
|
+
<pre class='ruby code syntax'>
|
6210
|
+
|
6211
|
+
</pre>
|
6212
|
+
<pre class='nested chunk'>
|
6213
|
+
<a class='nested chunk' href='#delimited-comment-classification-configurations'>Delimited comment classification configurations</a>
|
6214
|
+
</pre>
|
6215
|
+
<pre class='ruby code syntax'>
|
6216
|
+
|
6217
|
+
</pre>
|
6218
|
+
<pre class='nested chunk'>
|
6219
|
+
<a class='nested chunk' href='#comment-formatting-configurations'>Comment formatting configurations</a>
|
6220
|
+
</pre>
|
6221
|
+
<pre class='ruby code syntax'>
|
6222
|
+
|
6223
|
+
end
|
6224
|
+
|
6225
|
+
end
|
6226
|
+
|
6227
|
+
end
|
6228
|
+
</pre>
|
6229
|
+
</div>
|
6230
|
+
</div>
|
6231
|
+
</p>
|
6232
|
+
<h5>Simple comment classification</h5>
|
6233
|
+
<p>
|
6234
|
+
Many languages use a simple comment syntax, where some prefix indicates a
|
6235
|
+
comment that spans until the end of the line (e.g., shell <code>#</code> comments or C++
|
6236
|
+
<code>//</code> comments).
|
6237
|
+
</p>
|
6238
|
+
<p>
|
6239
|
+
<div class="named_with_containers chunk">
|
6240
|
+
<div class="chunk name">
|
6241
|
+
<a name="simple-comment-classification-configurations">
|
6242
|
+
<span>Simple comment classification configurations</span>
|
6243
|
+
</a>
|
6244
|
+
</div>
|
6245
|
+
<div class="chunk html">
|
6246
|
+
<pre class='ruby code syntax'>
|
6247
|
+
|
6248
|
+
</pre>
|
6249
|
+
<table class='layout'>
|
6250
|
+
<tr>
|
6251
|
+
<td class='indentation'>
|
6252
|
+
<pre></pre>
|
6253
|
+
</td>
|
6254
|
+
<td class='html'>
|
6255
|
+
<div class='rdoc comment markup'>
|
6256
|
+
<p>
|
6257
|
+
Classify simple comment lines. It accepts a restricted format: each comment
|
6258
|
+
is expected to start with some exact prefix (e.g. “#” for shell style
|
6259
|
+
comments or “//” for C++ style comments). The following space, if any,
|
6260
|
+
is stripped from the payload. As a convenience, comment that starts with
|
6261
|
+
“!” is not taken to start a comment. This both protects the 1st line of
|
6262
|
+
shell scripts (“#!”), and also any other line you wish to avoid being
|
6263
|
+
treated as a comment.
|
6264
|
+
</p>
|
6265
|
+
<p>
|
6266
|
+
This configuration is typically complemented by an additional one
|
6267
|
+
specifying how to format the (stripped!) comments; by default they are just
|
6268
|
+
displayed as-is using an HTML <tt>pre</tt> element, which isn’t very
|
6269
|
+
useful.
|
6270
|
+
</p>
|
6271
|
+
</div>
|
6272
|
+
</td>
|
6273
|
+
</tr>
|
6274
|
+
</table>
|
6275
|
+
<pre class='ruby code syntax'>
|
6276
|
+
<span class="Type">CLASSIFY_SIMPLE_COMMENTS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span> |<span class="Identifier">prefix</span>|
|
6277
|
+
<span class="Statement">return</span> <span class="Type">Comments</span>.simple_comments(prefix)
|
6278
|
+
<span class="Statement">end</span>
|
6279
|
+
|
6280
|
+
</pre>
|
6281
|
+
<table class='layout'>
|
6282
|
+
<tr>
|
6283
|
+
<td class='indentation'>
|
6284
|
+
<pre></pre>
|
6285
|
+
</td>
|
6286
|
+
<td class='html'>
|
6287
|
+
<div class='rdoc comment markup'>
|
6288
|
+
<p>
|
6289
|
+
Classify simple shell (“#”) comment lines.
|
6290
|
+
</p>
|
6291
|
+
</div>
|
6292
|
+
</td>
|
6293
|
+
</tr>
|
6294
|
+
</table>
|
6295
|
+
<pre class='ruby code syntax'>
|
6296
|
+
<span class="Type">CLASSIFY_SHELL_COMMENTS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span>
|
6297
|
+
<span class="Statement">return</span> <span class="Type">Comments</span>.simple_comments(<span class="Special">"</span><span class="Constant">#</span><span class="Special">"</span>)
|
6298
|
+
<span class="Statement">end</span>
|
6299
|
+
|
6300
|
+
</pre>
|
6301
|
+
<table class='layout'>
|
6302
|
+
<tr>
|
6303
|
+
<td class='indentation'>
|
6304
|
+
<pre></pre>
|
6305
|
+
</td>
|
6306
|
+
<td class='html'>
|
6307
|
+
<div class='rdoc comment markup'>
|
6308
|
+
<p>
|
6309
|
+
Classify simple C++ (“//”) comment lines.
|
6310
|
+
</p>
|
6311
|
+
</div>
|
6312
|
+
</td>
|
6313
|
+
</tr>
|
6314
|
+
</table>
|
6315
|
+
<pre class='ruby code syntax'>
|
6316
|
+
<span class="Type">CLASSIFY_CPP_COMMENTS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span>
|
6317
|
+
<span class="Statement">return</span> <span class="Type">Comments</span>.simple_comments(<span class="Special">"</span><span class="Constant">//</span><span class="Special">"</span>)
|
6318
|
+
<span class="Statement">end</span>
|
6319
|
+
|
6320
|
+
</pre>
|
6321
|
+
<table class='layout'>
|
6322
|
+
<tr>
|
6323
|
+
<td class='indentation'>
|
6324
|
+
<pre></pre>
|
6325
|
+
</td>
|
6326
|
+
<td class='html'>
|
6327
|
+
<div class='rdoc comment markup'>
|
6328
|
+
<p>
|
6329
|
+
Configuration for classifying lines to comments and code based on a simple
|
6330
|
+
prefix (e.g. “#” for shell style comments or “//” for C++ style
|
6331
|
+
comments).
|
6332
|
+
</p>
|
6333
|
+
</div>
|
6334
|
+
</td>
|
6335
|
+
</tr>
|
6336
|
+
</table>
|
6337
|
+
<pre class='ruby code syntax'>
|
6338
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">simple_comments</span>(prefix)
|
6339
|
+
<span class="Statement">return</span> {
|
6340
|
+
<span class="Special">"</span><span class="Constant">syntax</span><span class="Special">"</span> => {
|
6341
|
+
<span class="Special">"</span><span class="Constant">patterns</span><span class="Special">"</span> => {
|
6342
|
+
<span class="Special">"</span><span class="Constant">comment_</span><span class="Special">#{</span>prefix<span class="Special">}</span><span class="Special">"</span> => { <span class="Special">"</span><span class="Constant">regexp</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">^(</span><span class="Special">\\</span><span class="Constant">s*)</span><span class="Special">#{</span>prefix<span class="Special">}</span><span class="Constant">(?!!)</span><span class="Special">\\</span><span class="Constant">s?(.*)$</span><span class="Special">"</span> },
|
6343
|
+
},
|
6344
|
+
<span class="Special">"</span><span class="Constant">states</span><span class="Special">"</span> => {
|
6345
|
+
<span class="Special">"</span><span class="Constant">start</span><span class="Special">"</span> => {
|
6346
|
+
<span class="Special">"</span><span class="Constant">transitions</span><span class="Special">"</span> => [
|
6347
|
+
{ <span class="Special">"</span><span class="Constant">pattern</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">comment_</span><span class="Special">#{</span>prefix<span class="Special">}</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">kind</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">comment</span><span class="Special">"</span> },
|
6348
|
+
[]
|
6349
|
+
],
|
6350
|
+
},
|
6351
|
+
},
|
6352
|
+
},
|
6353
|
+
}
|
6354
|
+
<span class="PreProc">end</span>
|
6355
|
+
|
6356
|
+
</pre>
|
6357
|
+
</div>
|
6358
|
+
<div class="chunk containers">
|
6359
|
+
<span class="chunk containers header">Contained in:</span>
|
6360
|
+
<ul class="chunk containers">
|
6361
|
+
<li class="chunk container">
|
6362
|
+
<a class="chunk container" href="#lib-codnar-configuration-comments-rb">lib/codnar/configuration/comments.rb</a>
|
6363
|
+
</li>
|
6364
|
+
</ul>
|
6365
|
+
</div>
|
6366
|
+
</div>
|
6367
|
+
</p>
|
6368
|
+
<p>
|
6369
|
+
Here is a simple test demonstrating using simple comment classifications:
|
6370
|
+
</p>
|
6371
|
+
<p>
|
6372
|
+
<div class="named_with_containers chunk">
|
6373
|
+
<div class="chunk name">
|
6374
|
+
<a name="test-split-simple-comment-configurations-rb">
|
6375
|
+
<span>test/split_simple_comment_configurations.rb</span>
|
6376
|
+
</a>
|
6377
|
+
</div>
|
6378
|
+
<div class="chunk html">
|
6379
|
+
<pre class='ruby code syntax'>
|
6380
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar</span><span class="Special">"</span>
|
6381
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">olag/test</span><span class="Special">"</span>
|
6382
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">test/spec</span><span class="Special">"</span>
|
6383
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">test_with_configurations</span><span class="Special">"</span>
|
6384
|
+
|
6385
|
+
</pre>
|
6386
|
+
<table class='layout'>
|
6387
|
+
<tr>
|
6388
|
+
<td class='indentation'>
|
6389
|
+
<pre></pre>
|
6390
|
+
</td>
|
6391
|
+
<td class='html'>
|
6392
|
+
<div class='rdoc comment markup'>
|
6393
|
+
<p>
|
6394
|
+
Test built-in split simple comment configurations.
|
6395
|
+
</p>
|
6396
|
+
</div>
|
6397
|
+
</td>
|
6398
|
+
</tr>
|
6399
|
+
</table>
|
6400
|
+
<pre class='ruby code syntax'>
|
6401
|
+
<span class="PreProc">class</span> <span class="Type">TestSplitSimpleCommentsConfigurations</span> < <span class="Type">Test</span>::<span class="Type">Unit</span>::<span class="Type">TestCase</span>
|
6402
|
+
|
6403
|
+
<span class="PreProc">include</span> <span class="Type">Test</span>::<span class="Type">WithConfigurations</span>
|
6404
|
+
<span class="PreProc">include</span> <span class="Type">Test</span>::<span class="Type">WithErrors</span>
|
6405
|
+
<span class="PreProc">include</span> <span class="Type">Test</span>::<span class="Type">WithTempfile</span>
|
6406
|
+
|
6407
|
+
<span class="PreProc">def</span> <span class="Identifier">test_custom_comments</span>
|
6408
|
+
check_any_comment(<span class="Special">"</span><span class="Constant">!</span><span class="Special">"</span>, <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_SIMPLE_COMMENTS</span>.call(<span class="Special">"</span><span class="Constant">!</span><span class="Special">"</span>))
|
6409
|
+
<span class="PreProc">end</span>
|
6410
|
+
|
6411
|
+
<span class="PreProc">def</span> <span class="Identifier">test_shell_comments</span>
|
6412
|
+
check_any_comment(<span class="Special">"</span><span class="Constant">#</span><span class="Special">"</span>, <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_SHELL_COMMENTS</span>.call)
|
6413
|
+
<span class="PreProc">end</span>
|
6414
|
+
|
6415
|
+
<span class="PreProc">def</span> <span class="Identifier">test_cpp_comments</span>
|
6416
|
+
check_any_comment(<span class="Special">"</span><span class="Constant">//</span><span class="Special">"</span>, <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_CPP_COMMENTS</span>.call)
|
6417
|
+
<span class="PreProc">end</span>
|
6418
|
+
|
6419
|
+
<span class="Statement">protected</span>
|
6420
|
+
|
6421
|
+
</pre>
|
6422
|
+
<table class='layout'>
|
6423
|
+
<tr>
|
6424
|
+
<td class='indentation'>
|
6425
|
+
<pre> </pre>
|
6426
|
+
</td>
|
6427
|
+
<td class='html'>
|
6428
|
+
<div class='rdoc comment markup'>
|
6429
|
+
<p>
|
6430
|
+
The “?” will be replaced by the simple comment prefix.
|
6431
|
+
</p>
|
6432
|
+
</div>
|
6433
|
+
</td>
|
6434
|
+
</tr>
|
6435
|
+
</table>
|
6436
|
+
<pre class='ruby code syntax'>
|
6437
|
+
<span class="Type">ANY_COMMENT_CODE</span> = <<-<span class="Special">EOF</span>.unindent
|
6438
|
+
<span class="Constant"> ?</span>
|
6439
|
+
<span class="Constant"> ? Comment</span>
|
6440
|
+
<span class="Constant"> Code</span>
|
6441
|
+
<span class="Constant"> ?! Not comment</span>
|
6442
|
+
<span class="Constant"> </span><span class="Special">EOF</span>
|
5774
6443
|
|
5775
|
-
<span class="PreProc">def</span> <span class="Identifier">
|
5776
|
-
check_split_file(<span class="Type">
|
5777
|
-
|
5778
|
-
|
5779
|
-
|
6444
|
+
<span class="PreProc">def</span> <span class="Identifier">check_any_comment</span>(prefix, configuration)
|
6445
|
+
check_split_file(<span class="Type">ANY_COMMENT_CODE</span>.gsub(<span class="Special">"</span><span class="Constant">?</span><span class="Special">"</span>, prefix),
|
6446
|
+
<span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_SOURCE_CODE</span>.call(<span class="Special">"</span><span class="Constant">any</span><span class="Special">"</span>),
|
6447
|
+
<span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">FORMAT_PRE_COMMENTS</span>,
|
6448
|
+
configuration) <span class="Statement">do</span> |<span class="Identifier">path</span>|
|
5780
6449
|
[ {
|
5781
6450
|
<span class="Special">"</span><span class="Constant">name</span><span class="Special">"</span> => path,
|
5782
6451
|
<span class="Special">"</span><span class="Constant">locations</span><span class="Special">"</span> => [ { <span class="Special">"</span><span class="Constant">file</span><span class="Special">"</span> => path, <span class="Special">"</span><span class="Constant">line</span><span class="Special">"</span> => <span class="Constant">1</span> } ],
|
5783
6452
|
<span class="Special">"</span><span class="Constant">containers</span><span class="Special">"</span> => [],
|
5784
6453
|
<span class="Special">"</span><span class="Constant">contained</span><span class="Special">"</span> => [],
|
5785
|
-
<span class="Special">"</span><span class="Constant">html</span><span class="Special">"</span> => <span class="
|
6454
|
+
<span class="Special">"</span><span class="Constant">html</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant"><pre class='comment'></span><span class="Special">\n\n</span><span class="Constant">Comment</span><span class="Special">\n</span><span class="Constant"></pre></span><span class="Special">\n</span><span class="Constant"><pre class='code'></span><span class="Special">\n</span><span class="Constant">Code</span><span class="Special">\n</span><span class="Special">#{</span>prefix<span class="Special">}</span><span class="Constant">! Not comment</span><span class="Special">\n</span><span class="Constant"></pre></span><span class="Special">"</span>
|
5786
6455
|
} ]
|
5787
6456
|
<span class="Statement">end</span>
|
5788
6457
|
<span class="PreProc">end</span>
|
5789
6458
|
|
5790
|
-
|
6459
|
+
end
|
5791
6460
|
</pre>
|
5792
6461
|
</div>
|
5793
6462
|
</div>
|
5794
6463
|
</p>
|
5795
|
-
<
|
6464
|
+
<h5>Denoted comment classification</h5>
|
5796
6465
|
<p>
|
5797
|
-
|
5798
|
-
|
5799
|
-
<code
|
6466
|
+
Sometimes some simple comments require special treatment if they are denoted by
|
6467
|
+
some leading prefix. For example, Haskell simple comments start with <code>--</code> but
|
6468
|
+
Haddock (documentation) comments start with <code>-- |</code>, <code>-- ^</code> etc.
|
5800
6469
|
</p>
|
5801
6470
|
<p>
|
5802
6471
|
<div class="named_with_containers chunk">
|
5803
6472
|
<div class="chunk name">
|
5804
|
-
<a name="
|
5805
|
-
<span>
|
6473
|
+
<a name="denoted-comment-classification-configurations">
|
6474
|
+
<span>Denoted comment classification configurations</span>
|
5806
6475
|
</a>
|
5807
6476
|
</div>
|
5808
6477
|
<div class="chunk html">
|
@@ -5817,13 +6486,11 @@ comment that spans until the end of the line (e.g., shell <code>#</code> comment
|
|
5817
6486
|
<td class='html'>
|
5818
6487
|
<div class='rdoc comment markup'>
|
5819
6488
|
<p>
|
5820
|
-
Classify
|
5821
|
-
|
5822
|
-
|
5823
|
-
|
5824
|
-
|
5825
|
-
shell scripts (“#!”), and also any other line you wish to avoid being
|
5826
|
-
treated as a comment.
|
6489
|
+
Classify denoted comment lines. Denoted comments are similar to simple
|
6490
|
+
comments, except that the 1st simple comment line must start with a
|
6491
|
+
specific prefix (e.g., in haddock, comment lines start with ‘–’ but
|
6492
|
+
haddoc comments start with ‘– |’, ‘– ^’, etc.). The comment
|
6493
|
+
continues in additional simple comment lines.
|
5827
6494
|
</p>
|
5828
6495
|
<p>
|
5829
6496
|
This configuration is typically complemented by an additional one
|
@@ -5836,8 +6503,8 @@ useful.
|
|
5836
6503
|
</tr>
|
5837
6504
|
</table>
|
5838
6505
|
<pre class='ruby code syntax'>
|
5839
|
-
<span class="Type">
|
5840
|
-
<span class="Statement">return</span> <span class="Type">
|
6506
|
+
<span class="Type">CLASSIFY_DENOTED_COMMENTS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span> |<span class="Identifier">start_prefix</span>, <span class="Identifier">continue_prefix</span>|
|
6507
|
+
<span class="Statement">return</span> <span class="Type">Comments</span>.denoted_comments(start_prefix, continue_prefix)
|
5841
6508
|
<span class="Statement">end</span>
|
5842
6509
|
|
5843
6510
|
</pre>
|
@@ -5849,15 +6516,17 @@ useful.
|
|
5849
6516
|
<td class='html'>
|
5850
6517
|
<div class='rdoc comment markup'>
|
5851
6518
|
<p>
|
5852
|
-
Classify
|
6519
|
+
Classify denoted haddock (“–”) comment lines. Note that non-haddock
|
6520
|
+
comment lines are not captured; they would treated as code and handled by
|
6521
|
+
syntax highlighting, if any.
|
5853
6522
|
</p>
|
5854
6523
|
</div>
|
5855
6524
|
</td>
|
5856
6525
|
</tr>
|
5857
6526
|
</table>
|
5858
6527
|
<pre class='ruby code syntax'>
|
5859
|
-
<span class="Type">
|
5860
|
-
<span class="Statement">return</span> <span class="Type">
|
6528
|
+
<span class="Type">CLASSIFY_HADDOCK_COMMENTS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span>
|
6529
|
+
<span class="Statement">return</span> <span class="Type">Comments</span>.denoted_comments(<span class="Special">"</span><span class="Constant">-- [|^$]</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">--</span><span class="Special">"</span>)
|
5861
6530
|
<span class="Statement">end</span>
|
5862
6531
|
|
5863
6532
|
</pre>
|
@@ -5869,52 +6538,58 @@ Classify simple shell (“#”) comment lines.
|
|
5869
6538
|
<td class='html'>
|
5870
6539
|
<div class='rdoc comment markup'>
|
5871
6540
|
<p>
|
5872
|
-
|
6541
|
+
Configuration for classifying lines to comments and code based on a start
|
6542
|
+
comment prefix and continuation comment prefix (e.g., “– |” and
|
6543
|
+
“–” for haddock).
|
5873
6544
|
</p>
|
5874
6545
|
</div>
|
5875
6546
|
</td>
|
5876
6547
|
</tr>
|
5877
6548
|
</table>
|
5878
6549
|
<pre class='ruby code syntax'>
|
5879
|
-
<span class="
|
5880
|
-
<span class="Statement">return</span> <span class="Type">Configuration</span>.simple_comments(<span class="Special">"</span><span class="Constant">//</span><span class="Special">"</span>)
|
5881
|
-
<span class="Statement">end</span>
|
5882
|
-
|
6550
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">denoted_comments</span>(start_prefix, continue_prefix)
|
5883
6551
|
</pre>
|
5884
|
-
<table class='layout'>
|
6552
|
+
<table class='layout'>
|
5885
6553
|
<tr>
|
5886
6554
|
<td class='indentation'>
|
5887
|
-
<pre
|
6555
|
+
<pre> </pre>
|
5888
6556
|
</td>
|
5889
6557
|
<td class='html'>
|
5890
6558
|
<div class='rdoc comment markup'>
|
5891
6559
|
<p>
|
5892
|
-
|
5893
|
-
prefix (e.g. “#” for shell style comments or “//” for C++ style
|
5894
|
-
comments).
|
6560
|
+
Ruby coverage somehow barfs if we inline this. Go figure.
|
5895
6561
|
</p>
|
5896
6562
|
</div>
|
5897
6563
|
</td>
|
5898
6564
|
</tr>
|
5899
6565
|
</table>
|
5900
6566
|
<pre class='ruby code syntax'>
|
5901
|
-
|
6567
|
+
start_transition = {
|
6568
|
+
<span class="Special">"</span><span class="Constant">pattern</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">comment_start_</span><span class="Special">#{</span>start_prefix<span class="Special">}</span><span class="Special">"</span>,
|
6569
|
+
<span class="Special">"</span><span class="Constant">next_state</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">comment_continue_</span><span class="Special">#{</span>continue_prefix<span class="Special">}</span><span class="Special">"</span>,
|
6570
|
+
<span class="Special">"</span><span class="Constant">kind</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">comment</span><span class="Special">"</span>
|
6571
|
+
}
|
5902
6572
|
<span class="Statement">return</span> {
|
5903
6573
|
<span class="Special">"</span><span class="Constant">syntax</span><span class="Special">"</span> => {
|
5904
6574
|
<span class="Special">"</span><span class="Constant">patterns</span><span class="Special">"</span> => {
|
5905
|
-
<span class="Special">"</span><span class="Constant">
|
6575
|
+
<span class="Special">"</span><span class="Constant">comment_start_</span><span class="Special">#{</span>start_prefix<span class="Special">}</span><span class="Special">"</span> => { <span class="Special">"</span><span class="Constant">regexp</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">^(</span><span class="Special">\\</span><span class="Constant">s*)</span><span class="Special">#{</span>start_prefix<span class="Special">}</span><span class="Special">\\</span><span class="Constant">s?(.*)$</span><span class="Special">"</span> },
|
6576
|
+
<span class="Special">"</span><span class="Constant">comment_continue_</span><span class="Special">#{</span>continue_prefix<span class="Special">}</span><span class="Special">"</span> => { <span class="Special">"</span><span class="Constant">regexp</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">^(</span><span class="Special">\\</span><span class="Constant">s*)</span><span class="Special">#{</span>continue_prefix<span class="Special">}</span><span class="Special">\\</span><span class="Constant">s?(.*)$</span><span class="Special">"</span> },
|
5906
6577
|
},
|
5907
6578
|
<span class="Special">"</span><span class="Constant">states</span><span class="Special">"</span> => {
|
5908
6579
|
<span class="Special">"</span><span class="Constant">start</span><span class="Special">"</span> => {
|
5909
|
-
<span class="Special">"</span><span class="Constant">transitions</span><span class="Special">"</span> => [
|
5910
|
-
|
5911
|
-
|
6580
|
+
<span class="Special">"</span><span class="Constant">transitions</span><span class="Special">"</span> => [ start_transition, [] ],
|
6581
|
+
},
|
6582
|
+
<span class="Special">"</span><span class="Constant">comment_continue_</span><span class="Special">#{</span>continue_prefix<span class="Special">}</span><span class="Special">"</span> => {
|
6583
|
+
<span class="Special">"</span><span class="Constant">transitions</span><span class="Special">"</span> => [ {
|
6584
|
+
<span class="Special">"</span><span class="Constant">pattern</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">comment_continue_</span><span class="Special">#{</span>continue_prefix<span class="Special">}</span><span class="Special">"</span>,
|
6585
|
+
<span class="Special">"</span><span class="Constant">kind</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">comment</span><span class="Special">"</span> },
|
6586
|
+
{ <span class="Special">"</span><span class="Constant">next_state</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">start</span><span class="Special">"</span> }
|
5912
6587
|
],
|
5913
6588
|
},
|
5914
6589
|
},
|
5915
6590
|
},
|
5916
6591
|
}
|
5917
|
-
|
6592
|
+
end
|
5918
6593
|
|
5919
6594
|
</pre>
|
5920
6595
|
</div>
|
@@ -5922,20 +6597,20 @@ comments).
|
|
5922
6597
|
<span class="chunk containers header">Contained in:</span>
|
5923
6598
|
<ul class="chunk containers">
|
5924
6599
|
<li class="chunk container">
|
5925
|
-
<a class="chunk container" href="#lib-codnar-
|
6600
|
+
<a class="chunk container" href="#lib-codnar-configuration-comments-rb">lib/codnar/configuration/comments.rb</a>
|
5926
6601
|
</li>
|
5927
6602
|
</ul>
|
5928
6603
|
</div>
|
5929
6604
|
</div>
|
5930
6605
|
</p>
|
5931
6606
|
<p>
|
5932
|
-
Here is a simple test demonstrating using
|
6607
|
+
Here is a simple test demonstrating using denoted comment classifications:
|
5933
6608
|
</p>
|
5934
6609
|
<p>
|
5935
6610
|
<div class="named_with_containers chunk">
|
5936
6611
|
<div class="chunk name">
|
5937
|
-
<a name="test-split-
|
5938
|
-
<span>test/
|
6612
|
+
<a name="test-split-denoted-comment-configurations-rb">
|
6613
|
+
<span>test/split_denoted_comment_configurations.rb</span>
|
5939
6614
|
</a>
|
5940
6615
|
</div>
|
5941
6616
|
<div class="chunk html">
|
@@ -5954,29 +6629,25 @@ Here is a simple test demonstrating using simple comment classifications:
|
|
5954
6629
|
<td class='html'>
|
5955
6630
|
<div class='rdoc comment markup'>
|
5956
6631
|
<p>
|
5957
|
-
Test built-in split
|
6632
|
+
Test built-in split denoted comment configurations.
|
5958
6633
|
</p>
|
5959
6634
|
</div>
|
5960
6635
|
</td>
|
5961
6636
|
</tr>
|
5962
6637
|
</table>
|
5963
6638
|
<pre class='ruby code syntax'>
|
5964
|
-
<span class="PreProc">class</span> <span class="Type">
|
6639
|
+
<span class="PreProc">class</span> <span class="Type">TestSplitDenotedCommentsConfigurations</span> < <span class="Type">Test</span>::<span class="Type">Unit</span>::<span class="Type">TestCase</span>
|
5965
6640
|
|
5966
6641
|
<span class="PreProc">include</span> <span class="Type">Test</span>::<span class="Type">WithConfigurations</span>
|
5967
6642
|
<span class="PreProc">include</span> <span class="Type">Test</span>::<span class="Type">WithErrors</span>
|
5968
6643
|
<span class="PreProc">include</span> <span class="Type">Test</span>::<span class="Type">WithTempfile</span>
|
5969
6644
|
|
5970
6645
|
<span class="PreProc">def</span> <span class="Identifier">test_custom_comments</span>
|
5971
|
-
check_any_comment(<span class="Special">"</span><span class="Constant"
|
6646
|
+
check_any_comment(<span class="Special">"</span><span class="Constant">// @</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">//</span><span class="Special">"</span>, <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_DENOTED_COMMENTS</span>.call(<span class="Special">"</span><span class="Constant">// @</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">//</span><span class="Special">"</span>))
|
5972
6647
|
<span class="PreProc">end</span>
|
5973
6648
|
|
5974
|
-
<span class="PreProc">def</span> <span class="Identifier">
|
5975
|
-
check_any_comment(<span class="Special">"</span><span class="Constant"
|
5976
|
-
<span class="PreProc">end</span>
|
5977
|
-
|
5978
|
-
<span class="PreProc">def</span> <span class="Identifier">test_cpp_comments</span>
|
5979
|
-
check_any_comment(<span class="Special">"</span><span class="Constant">//</span><span class="Special">"</span>, <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_CPP_COMMENTS</span>.call)
|
6649
|
+
<span class="PreProc">def</span> <span class="Identifier">test_haddoc_comments</span>
|
6650
|
+
check_any_comment(<span class="Special">"</span><span class="Constant">-- |</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">--</span><span class="Special">"</span>, <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_HADDOCK_COMMENTS</span>.call)
|
5980
6651
|
<span class="PreProc">end</span>
|
5981
6652
|
|
5982
6653
|
<span class="Statement">protected</span>
|
@@ -5990,7 +6661,8 @@ Test built-in split simple comment configurations.
|
|
5990
6661
|
<td class='html'>
|
5991
6662
|
<div class='rdoc comment markup'>
|
5992
6663
|
<p>
|
5993
|
-
The
|
6664
|
+
The “<<<” will be replaced by the start comment prefix, and
|
6665
|
+
the “>>>” will be replaced by the continue comment prefix.
|
5994
6666
|
</p>
|
5995
6667
|
</div>
|
5996
6668
|
</td>
|
@@ -5998,35 +6670,67 @@ The “?” will be replaced by the simple comment prefix.
|
|
5998
6670
|
</table>
|
5999
6671
|
<pre class='ruby code syntax'>
|
6000
6672
|
<span class="Type">ANY_COMMENT_CODE</span> = <<-<span class="Special">EOF</span>.unindent
|
6001
|
-
<span class="Constant">
|
6002
|
-
<span class="Constant">
|
6003
|
-
<span class="Constant">
|
6004
|
-
<span class="Constant">
|
6673
|
+
<span class="Constant"> >>> Not start comment</span>
|
6674
|
+
<span class="Constant"> <<< Start comment</span>
|
6675
|
+
<span class="Constant"> >>> Continue comment</span>
|
6676
|
+
<span class="Constant"> Not a comment</span>
|
6005
6677
|
<span class="Constant"> </span><span class="Special">EOF</span>
|
6006
6678
|
|
6007
|
-
|
6008
|
-
|
6009
|
-
|
6010
|
-
|
6011
|
-
|
6679
|
+
</pre>
|
6680
|
+
<table class='layout'>
|
6681
|
+
<tr>
|
6682
|
+
<td class='indentation'>
|
6683
|
+
<pre> </pre>
|
6684
|
+
</td>
|
6685
|
+
<td class='html'>
|
6686
|
+
<div class='rdoc comment markup'>
|
6687
|
+
<p>
|
6688
|
+
The “>>>” will be replaced by the continue comment prefix.
|
6689
|
+
</p>
|
6690
|
+
</div>
|
6691
|
+
</td>
|
6692
|
+
</tr>
|
6693
|
+
</table>
|
6694
|
+
<pre class='ruby code syntax'>
|
6695
|
+
<span class="Type">ANY_COMMENT_HTML</span> = <<-<span class="Special">EOF</span>.unindent.chomp <span class="Comment"># ((( html</span>
|
6696
|
+
</pre>
|
6697
|
+
<pre class='html code syntax'>
|
6698
|
+
<span class="Identifier"><</span><span class="Statement">pre</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'code'</span><span class="Identifier">></span>
|
6699
|
+
<span class="Error">>>></span> Not start comment
|
6700
|
+
<span class="Identifier"></</span><span class="Statement">pre</span><span class="Identifier">></span>
|
6701
|
+
<span class="Identifier"><</span><span class="Statement">pre</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'comment'</span><span class="Identifier">></span>
|
6702
|
+
Start comment
|
6703
|
+
Continue comment
|
6704
|
+
<span class="Identifier"></</span><span class="Statement">pre</span><span class="Identifier">></span>
|
6705
|
+
<span class="Identifier"><</span><span class="Statement">pre</span><span class="Identifier"> </span><span class="Type">class</span><span class="Identifier">=</span><span class="Constant">'code'</span><span class="Identifier">></span>
|
6706
|
+
Not a comment
|
6707
|
+
<span class="Identifier"></</span><span class="Statement">pre</span><span class="Identifier">></span>
|
6708
|
+
EOF
|
6709
|
+
# )))
|
6710
|
+
|
6711
|
+
def check_any_comment(start_prefix, continue_prefix, configuration)
|
6712
|
+
check_split_file(ANY_COMMENT_CODE.gsub("<span class="Identifier"><</span><span class="Error"><</span><span class="Identifier"><</span><span class="Constant">", start_prefix).gsub("</span><span class="Identifier">></span><span class="Error">>></span>", continue_prefix),
|
6713
|
+
Codnar::Configuration::CLASSIFY_SOURCE_CODE.call("any"),
|
6714
|
+
Codnar::Configuration::FORMAT_PRE_COMMENTS,
|
6715
|
+
configuration) do |path|
|
6012
6716
|
[ {
|
6013
|
-
|
6014
|
-
|
6015
|
-
|
6016
|
-
|
6017
|
-
|
6717
|
+
"name" =<span class="Error">></span> path,
|
6718
|
+
"locations" =<span class="Error">></span> [ { "file" =<span class="Error">></span> path, "line" =<span class="Error">></span> 1 } ],
|
6719
|
+
"containers" =<span class="Error">></span> [],
|
6720
|
+
"contained" =<span class="Error">></span> [],
|
6721
|
+
"html" =<span class="Error">></span> ANY_COMMENT_HTML.gsub("<span class="Error">>>></span>", continue_prefix),
|
6018
6722
|
} ]
|
6019
|
-
|
6020
|
-
|
6723
|
+
end
|
6724
|
+
end
|
6021
6725
|
|
6022
6726
|
end
|
6023
6727
|
</pre>
|
6024
6728
|
</div>
|
6025
6729
|
</div>
|
6026
6730
|
</p>
|
6027
|
-
<
|
6731
|
+
<h5>Delimited comment classification</h5>
|
6028
6732
|
<p>
|
6029
|
-
Other languages use a
|
6733
|
+
Other languages use a delimited multi-line comment syntax, where some prefix
|
6030
6734
|
indicates the beginning of the comment, some suffix indicates the end, and by
|
6031
6735
|
convention some prefix is expected for the inner comment lines (e.g., C's
|
6032
6736
|
"<code>/*</code>", "<code>*</code>", "<code>*/</code>" comments or HTML's "<code><!--</code>", "<code>-</code>", "<code>--></code>" comments).
|
@@ -6034,8 +6738,8 @@ convention some prefix is expected for the inner comment lines (e.g., C's
|
|
6034
6738
|
<p>
|
6035
6739
|
<div class="named_with_containers chunk">
|
6036
6740
|
<div class="chunk name">
|
6037
|
-
<a name="
|
6038
|
-
<span>
|
6741
|
+
<a name="delimited-comment-classification-configurations">
|
6742
|
+
<span>Delimited comment classification configurations</span>
|
6039
6743
|
</a>
|
6040
6744
|
</div>
|
6041
6745
|
<div class="chunk html">
|
@@ -6050,7 +6754,7 @@ convention some prefix is expected for the inner comment lines (e.g., C's
|
|
6050
6754
|
<td class='html'>
|
6051
6755
|
<div class='rdoc comment markup'>
|
6052
6756
|
<p>
|
6053
|
-
Classify
|
6757
|
+
Classify delimited comment lines. It accepts a restricted format: each
|
6054
6758
|
comment is expected to start with some exact prefix (e.g. “/*” for C
|
6055
6759
|
style comments or “<!–” for HTML style comments). The following
|
6056
6760
|
space, if any, is stripped from the payload. Following lines are also
|
@@ -6075,8 +6779,8 @@ useful.
|
|
6075
6779
|
</tr>
|
6076
6780
|
</table>
|
6077
6781
|
<pre class='ruby code syntax'>
|
6078
|
-
<span class="Type">
|
6079
|
-
<span class="Statement">return</span> <span class="Type">
|
6782
|
+
<span class="Type">CLASSIFY_DELIMITED_COMMENTS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span> |<span class="Identifier">prefix</span>, <span class="Identifier">inner</span>, <span class="Identifier">suffix</span>|
|
6783
|
+
<span class="Statement">return</span> <span class="Type">Comments</span>.delimited_comments(prefix, inner, suffix)
|
6080
6784
|
<span class="Statement">end</span>
|
6081
6785
|
|
6082
6786
|
</pre>
|
@@ -6088,7 +6792,7 @@ useful.
|
|
6088
6792
|
<td class='html'>
|
6089
6793
|
<div class='rdoc comment markup'>
|
6090
6794
|
<p>
|
6091
|
-
Classify
|
6795
|
+
Classify delimited C (“/*”, “ *”, “ */”) style comments.
|
6092
6796
|
</p>
|
6093
6797
|
</div>
|
6094
6798
|
</td>
|
@@ -6113,7 +6817,7 @@ need to escape special characters such as “*”.
|
|
6113
6817
|
</tr>
|
6114
6818
|
</table>
|
6115
6819
|
<pre class='ruby code syntax'>
|
6116
|
-
<span class="Statement">return</span> <span class="Type">
|
6820
|
+
<span class="Statement">return</span> <span class="Type">Comments</span>.delimited_comments(<span class="Special">"</span><span class="Constant">/</span><span class="Special">\\</span><span class="Constant">*</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> </span><span class="Special">\\</span><span class="Constant">*</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> </span><span class="Special">\\</span><span class="Constant">*/</span><span class="Special">"</span>)
|
6117
6821
|
end
|
6118
6822
|
|
6119
6823
|
</pre>
|
@@ -6125,7 +6829,7 @@ end
|
|
6125
6829
|
<td class='html'>
|
6126
6830
|
<div class='rdoc comment markup'>
|
6127
6831
|
<p>
|
6128
|
-
Classify
|
6832
|
+
Classify delimited HTML (“<!–”, “ -”, “–>”) style
|
6129
6833
|
comments.
|
6130
6834
|
</p>
|
6131
6835
|
</div>
|
@@ -6134,7 +6838,7 @@ comments.
|
|
6134
6838
|
</table>
|
6135
6839
|
<pre class='ruby code syntax'>
|
6136
6840
|
<span class="Type">CLASSIFY_HTML_COMMENTS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span>
|
6137
|
-
<span class="Statement">return</span> <span class="Type">
|
6841
|
+
<span class="Statement">return</span> <span class="Type">Comments</span>.delimited_comments(<span class="Special">"</span><span class="Constant"><!--</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> -</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant">--></span><span class="Special">"</span>)
|
6138
6842
|
<span class="Statement">end</span>
|
6139
6843
|
|
6140
6844
|
</pre>
|
@@ -6146,17 +6850,17 @@ comments.
|
|
6146
6850
|
<td class='html'>
|
6147
6851
|
<div class='rdoc comment markup'>
|
6148
6852
|
<p>
|
6149
|
-
Configuration for classifying lines to comments and code based on a
|
6150
|
-
start prefix, inner line prefix and final suffix (e.g., “/*”,
|
6151
|
-
“ */” for C-style comments or “<!–”, “ -”,
|
6152
|
-
for HTML style comments).
|
6853
|
+
Configuration for classifying lines to comments and code based on a
|
6854
|
+
delimited start prefix, inner line prefix and final suffix (e.g., “/*”,
|
6855
|
+
“ *”, “ */” for C-style comments or “<!–”, “ -”,
|
6856
|
+
“–>” for HTML style comments).
|
6153
6857
|
</p>
|
6154
6858
|
</div>
|
6155
6859
|
</td>
|
6156
6860
|
</tr>
|
6157
6861
|
</table>
|
6158
6862
|
<pre class='ruby code syntax'>
|
6159
|
-
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">
|
6863
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">delimited_comments</span>(prefix, inner, suffix)
|
6160
6864
|
<span class="Statement">return</span> {
|
6161
6865
|
<span class="Special">"</span><span class="Constant">syntax</span><span class="Special">"</span> => {
|
6162
6866
|
<span class="Special">"</span><span class="Constant">patterns</span><span class="Special">"</span> => {
|
@@ -6196,20 +6900,20 @@ for HTML style comments).
|
|
6196
6900
|
<span class="chunk containers header">Contained in:</span>
|
6197
6901
|
<ul class="chunk containers">
|
6198
6902
|
<li class="chunk container">
|
6199
|
-
<a class="chunk container" href="#lib-codnar-
|
6903
|
+
<a class="chunk container" href="#lib-codnar-configuration-comments-rb">lib/codnar/configuration/comments.rb</a>
|
6200
6904
|
</li>
|
6201
6905
|
</ul>
|
6202
6906
|
</div>
|
6203
6907
|
</div>
|
6204
6908
|
</p>
|
6205
6909
|
<p>
|
6206
|
-
Here is a simple test demonstrating using
|
6910
|
+
Here is a simple test demonstrating using delimited comment classifications:
|
6207
6911
|
</p>
|
6208
6912
|
<p>
|
6209
6913
|
<div class="named_with_containers chunk">
|
6210
6914
|
<div class="chunk name">
|
6211
|
-
<a name="test-split-
|
6212
|
-
<span>test/
|
6915
|
+
<a name="test-split-delimited-comment-configurations-rb">
|
6916
|
+
<span>test/split_delimited_comment_configurations.rb</span>
|
6213
6917
|
</a>
|
6214
6918
|
</div>
|
6215
6919
|
<div class="chunk html">
|
@@ -6228,14 +6932,14 @@ Here is a simple test demonstrating using complex comment classifications:
|
|
6228
6932
|
<td class='html'>
|
6229
6933
|
<div class='rdoc comment markup'>
|
6230
6934
|
<p>
|
6231
|
-
Test built-in split
|
6935
|
+
Test built-in split delimited comment configurations.
|
6232
6936
|
</p>
|
6233
6937
|
</div>
|
6234
6938
|
</td>
|
6235
6939
|
</tr>
|
6236
6940
|
</table>
|
6237
6941
|
<pre class='ruby code syntax'>
|
6238
|
-
<span class="PreProc">class</span> <span class="Type">
|
6942
|
+
<span class="PreProc">class</span> <span class="Type">TestSplitDelimitedCommentsConfigurations</span> < <span class="Type">Test</span>::<span class="Type">Unit</span>::<span class="Type">TestCase</span>
|
6239
6943
|
|
6240
6944
|
<span class="PreProc">include</span> <span class="Type">Test</span>::<span class="Type">WithConfigurations</span>
|
6241
6945
|
<span class="PreProc">include</span> <span class="Type">Test</span>::<span class="Type">WithErrors</span>
|
@@ -6259,7 +6963,7 @@ need to escape special characters such as “{” and “|”.
|
|
6259
6963
|
</tr>
|
6260
6964
|
</table>
|
6261
6965
|
<pre class='ruby code syntax'>
|
6262
|
-
check_any_comment([ <span class="Special">"</span><span class="Constant">@{</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> |</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> }@</span><span class="Special">"</span> ], <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">
|
6966
|
+
check_any_comment([ <span class="Special">"</span><span class="Constant">@{</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> |</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> }@</span><span class="Special">"</span> ], <span class="Type">Codnar</span>::<span class="Type">Configuration</span>::<span class="Type">CLASSIFY_DELIMITED_COMMENTS</span>.call(<span class="Special">"</span><span class="Constant">@</span><span class="Special">\\</span><span class="Constant">{</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> </span><span class="Special">\\</span><span class="Constant">|</span><span class="Special">"</span>, <span class="Special">"</span><span class="Constant"> </span><span class="Special">\\</span><span class="Constant">}@</span><span class="Special">"</span>))
|
6263
6967
|
end
|
6264
6968
|
|
6265
6969
|
<span class="PreProc">def</span> <span class="Identifier">test_c_comments</span>
|
@@ -6281,9 +6985,9 @@ need to escape special characters such as “{” and “|”.
|
|
6281
6985
|
<td class='html'>
|
6282
6986
|
<div class='rdoc comment markup'>
|
6283
6987
|
<p>
|
6284
|
-
The “<<<” will be replaced by the
|
6988
|
+
The “<<<” will be replaced by the start comment prefix, the
|
6285
6989
|
“<>” will be replaced by the inner line comment prefix, and the
|
6286
|
-
“>>>” will be replaced by the
|
6990
|
+
“>>>” will be replaced by the end comment suffix.
|
6287
6991
|
</p>
|
6288
6992
|
</div>
|
6289
6993
|
</td>
|
@@ -6291,12 +6995,12 @@ The “<<<” will be replaced by the complex comment prefix, the
|
|
6291
6995
|
</table>
|
6292
6996
|
<pre class='ruby code syntax'>
|
6293
6997
|
<span class="Type">ANY_COMMENT_CODE</span> = <<-<span class="Special">EOF</span>.unindent
|
6294
|
-
<span class="Constant">
|
6998
|
+
<span class="Constant"> <<< One-line comment >>></span>
|
6295
6999
|
<span class="Constant"> Code</span>
|
6296
|
-
<span class="Constant">
|
6297
|
-
<span class="Constant">
|
6298
|
-
<span class="Constant">
|
6299
|
-
<span class="Constant">
|
7000
|
+
<span class="Constant"> <<<</span>
|
7001
|
+
<span class="Constant"> <> Multi-line</span>
|
7002
|
+
<span class="Constant"> <> comment.</span>
|
7003
|
+
<span class="Constant"> >>></span>
|
6300
7004
|
<span class="Constant"> </span><span class="Special">EOF</span>
|
6301
7005
|
|
6302
7006
|
<span class="Type">ANY_COMMENT_HTML</span> = <<-<span class="Special">EOF</span>.unindent.chomp <span class="Comment"># ((( html</span>
|
@@ -6319,21 +7023,21 @@ The “<<<” will be replaced by the complex comment prefix, the
|
|
6319
7023
|
|
6320
7024
|
def check_any_comment(patterns, configuration)
|
6321
7025
|
prefix, inner, suffix = patterns
|
6322
|
-
check_split_file(ANY_COMMENT_CODE.gsub("
|
6323
|
-
Codnar::Configuration::CLASSIFY_SOURCE_CODE.call("
|
6324
|
-
Codnar::Configuration::FORMAT_PRE_COMMENTS
|
6325
|
-
configuration) do |path
|
6326
|
-
[ {
|
6327
|
-
"
|
6328
|
-
"
|
6329
|
-
"
|
6330
|
-
"
|
6331
|
-
"
|
6332
|
-
} ]
|
6333
|
-
end
|
6334
|
-
end
|
7026
|
+
check_split_file(ANY_COMMENT_CODE.gsub("<span class="Identifier"><</span><span class="Error"><</span><span class="Identifier"><</span><span class="Constant">", prefix).gsub("</span><span class="Identifier">></span><span class="Error">>></span>", suffix).gsub("<span class="Identifier"><></span><span class="Constant">", inner),</span>
|
7027
|
+
<span class="Constant"> Codnar::Configuration::CLASSIFY_SOURCE_CODE.call("</span><span class="Identifier">any</span><span class="Constant">"),</span>
|
7028
|
+
<span class="Constant"> Codnar::Configuration::FORMAT_PRE_COMMENTS,</span>
|
7029
|
+
<span class="Constant"> configuration) do |path|</span>
|
7030
|
+
<span class="Constant"> [ {</span>
|
7031
|
+
<span class="Constant"> "</span><span class="Type">name</span><span class="Constant">" => path,</span>
|
7032
|
+
<span class="Constant"> "</span><span class="Identifier">locations</span><span class="Constant">" => [ { "</span><span class="Identifier">file</span><span class="Constant">" => path, "</span><span class="Identifier">line</span><span class="Constant">" => 1 } ],</span>
|
7033
|
+
<span class="Constant"> "</span><span class="Identifier">containers</span><span class="Constant">" => [],</span>
|
7034
|
+
<span class="Constant"> "</span><span class="Identifier">contained</span><span class="Constant">" => [],</span>
|
7035
|
+
<span class="Constant"> "</span><span class="Identifier">html</span><span class="Constant">" => ANY_COMMENT_HTML.gsub("</span><span class="Identifier">/--</span><span class="Constant">", prefix).gsub("</span><span class="Identifier">--/</span><span class="Constant">", suffix).gsub("</span><span class="Identifier"> -</span><span class="Constant">", inner),</span>
|
7036
|
+
<span class="Constant"> } ]</span>
|
7037
|
+
<span class="Constant"> end</span>
|
7038
|
+
<span class="Constant"> end</span>
|
6335
7039
|
|
6336
|
-
end
|
7040
|
+
<span class="Constant">end</span>
|
6337
7041
|
</pre>
|
6338
7042
|
</div>
|
6339
7043
|
</div>
|
@@ -6425,13 +7129,37 @@ configuration that classifies some lines as <tt>comment</tt>.
|
|
6425
7129
|
},
|
6426
7130
|
}
|
6427
7131
|
|
7132
|
+
</pre>
|
7133
|
+
<table class='layout'>
|
7134
|
+
<tr>
|
7135
|
+
<td class='indentation'>
|
7136
|
+
<pre></pre>
|
7137
|
+
</td>
|
7138
|
+
<td class='html'>
|
7139
|
+
<div class='rdoc comment markup'>
|
7140
|
+
<p>
|
7141
|
+
Format comments that use the Haddock notation. Is used to complement a
|
7142
|
+
configuration that classifies some lines as <tt>comment</tt>.
|
7143
|
+
</p>
|
7144
|
+
</div>
|
7145
|
+
</td>
|
7146
|
+
</tr>
|
7147
|
+
</table>
|
7148
|
+
<pre class='ruby code syntax'>
|
7149
|
+
<span class="Type">FORMAT_HADDOCK_COMMENTS</span> = {
|
7150
|
+
<span class="Special">"</span><span class="Constant">formatters</span><span class="Special">"</span> => {
|
7151
|
+
<span class="Special">"</span><span class="Constant">comment</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.markup_lines_to_html(lines, Haddock, 'haddock')</span><span class="Special">"</span>,
|
7152
|
+
<span class="Special">"</span><span class="Constant">unindented_html</span><span class="Special">"</span> => <span class="Special">"</span><span class="Constant">Formatter.unindented_lines_to_html(lines)</span><span class="Special">"</span>,
|
7153
|
+
},
|
7154
|
+
}
|
7155
|
+
|
6428
7156
|
</pre>
|
6429
7157
|
</div>
|
6430
7158
|
<div class="chunk containers">
|
6431
7159
|
<span class="chunk containers header">Contained in:</span>
|
6432
7160
|
<ul class="chunk containers">
|
6433
7161
|
<li class="chunk container">
|
6434
|
-
<a class="chunk container" href="#lib-codnar-
|
7162
|
+
<a class="chunk container" href="#lib-codnar-configuration-comments-rb">lib/codnar/configuration/comments.rb</a>
|
6435
7163
|
</li>
|
6436
7164
|
</ul>
|
6437
7165
|
</div>
|
@@ -6499,7 +7227,7 @@ Test built-in split comment formatting configurations.
|
|
6499
7227
|
<span class="Constant"> <td class='html'></span>
|
6500
7228
|
<span class="Constant"> <div class='rdoc comment markup'></span>
|
6501
7229
|
<span class="Constant"> <p></span>
|
6502
|
-
<span class="Constant"> Comment <
|
7230
|
+
<span class="Constant"> Comment <strong>text</strong>.</span>
|
6503
7231
|
<span class="Constant"> </p></span>
|
6504
7232
|
<span class="Constant"> </div></span>
|
6505
7233
|
<span class="Constant"> </td></span>
|
@@ -6554,10 +7282,80 @@ Test built-in split comment formatting configurations.
|
|
6554
7282
|
</div>
|
6555
7283
|
</div>
|
6556
7284
|
</p>
|
6557
|
-
<h4>Syntax highlighting
|
7285
|
+
<h4>Syntax highlighting</h4>
|
7286
|
+
<p>
|
7287
|
+
Highlighting the syntax of the source code embedded in the documentation
|
7288
|
+
improved readability. Codnar provides several ways to achieve this.
|
7289
|
+
</p>
|
7290
|
+
<p>
|
7291
|
+
<div class="named_with_containers chunk">
|
7292
|
+
<div class="chunk name">
|
7293
|
+
<a name="lib-codnar-configuration-highlighting-rb">
|
7294
|
+
<span>lib/codnar/configuration/highlighting.rb</span>
|
7295
|
+
</a>
|
7296
|
+
</div>
|
7297
|
+
<div class="chunk html">
|
7298
|
+
<pre class='ruby code syntax'>
|
7299
|
+
<span class="PreProc">module</span> <span class="Type">Codnar</span>
|
7300
|
+
|
7301
|
+
<span class="PreProc">module</span> <span class="Type">Configuration</span>
|
7302
|
+
|
7303
|
+
</pre>
|
7304
|
+
<table class='layout'>
|
7305
|
+
<tr>
|
7306
|
+
<td class='indentation'>
|
7307
|
+
<pre> </pre>
|
7308
|
+
</td>
|
7309
|
+
<td class='html'>
|
7310
|
+
<div class='rdoc comment markup'>
|
7311
|
+
<p>
|
7312
|
+
Configurations for highlighting source code lines.
|
7313
|
+
</p>
|
7314
|
+
</div>
|
7315
|
+
</td>
|
7316
|
+
</tr>
|
7317
|
+
</table>
|
7318
|
+
<pre class='ruby code syntax'>
|
7319
|
+
<span class="PreProc">module</span> <span class="Type">Highlighting</span>
|
7320
|
+
|
7321
|
+
</pre>
|
7322
|
+
<pre class='nested chunk'>
|
7323
|
+
<a class='nested chunk' href='#gvim-syntax-highlighting-formatting-configurations'>GVim syntax highlighting formatting configurations</a>
|
7324
|
+
</pre>
|
7325
|
+
<pre class='ruby code syntax'>
|
7326
|
+
|
7327
|
+
</pre>
|
7328
|
+
<pre class='nested chunk'>
|
7329
|
+
<a class='nested chunk' href='#coderay-syntax-highlighting-formatting-configurations'>CodeRay syntax highlighting formatting configurations</a>
|
7330
|
+
</pre>
|
7331
|
+
<pre class='ruby code syntax'>
|
7332
|
+
|
7333
|
+
</pre>
|
7334
|
+
<pre class='nested chunk'>
|
7335
|
+
<a class='nested chunk' href='#sunlight-syntax-highlighting-formatting-configurations'>Sunlight syntax highlighting formatting configurations</a>
|
7336
|
+
</pre>
|
7337
|
+
<pre class='ruby code syntax'>
|
7338
|
+
|
7339
|
+
</pre>
|
7340
|
+
<pre class='nested chunk'>
|
7341
|
+
<a class='nested chunk' href='#chunk-splitting-configurations'>Chunk splitting configurations</a>
|
7342
|
+
</pre>
|
7343
|
+
<pre class='ruby code syntax'>
|
7344
|
+
|
7345
|
+
end
|
7346
|
+
|
7347
|
+
end
|
7348
|
+
|
7349
|
+
end
|
7350
|
+
</pre>
|
7351
|
+
</div>
|
7352
|
+
</div>
|
7353
|
+
</p>
|
7354
|
+
<h5>Syntax highlighting using GVim</h5>
|
6558
7355
|
<p>
|
6559
|
-
Supporting
|
6560
|
-
is very easy using GVim for syntax highlighting, as demonstrated
|
7356
|
+
Supporting almost any known programming language (other than dealing with
|
7357
|
+
comments) is very easy using GVim for syntax highlighting, as demonstrated
|
7358
|
+
here:
|
6561
7359
|
</p>
|
6562
7360
|
<p>
|
6563
7361
|
<div class="named_with_containers chunk">
|
@@ -6588,7 +7386,7 @@ lines.
|
|
6588
7386
|
</table>
|
6589
7387
|
<pre class='ruby code syntax'>
|
6590
7388
|
<span class="Type">FORMAT_CODE_GVIM_HTML</span> = <span class="Statement">lambda</span> <span class="Statement">do</span> |<span class="Identifier">syntax</span>|
|
6591
|
-
<span class="Statement">return</span> <span class="Type">
|
7389
|
+
<span class="Statement">return</span> <span class="Type">Highlighting</span>.klass_code_format(<span class="Special">'</span><span class="Constant">GVim</span><span class="Special">'</span>, syntax, <span class="Special">"</span><span class="Constant">[]</span><span class="Special">"</span>)
|
6592
7390
|
<span class="Statement">end</span>
|
6593
7391
|
|
6594
7392
|
</pre>
|
@@ -6610,7 +7408,7 @@ already classified the code lines.
|
|
6610
7408
|
</table>
|
6611
7409
|
<pre class='ruby code syntax'>
|
6612
7410
|
<span class="Type">FORMAT_CODE_GVIM_CSS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span> |<span class="Identifier">syntax</span>|
|
6613
|
-
<span class="Statement">return</span> <span class="Type">
|
7411
|
+
<span class="Statement">return</span> <span class="Type">Highlighting</span>.klass_code_format(<span class="Special">'</span><span class="Constant">GVim</span><span class="Special">'</span>, syntax, <span class="Special">"</span><span class="Constant">[ '+:let html_use_css=1' ]</span><span class="Special">"</span>)
|
6614
7412
|
<span class="Statement">end</span>
|
6615
7413
|
|
6616
7414
|
</pre>
|
@@ -6643,7 +7441,7 @@ Return a configuration for highlighting a specific syntax using GVim.
|
|
6643
7441
|
<span class="chunk containers header">Contained in:</span>
|
6644
7442
|
<ul class="chunk containers">
|
6645
7443
|
<li class="chunk container">
|
6646
|
-
<a class="chunk container" href="#lib-codnar-
|
7444
|
+
<a class="chunk container" href="#lib-codnar-configuration-highlighting-rb">lib/codnar/configuration/highlighting.rb</a>
|
6647
7445
|
</li>
|
6648
7446
|
</ul>
|
6649
7447
|
</div>
|
@@ -6688,7 +7486,7 @@ Colors for GVim classes
|
|
6688
7486
|
</div>
|
6689
7487
|
</div>
|
6690
7488
|
</p>
|
6691
|
-
<
|
7489
|
+
<h5>Syntax highlighting using CodeRay</h5>
|
6692
7490
|
<p>
|
6693
7491
|
For supported programming languages, you may choose to use CodeRay instead of GVim.
|
6694
7492
|
</p>
|
@@ -6721,7 +7519,7 @@ lines.
|
|
6721
7519
|
</table>
|
6722
7520
|
<pre class='ruby code syntax'>
|
6723
7521
|
<span class="Type">FORMAT_CODE_CODERAY_HTML</span> = <span class="Statement">lambda</span> <span class="Statement">do</span> |<span class="Identifier">syntax</span>|
|
6724
|
-
<span class="Statement">return</span> <span class="Type">
|
7522
|
+
<span class="Statement">return</span> <span class="Type">Highlighting</span>.klass_code_format(<span class="Special">'</span><span class="Constant">CodeRay</span><span class="Special">'</span>, syntax, <span class="Special">"</span><span class="Constant">{}</span><span class="Special">"</span>)
|
6725
7523
|
<span class="Statement">end</span>
|
6726
7524
|
|
6727
7525
|
</pre>
|
@@ -6743,7 +7541,7 @@ configuration already classified the code lines.
|
|
6743
7541
|
</table>
|
6744
7542
|
<pre class='ruby code syntax'>
|
6745
7543
|
<span class="Type">FORMAT_CODE_CODERAY_CSS</span> = <span class="Statement">lambda</span> <span class="Statement">do</span> |<span class="Identifier">syntax</span>|
|
6746
|
-
<span class="Statement">return</span> <span class="Type">
|
7544
|
+
<span class="Statement">return</span> <span class="Type">Highlighting</span>.klass_code_format(<span class="Special">'</span><span class="Constant">CodeRay</span><span class="Special">'</span>, syntax, <span class="Special">"</span><span class="Constant">{ :css => :class }</span><span class="Special">"</span>)
|
6747
7545
|
<span class="Statement">end</span>
|
6748
7546
|
|
6749
7547
|
</pre>
|
@@ -6752,7 +7550,7 @@ configuration already classified the code lines.
|
|
6752
7550
|
<span class="chunk containers header">Contained in:</span>
|
6753
7551
|
<ul class="chunk containers">
|
6754
7552
|
<li class="chunk container">
|
6755
|
-
<a class="chunk container" href="#lib-codnar-
|
7553
|
+
<a class="chunk container" href="#lib-codnar-configuration-highlighting-rb">lib/codnar/configuration/highlighting.rb</a>
|
6756
7554
|
</li>
|
6757
7555
|
</ul>
|
6758
7556
|
</div>
|
@@ -6916,7 +7714,7 @@ Extracted from CodeRay output
|
|
6916
7714
|
</div>
|
6917
7715
|
</div>
|
6918
7716
|
</p>
|
6919
|
-
<
|
7717
|
+
<h5>Syntax highlighting using Sunlight</h5>
|
6920
7718
|
<p>
|
6921
7719
|
For small projects in supported languages, you may choose to use Sunlight
|
6922
7720
|
instead of GVim.
|
@@ -6951,7 +7749,7 @@ splitting the file.
|
|
6951
7749
|
</table>
|
6952
7750
|
<pre class='ruby code syntax'>
|
6953
7751
|
<span class="Type">FORMAT_CODE_SUNLIGHT</span> = <span class="Statement">lambda</span> <span class="Statement">do</span> |<span class="Identifier">syntax</span>|
|
6954
|
-
<span class="Statement">return</span> <span class="Type">
|
7752
|
+
<span class="Statement">return</span> <span class="Type">Highlighting</span>.sunlight_code_format(syntax)
|
6955
7753
|
<span class="Statement">end</span>
|
6956
7754
|
|
6957
7755
|
</pre>
|
@@ -6984,7 +7782,7 @@ Return a configuration for highlighting a specific syntax using Sunlight.
|
|
6984
7782
|
<span class="chunk containers header">Contained in:</span>
|
6985
7783
|
<ul class="chunk containers">
|
6986
7784
|
<li class="chunk container">
|
6987
|
-
<a class="chunk container" href="#lib-codnar-
|
7785
|
+
<a class="chunk container" href="#lib-codnar-configuration-highlighting-rb">lib/codnar/configuration/highlighting.rb</a>
|
6988
7786
|
</li>
|
6989
7787
|
</ul>
|
6990
7788
|
</div>
|
@@ -7156,7 +7954,7 @@ designations. Assumes other configurations handle the actual content lines.
|
|
7156
7954
|
<span class="chunk containers header">Contained in:</span>
|
7157
7955
|
<ul class="chunk containers">
|
7158
7956
|
<li class="chunk container">
|
7159
|
-
<a class="chunk container" href="#lib-codnar-
|
7957
|
+
<a class="chunk container" href="#lib-codnar-configuration-highlighting-rb">lib/codnar/configuration/highlighting.rb</a>
|
7160
7958
|
</li>
|
7161
7959
|
</ul>
|
7162
7960
|
</div>
|
@@ -7364,7 +8162,7 @@ Test combination of many built-in configurations.
|
|
7364
8162
|
<span class="Constant"> <td class='html'></span>
|
7365
8163
|
<span class="Constant"> <div class='rdoc comment markup'></span>
|
7366
8164
|
<span class="Constant"> <p></span>
|
7367
|
-
<span class="Constant"> Hello, <
|
8165
|
+
<span class="Constant"> Hello, <strong>world</strong>!</span>
|
7368
8166
|
<span class="Constant"> </p></span>
|
7369
8167
|
<span class="Constant"> </div></span>
|
7370
8168
|
<span class="Constant"> </td></span>
|
@@ -9100,6 +9898,7 @@ convenient list of all of Codnar's parts and dependencies:
|
|
9100
9898
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">irb</span><span class="Special">"</span>
|
9101
9899
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">open3</span><span class="Special">"</span>
|
9102
9900
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">rdiscount</span><span class="Special">"</span>
|
9901
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">rdoc</span><span class="Special">"</span>
|
9103
9902
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">rdoc/markup/to_html</span><span class="Special">"</span>
|
9104
9903
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">tempfile</span><span class="Special">"</span>
|
9105
9904
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">yaml</span><span class="Special">"</span>
|
@@ -9113,6 +9912,7 @@ convenient list of all of Codnar's parts and dependencies:
|
|
9113
9912
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/version</span><span class="Special">"</span>
|
9114
9913
|
|
9115
9914
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/coderay</span><span class="Special">"</span>
|
9915
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/haddock</span><span class="Special">"</span>
|
9116
9916
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/hash_extensions</span><span class="Special">"</span>
|
9117
9917
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/markdown</span><span class="Special">"</span>
|
9118
9918
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/rdoc</span><span class="Special">"</span>
|
@@ -9128,6 +9928,10 @@ convenient list of all of Codnar's parts and dependencies:
|
|
9128
9928
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/split</span><span class="Special">"</span>
|
9129
9929
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/reader</span><span class="Special">"</span>
|
9130
9930
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/scanner</span><span class="Special">"</span>
|
9931
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/configuration/code</span><span class="Special">"</span>
|
9932
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/configuration/comments</span><span class="Special">"</span>
|
9933
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/configuration/documentation</span><span class="Special">"</span>
|
9934
|
+
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/configuration/highlighting</span><span class="Special">"</span>
|
9131
9935
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/split_configurations</span><span class="Special">"</span>
|
9132
9936
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/splitter</span><span class="Special">"</span>
|
9133
9937
|
<span class="PreProc">require</span> <span class="Special">"</span><span class="Constant">codnar/sunlight</span><span class="Special">"</span>
|
@@ -9848,10 +10652,9 @@ Test running the Weave Codnar Application.
|
|
9848
10652
|
<span class="PreProc">def</span> <span class="Identifier">test_run_weave_missing_file</span>
|
9849
10653
|
write_fake_file(<span class="Special">"</span><span class="Constant">root</span><span class="Special">"</span>, <span class="Type">FILE_CHUNKS</span>.to_yaml)
|
9850
10654
|
<span class="Type">Codnar</span>::<span class="Type">Application</span>.with_argv(<span class="Special">%w(</span><span class="Constant">-e stderr -o stdout root</span><span class="Special">)</span>) { <span class="Type">Codnar</span>::<span class="Type">Weave</span>.new(<span class="Constant">true</span>).run }.should == <span class="Constant">1</span>
|
9851
|
-
|
9852
|
-
<span class="Type">File</span>.read(<span class="Special">"</span><span class="Constant">stdout</span><span class="Special">"</span>).should == <span class="Special">"</span><span class="Constant">Root</span><span class="Special">\n</span><span class="Constant">FILE: included.file EXCEPTION: </span><span class="Special">#{</span>double_message<span class="Special">}</span><span class="Special">\n</span><span class="Special">"</span>
|
10655
|
+
<span class="Type">File</span>.read(<span class="Special">"</span><span class="Constant">stdout</span><span class="Special">"</span>).should == <span class="Special">"</span><span class="Constant">Root</span><span class="Special">\n</span><span class="Constant">FILE: included.file EXCEPTION: No such file or directory - included.file</span><span class="Special">\n</span><span class="Special">"</span>
|
9853
10656
|
<span class="Type">File</span>.read(<span class="Special">"</span><span class="Constant">stderr</span><span class="Special">"</span>).should \
|
9854
|
-
== <span class="Special">"</span><span class="Special">#{</span><span class="Identifier">$0</span><span class="Special">}</span><span class="Constant">: Reading file: included.file exception:
|
10657
|
+
== <span class="Special">"</span><span class="Special">#{</span><span class="Identifier">$0</span><span class="Special">}</span><span class="Constant">: Reading file: included.file exception: No such file or directory - included.file in file: root at line: 1</span><span class="Special">\n</span><span class="Special">"</span>
|
9855
10658
|
<span class="PreProc">end</span>
|
9856
10659
|
|
9857
10660
|
<span class="PreProc">def</span> <span class="Identifier">test_run_weave_existing_file</span>
|
@@ -10447,6 +11250,27 @@ Actually create common Rake split tasks.
|
|
10447
11250
|
::<span class="Type">Rake</span>::<span class="Type">Task</span>.define_task(<span class="Constant">:clean</span> => <span class="Special">"</span><span class="Constant">clean_codnar</span><span class="Special">"</span>)
|
10448
11251
|
<span class="PreProc">end</span>
|
10449
11252
|
|
11253
|
+
</pre>
|
11254
|
+
<table class='layout'>
|
11255
|
+
<tr>
|
11256
|
+
<td class='indentation'>
|
11257
|
+
<pre> </pre>
|
11258
|
+
</td>
|
11259
|
+
<td class='html'>
|
11260
|
+
<div class='rdoc comment markup'>
|
11261
|
+
<p>
|
11262
|
+
For some reason, <code>include ::Rake::DSL</code> doesn’t give us this
|
11263
|
+
and life is too short…
|
11264
|
+
</p>
|
11265
|
+
</div>
|
11266
|
+
</td>
|
11267
|
+
</tr>
|
11268
|
+
</table>
|
11269
|
+
<pre class='ruby code syntax'>
|
11270
|
+
<span class="PreProc">def</span> <span class="Constant">self</span>.<span class="Identifier">desc</span>(description)
|
11271
|
+
::<span class="Type">Rake</span>.application.last_description = description
|
11272
|
+
<span class="PreProc">end</span>
|
11273
|
+
|
10450
11274
|
</pre>
|
10451
11275
|
<table class='layout'>
|
10452
11276
|
<tr>
|
@@ -11040,7 +11864,23 @@ Create nested UL/LI lists for the table of content.
|
|
11040
11864
|
<span class="Identifier">var</span> container;
|
11041
11865
|
<span class="Identifier">var</span> indices = <span class="Identifier">[]</span>;
|
11042
11866
|
<span class="Identifier">var</span> h_elements = all_h_elements();
|
11043
|
-
|
11867
|
+
</pre>
|
11868
|
+
<table class='layout'>
|
11869
|
+
<tr>
|
11870
|
+
<td class='indentation'>
|
11871
|
+
<pre> </pre>
|
11872
|
+
</td>
|
11873
|
+
<td class='html'>
|
11874
|
+
<div class='markdown comment markup'>
|
11875
|
+
<p>
|
11876
|
+
Using "for (var e in h_elements)" is too sensitive to other libraries
|
11877
|
+
</p>
|
11878
|
+
</div>
|
11879
|
+
</td>
|
11880
|
+
</tr>
|
11881
|
+
</table>
|
11882
|
+
<pre class='javascript code syntax'>
|
11883
|
+
<span class="Statement">for</span> (<span class="Identifier">var</span> e = 0; e < h_elements.length; e++) <span class="Identifier">{</span>
|
11044
11884
|
h = h_elements<span class="Identifier">[</span>e<span class="Identifier">]</span>;
|
11045
11885
|
<span class="Identifier">var</span> level = h.tagName.substring(1, 2) - 1;
|
11046
11886
|
container = pop_container(container, indices, level);
|
@@ -11450,7 +12290,8 @@ function contents_lists() {
|
|
11450
12290
|
var container;
|
11451
12291
|
var indices = [];
|
11452
12292
|
var h_elements = all_h_elements();
|
11453
|
-
for (var e in h_elements)
|
12293
|
+
/* Using "for (var e in h_elements)" is too sensitive to other libraries */
|
12294
|
+
for (var e = 0; e < h_elements.length; e++) {
|
11454
12295
|
h = h_elements[e];
|
11455
12296
|
var level = h.tagName.substring(1, 2) - 1;
|
11456
12297
|
container = pop_container(container, indices, level);
|