Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switch to using CSS classes, bit of a cost in dumping the CSS into th…

…e top of the HTML file, but for sites which can relocate it, this dramatically improves the way things work. Also simplifies inverse!
  • Loading branch information...
commit d703a292c9c0ad67aa4989951238156c46f1b88c 1 parent e3ee855
@trejkaz authored
View
45 doc/example.css
@@ -0,0 +1,45 @@
+
+/* Example CSS file for styling the output. */
+
+.log { color: #B2B2B2; background-color: #000000; }
+.v { color: #000000; background-color:#B2B2B2; }
+
+.b { font-weight: bold; }
+.u { text-decoration: underline; }
+.m { font-family: monospace; }
+.f { /* find a way to do blinking, if you want it */ }
+
+.fnk, .bnk.v { color: #000000; }
+.fnr, .bnr.v { color: #B21717; }
+.fng, .bng.v { color: #17B217; }
+.fny, .bny.v { color: #B26717; }
+.fnb, .bnb.v { color: #1717B2; }
+.fnm, .bnm.v { color: #B217B2; }
+.fnc, .bnc.v { color: #17B2B2; }
+.fnw, .bnw.v { color: #B2B2B2; }
+.fik, .bik.v { color: #686868; }
+.fir, .bir.v { color: #FF5454; }
+.fig, .big.v { color: #54FF54; }
+.fiy, .biy.v { color: #FFFF54; }
+.fib, .bib.v { color: #5454FF; }
+.fim, .bim.v { color: #FF54FF; }
+.fic, .bic.v { color: #54FFFF; }
+.fiw, .biw.v { color: #FFFFFF; }
+
+.bnk, .fnk.v { background-color: #000000; }
+.bnr, .fnr.v { background-color: #B21717; }
+.bng, .fng.v { background-color: #17B217; }
+.bny, .fny.v { background-color: #B26717; }
+.bnb, .fnb.v { background-color: #1717B2; }
+.bnm, .fnm.v { background-color: #B217B2; }
+.bnc, .fnc.v { background-color: #17B2B2; }
+.bnw, .fnw.v { background-color: #B2B2B2; }
+.bik, .fik.v { background-color: #686868; }
+.bir, .fir.v { background-color: #FF5454; }
+.big, .fig.v { background-color: #54FF54; }
+.biy, .fiy.v { background-color: #FFFF54; }
+.bib, .fib.v { background-color: #5454FF; }
+.bim, .fim.v { background-color: #FF54FF; }
+.bic, .fic.v { background-color: #54FFFF; }
+.biw, .fiw.v { background-color: #FFFFFF; }
+
View
47 lib/ircformat/html_convertor.rb
@@ -5,25 +5,6 @@
module IrcFormat
class HtmlConvertor
- COLOR_MAPPINGS = {
- :nk => '#000000'.freeze, # dark black (black)
- :nr => '#B21717'.freeze, # dark red
- :ng => '#17B217'.freeze, # dark green
- :ny => '#B26717'.freeze, # dark yellow (orange)
- :nb => '#1717B2'.freeze, # dark blue
- :nm => '#B217B2'.freeze, # dark magenta
- :nc => '#17B2B2'.freeze, # dark cyan
- :nw => '#B2B2B2'.freeze, # dark white (light grey)
- :ik => '#686868'.freeze, # light black (dark grey)
- :ir => '#FF5454'.freeze, # light red
- :ig => '#54FF54'.freeze, # light green
- :iy => '#FFFF54'.freeze, # light yellow
- :ib => '#5454FF'.freeze, # light blue
- :im => '#FF54FF'.freeze, # light magenta
- :ic => '#54FFFF'.freeze, # light cyan
- :iw => '#FFFFFF'.freeze, # light white (white)
- }.freeze
-
def initialize(defaultfg, defaultbg, code_parsers = [:mirc])
@defaultfg = defaultfg
@defaultbg = defaultbg
@@ -41,18 +22,16 @@ def initialize(defaultfg, defaultbg, code_parsers = [:mirc])
end
end
- def to_css(format_state)
- fgcolor, bgcolor = format_state.fgcolor, format_state.bgcolor
- if format_state.inverse
- fgcolor, bgcolor = (bgcolor || @defaultbg), (fgcolor || @defaultfg)
- end
- styles = []
- styles << "color: #{COLOR_MAPPINGS[fgcolor]};" if fgcolor
- styles << "background-color: #{COLOR_MAPPINGS[bgcolor]};" if bgcolor
- styles << "font-weight: bold;" if format_state.bold
- styles << "text-decoration: underline;" if format_state.underline
- styles << "font-family: monospaced;" if format_state.monospace
- return styles.empty? ? nil : styles.join(' ')
+ def to_css_classes(state)
+ classes = []
+ classes << "f#{state.fgcolor}" if state.fgcolor
+ classes << "b#{state.bgcolor}" if state.bgcolor
+ classes << "v" if state.inverse
+ classes << "b" if state.bold
+ classes << "u" if state.underline
+ classes << "m" if state.monospace
+ classes << "f" if state.blink
+ return classes.empty? ? nil : classes.join(' ')
end
def escape_html(string)
@@ -64,9 +43,9 @@ def irc_to_html(string)
string.each_line do |line|
IrcFormat::Parser.new(@code_parsers).parse_formatted_string(line).each do |fragment|
text = self.escape_html(fragment[1])
- css = self.to_css(fragment[0])
- if css
- result += "<span style=\"#{css}\">#{text}</span>"
+ classes = self.to_css_classes(fragment[0])
+ if classes
+ result += "<span class=\"#{classes}\">#{text}</span>"
else
result += text
end
View
14 test/test_irssi.rb
@@ -9,19 +9,19 @@ def test_plain_string
end
def test_blink
- # TODO: Implement blinking. Or decide not to...
+ inout("plain \004ablink\004a plain", 'plain <span class="f">blink</span> plain')
end
def test_underline
- inout("plain \004bunderline\004b plain", 'plain <span style="text-decoration: underline;">underline</span> plain')
+ inout("plain \004bunderline\004b plain", 'plain <span class="u">underline</span> plain')
end
def test_bold
- inout("plain \004cbold\004c plain", 'plain <span style="font-weight: bold;">bold</span> plain')
+ inout("plain \004cbold\004c plain", 'plain <span class="b">bold</span> plain')
end
def test_inverse
- inout("plain \004dinverse\004d plain", 'plain <span style="color: #FFFFFF; background-color: #000000;">inverse</span> plain')
+ inout("plain \004dinverse\004d plain", 'plain <span class="v">inverse</span> plain')
end
def test_indent
@@ -33,7 +33,7 @@ def test_indent_func
end
def test_reset
- inout("plain \004cbold\004g plain", 'plain <span style="font-weight: bold;">bold</span> plain')
+ inout("plain \004cbold\004g plain", 'plain <span class="b">bold</span> plain')
end
def test_clrtoeol
@@ -41,11 +41,11 @@ def test_clrtoeol
end
def test_monospace
- inout("plain \004imonospace\004g plain", 'plain <span style="font-family: monospaced;">monospace</span> plain')
+ inout("plain \004imonospace\004g plain", 'plain <span class="m">monospace</span> plain')
end
def test_color
- inout("\00400small bombs", '<span style="color: #000000; background-color: #000000;">small bombs</span>')
+ inout("\00400small bombs", '<span class="fnk bnk">small bombs</span>')
end
def inout(input, expected_output)
View
14 test/test_mirc.rb
@@ -9,23 +9,27 @@ def test_plain_string
end
def test_color
- inout("\0031,1small bombs", '<span style="color: #000000; background-color: #000000;">small bombs</span>')
+ inout("\0031,1small bombs", '<span class="fnk bnk">small bombs</span>')
end
def test_color_reset
- inout("Some \0034red\003 text", 'Some <span style="color: #FF5454;">red</span> text')
+ inout("Some \0034red\003 text", 'Some <span class="fir">red</span> text')
end
def test_bold
- inout("plain \002bold\002 plain", 'plain <span style="font-weight: bold;">bold</span> plain')
+ inout("plain \002bold\002 plain", 'plain <span class="b">bold</span> plain')
end
def test_underline
- inout("plain \037underline\037 plain", 'plain <span style="text-decoration: underline;">underline</span> plain')
+ inout("plain \037underline\037 plain", 'plain <span class="u">underline</span> plain')
+ end
+
+ def test_inverse
+ inout("plain \026inverse\026 plain", 'plain <span class="v">inverse</span> plain')
end
def test_reset
- inout("plain \002bold\017 plain", 'plain <span style="font-weight: bold;">bold</span> plain')
+ inout("plain \002bold\017 plain", 'plain <span class="b">bold</span> plain')
end
def inout(input, expected_output)
Please sign in to comment.
Something went wrong with that request. Please try again.