summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/coderay/encoders/helpers/html_css.rb65
-rw-r--r--lib/coderay/encoders/helpers/html_output.rb20
-rw-r--r--lib/coderay/encoders/html.rb3
-rw-r--r--lib/coderay/encoders/span.rb1
4 files changed, 33 insertions, 56 deletions
diff --git a/lib/coderay/encoders/helpers/html_css.rb b/lib/coderay/encoders/helpers/html_css.rb
index f9cadf7..5c39527 100644
--- a/lib/coderay/encoders/helpers/html_css.rb
+++ b/lib/coderay/encoders/helpers/html_css.rb
@@ -20,7 +20,7 @@ module CodeRay module Encoders
private
- CSS_CLASS = /
+ CSS_CLASS_PATTERN = /
( (?: # $1 = classes
\s* \. [-\w]+
)+ )
@@ -31,8 +31,8 @@ module CodeRay module Encoders
( . ) # $3 = error
/mx
def parse stylesheet
- stylesheet.scan CSS_CLASS do |classes, style, error|
- raise "CSS parse error: '#{error}' not recognized" if error
+ stylesheet.scan CSS_CLASS_PATTERN do |classes, style, error|
+ raise "CSS parse error: '#{error.inspect}' not recognized" if error
styles = classes.scan(/[-\w]+/)
cl = styles.pop
@classes[cl] ||= Hash.new
@@ -41,48 +41,31 @@ module CodeRay module Encoders
end
MAIN = <<-'MAIN'
-.code {
- background-color: #FAFAFA;
- border: 1px solid #D1D7DC;
+.CodeRay {
+ background-color: #f8f8f8;
+ border: 1px solid silver;
font-family: 'Courier New', 'Terminal', monospace;
- font-size: 10pt;
color: black;
- vertical-align: top;
- text-align: left;
- padding: 0px;
}
-span.code { white-space: pre; }
-.code tt { font-weight: bold; }
-.code pre {
- font-size: 10pt;
- margin: 0px 5px;
-}
-.code .code_table {
- margin: 0px;
-}
-.code .line_numbers {
- margin: 0px;
- background-color:#DEF; color: #777;
- vertical-align: top;
+.CodeRay pre { margin: 0px; }
+
+div.CodeRay { }
+
+span.CodeRay { white-space: pre; border: 0; }
+
+table.CodeRay { border-collapse: collapse; }
+table.CodeRay td { padding: 2px 4px; vertical-align: top; }
+
+.CodeRay .line_numbers {
+ background-color: #def;
+ color: gray;
text-align: right;
}
-.code .code_cell {
- width: 100%;
- background-color:#FAFAFA;
- color: black;
- vertical-align: top;
- text-align: left;
-}
-.code .no {
- background-color:#DEF;
- color: #777;
- padding: 0px 5px;
- font-weight: normal;
- font-style: normal;
-}
-
-.code tt { display: hidden; }
+.CodeRay .line_numbers tt { font-weight: bold; }
+.CodeRay .code {
+}
+.CodeRay .code pre { overflow: auto; }
MAIN
TOKENS = <<-'TOKENS'
@@ -93,7 +76,7 @@ span.code { white-space: pre; }
.bi { color:#509; font-weight:bold; }
.c { color:#888; }
-.ch { color:#04D; /* background-color:#f0f0ff; */ }
+.ch { color:#04D; }
.ch .k { color:#04D; }
.ch .dl { color:#039; }
@@ -155,7 +138,7 @@ span.code { white-space: pre; }
.xt { color:#444; }
TOKENS
- DEFAULT_STYLESHEET = MAIN + TOKENS
+ DEFAULT_STYLESHEET = MAIN + TOKENS.gsub(/^(?!$)/, '.CodeRay ')
end
end
diff --git a/lib/coderay/encoders/helpers/html_output.rb b/lib/coderay/encoders/helpers/html_output.rb
index 692e810..c873896 100644
--- a/lib/coderay/encoders/helpers/html_output.rb
+++ b/lib/coderay/encoders/helpers/html_output.rb
@@ -200,22 +200,15 @@ module CodeRay
DIV, DIV_TABLE, PAGE =
<<-`DIV`, <<-`DIV_TABLE`, <<-`PAGE`
-
-<div class="code">
-<pre><%CONTENT%></pre>
+<div class="CodeRay">
+ <div class="code"><pre><%CONTENT%></pre></div>
</div>
DIV
-
-<div class="code">
- <table class="code_table">
- <tr>
- <td class="line_numbers"><pre><%LINE_NUMBERS%></pre></td>
- <td class="code_cell"><div class="nowrap"><pre><%CONTENT%></pre></div></td>
- </tr>
- </table>
-</div>
+<table class="CodeRay"> <tr>
+ <td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre><%LINE_NUMBERS%></pre></td>
+ <td class="code"><pre title="double click to expand" ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><%CONTENT%></pre></td>
+</tr> </table>
DIV_TABLE
-<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de">
@@ -227,6 +220,7 @@ module CodeRay
</style>
</head>
<body style="background-color: white;">
+
<%CONTENT%>
</body>
</html>
diff --git a/lib/coderay/encoders/html.rb b/lib/coderay/encoders/html.rb
index 69b6e22..58fdd86 100644
--- a/lib/coderay/encoders/html.rb
+++ b/lib/coderay/encoders/html.rb
@@ -15,7 +15,8 @@ module Encoders
:css => :class,
:wrap => :page,
- :line_numbers => :table,
+
+ :line_numbers => nil,
:line_numbers_offset => 1,
:bold_every => 10,
}
diff --git a/lib/coderay/encoders/span.rb b/lib/coderay/encoders/span.rb
index a7715f4..abd8a39 100644
--- a/lib/coderay/encoders/span.rb
+++ b/lib/coderay/encoders/span.rb
@@ -10,7 +10,6 @@ module CodeRay module Encoders
DEFAULT_OPTIONS = HTML::DEFAULT_OPTIONS.merge({
:css => :style,
:wrap => :span,
- :line_numbers => nil,
})
end