From 5ee15661dbc2da70927f588e310315233aff6eea Mon Sep 17 00:00:00 2001 From: murphy Date: Mon, 10 Apr 2006 03:06:50 +0000 Subject: Large update: Scanners for HTML, RHTML and Nitro-XHTML added. CSS style changes/enhancments (mainly the new background color for inline code, affects all Ruby code.) Demos and tests adjusted. Plugin: new PluginHost::default method. Scanner: - New setup method - ability to re-use a scanner - ability to keep the tokens - minor changes to token caching and string flattening Encoder: Error if token content is neither String nor Symbol. HTML encoder: - more warnings for unclosed tokens - output now UTF-8 Ruby Scanner: - bug: symbols before => now do not include =; {:foo=>bar} is valid Ruby code - try to close all open tokens - constants now all with specific namespace (for speed, I hope) Styles: new :entity/en class. Test suite now gives hinted HTML output. --- lib/coderay/encoder.rb | 6 +- lib/coderay/encoders/html.rb | 5 +- lib/coderay/encoders/html/classes.rb | 1 + lib/coderay/encoders/html/output.rb | 2 +- lib/coderay/helpers/plugin.rb | 22 ++++- lib/coderay/scanner.rb | 59 +++++++++---- lib/coderay/scanners/_map.rb | 4 +- lib/coderay/scanners/html.rb | 57 +++++++----- lib/coderay/scanners/nitro_html.rb | 123 ++++++++++++++++++++++++++ lib/coderay/scanners/rhtml.rb | 63 +++++++++++++ lib/coderay/scanners/ruby.rb | 35 +++++--- lib/coderay/scanners/ruby/patterns.rb | 2 +- lib/coderay/styles/cycnus.rb | 162 ++++++++++++++++++---------------- 13 files changed, 400 insertions(+), 141 deletions(-) create mode 100644 lib/coderay/scanners/nitro_html.rb create mode 100644 lib/coderay/scanners/rhtml.rb (limited to 'lib/coderay') diff --git a/lib/coderay/encoder.rb b/lib/coderay/encoder.rb index 8b6c22a..8f8375a 100644 --- a/lib/coderay/encoder.rb +++ b/lib/coderay/encoder.rb @@ -130,10 +130,12 @@ module CodeRay # By default, it calls text_token or block_token, depending on # whether +text+ is a String. def token text, kind - if text.is_a? String + if text.is_a? ::String text_token text, kind - else + elsif text.is_a? ::Symbol block_token text, kind + else + raise 'Unknown token text type: %p' % text end end diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb index 11fa84c..0b43c0c 100644 --- a/lib/coderay/encoders/html.rb +++ b/lib/coderay/encoders/html.rb @@ -205,6 +205,7 @@ module Encoders def finish options not_needed = @opened.shift @out << '' * @opened.size + warn '%d tokens still open' % @opened.size unless @opened.empty? @out.extend Output @out.css = @css @@ -230,11 +231,11 @@ module Encoders case text when :open @opened[0] = type - @out << @css_style[@opened] + @out << (@css_style[@opened] || '') @opened << type when :close unless @opened.empty? - raise 'Not Token to be closed.' unless @opened.size > 1 + raise 'Malformed token stream: Trying to close a token that was never opened.' unless @opened.size > 1 @out << '' @opened.pop end diff --git a/lib/coderay/encoders/html/classes.rb b/lib/coderay/encoders/html/classes.rb index 4a01920..3d40a42 100644 --- a/lib/coderay/encoders/html/classes.rb +++ b/lib/coderay/encoders/html/classes.rb @@ -20,6 +20,7 @@ module CodeRay module Encoders :directive => 'di', :doc => 'do', :doc_string => 'ds', + :entity => 'en', :error => 'er', :escape => 'e', :exception => 'ex', diff --git a/lib/coderay/encoders/html/output.rb b/lib/coderay/encoders/html/output.rb index 80ab4f1..e9a3a41 100644 --- a/lib/coderay/encoders/html/output.rb +++ b/lib/coderay/encoders/html/output.rb @@ -174,7 +174,7 @@ module CodeRay "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + CodeRay HTML Encoder Example