class Jekyll::PseudoCodeB::HtmlBrush

Public Instance Methods

comment(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 54
def comment(txt)
  "<span class='comment'>/* #{txt.strip} */</span>"
end
fn(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 22
def fn(txt)
  "<span class='function'>#{txt}</span>"
end
indent(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 62
def indent(txt)
  txt.gsub! "\t", '   '
  "<span class='indent'>#{txt}</span>"
end
is_numeric?(s) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 7
def is_numeric?(s)
  begin
    Float(s)
  rescue
    false # not numeric
  else
    true # numeric
  end
end
math(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 96
def math(txt)
  symbol = case txt
  when 'pi' then '&#x3C0;'
  when 'tau' then '&#x1d6d5;'
  when 'infinity' then '&#x221e;'
  else txt
  end
  # FIXME: html conversion for some operators
  "<span class='math-symbol'>#{symbol}</span>"
end
number(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 30
def number(txt)
  "<span class='numeric'>#{txt}</span>"
end
objfn(obj, fnc) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 26
def objfn(obj, fnc)
  "<span class='variable'>#{obj}</span><span class='operator'>.</span><span class='function'>#{fnc}</span>"
end
op(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 67
def op(txt)
  symbol = case txt
  when '<' then '&#65308;'
  when '>' then '&#65310;'
  when '<=' then '&#x2264;'
  when '>=' then '&#x2265;'
  when '<-' then '&#x2190;'
  when '->' then '&#x2192;'
  when '<--' then '&#x27f5;'
  when '-->' then '&#x27f6;'
  when '<->' then '&#x2194;'
  when '<-->' then '&#x27f7;'
  when '*' then '&times;'
  when '[' then '&#65339;'
  when ']' then '&#65341;'
  when '!=' then '&#x2260;'
  when '<>' then '&#x2260;'
  when '=' then '&#x3d;'
  when ':=' then '&#x2254;'
  when '+' then '&#x2b;'
  when '-' then '-'
  when '/' then '/'
  when '==' then '&#xff1d;'
  else txt
  end
  # FIXME: html conversion for some operators
  "<span class='operator'>#{symbol}</span>"
end
plain(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 107
def plain(txt)
  "#{txt}"
end
special(txt, sub) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 34
def special(txt, sub)
  if sub
    "<span class='special'>#{txt}<sub>#{sub.slice(1,sub.size)}</sub></span>"
  else
    "<span class='special'>#{txt}</span>"
  end
end
string(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 58
def string(txt)
  "<span class='string'>#{txt}</span>"
end
sym(txt) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 17
def sym(txt)
  "<span class='symbol'>#{txt}</span>"
end
var(txt, sub) click to toggle source
# File lib/jekyll-pseudocode-b/html_brush.rb, line 42
def var(txt, sub)
  if sub
    "<span class='variable'>#{txt}<sub>#{sub.slice(1,sub.size)}</sub></span>"
  else
    if (is_numeric?(txt))
      "<span class='numeric'>#{txt}</span>"
    else
      "<span class='variable'>#{txt}</span>"
    end
  end
end