[as2api-dev] [CVS trunk] Syntax highlighting for {@code ... } tags.
David Holroyd
dave at badgers-in-foil.co.uk
Sat, 16 Jul 2005 14:14:50 +0000
<html>
<head>
<style><!--
body {background-color:#ffffff;}
.file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
.pathname {font-family:monospace; float:right;}
.fileheader {margin-bottom:.5em;}
.diff {margin:0;}
.tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
.tasklist ul {margin-top:0;margin-bottom:0;}
tr.alt {background-color:#eeeeee}
#added {background-color:#ddffdd;}
#addedchars {background-color:#99ff99;font-weight:bolder;}
tr.alt #added {background-color:#ccf7cc;}
#removed {background-color:#ffdddd;}
#removedchars {background-color:#ff9999;font-weight:bolder;}
tr.alt #removed {background-color:#f7cccc;}
#info {color:#888888;}
#context {background-color:#eeeeee;}
td {padding-left:.3em;padding-right:.3em;}
tr.head {border-bottom-width:1px;border-bottom-style:solid;}
tr.head td {padding:0;padding-top:.2em;}
.task {background-color:#ffff00;}
.comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
.error {color:red;}
hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>trunk/as2api</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1">html_output.rb</a></tt></td><td align="right" id="added">+66</td><td align="right" id="removed">-42</td><td nowrap="nowrap" align="center"><a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/html_output.rb?rev=202&content-type=text/vnd.viewcvs-markup">202</a> <a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/html_output.rb.diff?r1=202&r2=203">-></a> <a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/html_output.rb?rev=203&content-type=text/vnd.viewcvs-markup">203</a></td></tr>
</table>
<pre class="comment">
Syntax highlighting for {@code ... } tags.
If a {@code} tag spans multiple lines, it will be rendered with <pre> rather
than <code>
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname"><a
href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk">trunk</a>/<a
href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api">as2api</a></span><br />
<div class="fileheader"><big><b>html_output.rb</b></big> <small id="info"><a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/html_output.rb?rev=202&content-type=text/vnd.viewcvs-markup">202</a> <a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/html_output.rb.diff?r1=202&r2=203">-></a> <a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/html_output.rb?rev=203&content-type=text/vnd.viewcvs-markup">203</a></small></div>
<pre class="diff"><small id="info">--- trunk/as2api/html_output.rb 2005-07-16 12:09:21 UTC (rev 202)
+++ trunk/as2api/html_output.rb 2005-07-16 14:14:48 UTC (rev 203)
@@ -472,8 +472,17 @@
</small></pre><pre class="diff" id="context"> end
end
elsif inline.is_a?(CodeTag)
</pre><pre class="diff" id="removed">- html_code do
- pcdata(inline.text)
</pre><pre class="diff" id="added">+ input = StringIO.new(inline.text)
+ highlight = CodeHighlighter.new
+ highlight.number_lines = false
+ if inline.text =~ /[\n\r]/
+ html_pre do
+ highlight.highlight(input, self)
+ end
+ else
+ html_code do
+ highlight.highlight(input, self)
+ end
</pre><pre class="diff" id="context"> end
else
html_em(inline.inspect)
</pre><pre class="diff"><small id="info">@@ -1646,41 +1655,14 @@
</small></pre><pre class="diff" id="context"> end
end
</pre><pre class="diff" id="added">+class CodeHighlighter
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">-class SourcePage < BasicPage
-
- def initialize(conf, type)
- dir = type.package_name.gsub(/\./, "/")
- super(conf, type.unqualified_name+".as", dir)
- @type = type
</pre><pre class="diff" id="added">+ def initialize
+ @number_lines = true
</pre><pre class="diff" id="context"> end
</pre><pre class="diff" id="removed">- def generate_body_content
- html_pre do
- file = @type.input_file
- parse(File.join(file.prefix, file.suffix))
- end
- end
</pre><pre class="diff" id="added">+ attr_accessor :number_lines
</pre><pre class="diff" id="context">
</pre><pre class="diff" id="removed">- def parse(file)
- File.open(File.join(file)) do |io|
- begin
- is_utf8 = detect_bom?(io)
- as_io = ASIO.new(io)
- lex = ActionScript::Parse::SkipASLexer.new(HighlightASLexer.new(self, as_io))
- parse = HighlightASParser.new(lex)
- parse.handler = ActionScript::Parse::ASHandler.new
- parse.parse_compilation_unit
- rescue =>e
- $stderr.puts "#{file}: #{e.message}\n#{e.backtrace.join("\n")}"
- end
- end
- end
-
- class HighlightASParser < ActionScript::Parse::ASParser
-
- end
-
</pre><pre class="diff" id="context"> Keywords = [
ActionScript::Parse::AsToken,
ActionScript::Parse::BreakToken,
</pre><pre class="diff"><small id="info">@@ -1734,6 +1716,8 @@
</small></pre><pre class="diff" id="context"> @out = out
end
</pre><pre class="diff" id="added">+ attr_accessor :number_lines
+
</pre><pre class="diff" id="context"> def get_next
tok = super
out(tok)
</pre><pre class="diff"><small id="info">@@ -1741,7 +1725,7 @@
</small></pre><pre class="diff" id="context"> end
def out(tok)
</pre><pre class="diff" id="removed">- mark_lineno if @lineno == 0
</pre><pre class="diff" id="added">+ mark_lineno if @<span id="addedchars">number_lines && @</span>lineno == 0
</pre><pre class="diff" id="context"> if Keywords.include?(tok.class)
pp_tok(tok, "key")
return
</pre><pre class="diff"><small id="info">@@ -1771,15 +1755,19 @@
</small></pre><pre class="diff" id="context"> end
end
def p_tok(tok)
</pre><pre class="diff" id="removed">- txt = StringScanner.new(tok.to_s)
- until txt.eos?
- if match = txt.scan_until(/\r\n|\n|\r/)
- p_str(match)
- mark_lineno
- else
- p_str(txt.rest)
- txt.terminate
</pre><pre class="diff" id="added">+ if @number_lines
+ txt = StringScanner.new(tok.to_s)
+ until txt.eos?
+ if match = txt.scan_until(/\r\n|\n|\r/)
+ p_str(match)
+ mark_lineno
+ else
+ p_str(txt.rest)
+ txt.terminate
+ end
</pre><pre class="diff" id="context"> end
</pre><pre class="diff" id="added">+ else
+ p_str(tok.to_s)
</pre><pre class="diff" id="context"> end
end
</pre><pre class="diff"><small id="info">@@ -1795,6 +1783,42 @@
</small></pre><pre class="diff" id="context"> end
end
</pre><pre class="diff" id="added">+ def highlight(input, output)
+ lex = HighlightASLexer.new(output, input)
+ lex.number_lines = @number_lines
+ while lex.get_next; end
+ end
+end
+
+class SourcePage < BasicPage
+
+ def initialize(conf, type)
+ dir = type.package_name.gsub(/\./, "/")
+ super(conf, type.unqualified_name+".as", dir)
+ @type = type
+ end
+
+ def generate_body_content
+ html_pre do
+ file = @type.input_file
+ parse(File.join(file.prefix, file.suffix))
+ end
+ end
+
+ def parse(file)
+ File.open(File.join(file)) do |io|
+ begin
+ is_utf8 = detect_bom?(io)
+ as_io = ASIO.new(io)
+ highlight = CodeHighlighter.new
+ highlight.highlight(as_io, self)
+ rescue =>e
+ $stderr.puts "#{file}: #{e.message}\n#{e.backtrace.join("\n")}"
+ end
+ end
+ end
+
+
</pre><pre class="diff" id="context"> def navigation
html_ul("class"=>"main_nav") do
html_li do
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -> email">CVSspam</a> 0.2.11</small></center>
</body></html>