lib/erbook/to_xhtml.rb
##
# Adds syntax coloring to <code> elements in this string.
#
# Each <code> element is annotated with a class="line"
# or a class="para" attribute, according to whether it
# spans a single line or multiple lines of code.
#
# In the latter case, the <code> element is replaced
# with a <pre> element so that its multi-line body
# appears correctly in text-mode web browsers.
#
# If a <code> element has a lang="..." attribute,
# then that attribute's value is considered to be
# the programming language for which appropriate
# syntax coloring should be applied.  Otherwise,
# the programming language is assumed to be ruby.
#
Adds syntax coloring to  elements in this string.
Each  element is annotated with a class="line"
or a class="para" attribute, according to whether it
spans a single line or multiple lines of code.

In the latter case, the  element is replaced
with a  element so that its multi-line body
appears correctly in text-mode web browsers.

If a  element has a lang="..." attribute,
then that attribute's value is considered to be
the programming language for which appropriate
syntax coloring should be applied.  Otherwise,
the programming language is assumed to be ruby.
Adds syntax coloring to elements in this string . Each element is annotated with a class = " line " or a class = " para " attribute according to whether it spans a single line or multiple lines of code . In the latter case the element is replaced with a element so that its multi - line body appears correctly in text - mode web browsers . If a element has a lang = " ... " attribute then that attribute ' s value is considered to be the programming language for which appropriate syntax coloring should be applied . Otherwise the programming language is assumed to be ruby .
def thru_coderay 
    gsub %r{<(code)(.*?)>(.*?)</\1>}m do
      elem, atts, code = $1, $2, CGI.unescapeHTML($3).sub(/\A\r?\n/, '')
      lang_regexp = /\blang=('|")(.*?)\1/io
      lang = atts[lang_regexp, 2]
      lang = :ruby if lang !~ /\S/
      atts.sub! lang_regexp, %{lang="#{lang}"}
      body = CodeRay.scan(code, lang).html(:css => :style)
      if code =~ /\n/
        span = :para
        head = "<ins><pre"
        tail = "</pre></ins>"
      else
        span = :line
        head = "<#{elem}"
        tail = "</#{elem}>"
      end
      unless atts.sub!(/\b(class=('|"))(.*?\2)/){ $1 + span + ' ' + $3 }
        atts << %{ class="#{span}"}
      end
      %{#{head}#{atts}>#{body}#{tail}}
    end
  end
def thru_coderay gsub %r{ <(code)(.*?)>(.*?)</ \1 > }m do elem , atts , code = $1 , $2 , CGI . unescapeHTML ( $3 ) . sub ( / \A \r ? \n / , '' ) lang_regexp = / \b lang=('|")(.*?) \1 /io lang = atts [ lang_regexp , 2 ] lang = :ruby if lang !~ / \S / atts . sub! lang_regexp , %{lang="#{lang}"} body = CodeRay . scan ( code , lang ) . html ( :css => :style ) if code =~ / \n / span = :para head = "<ins><pre" tail = "</pre></ins>" else span = :line head = "<#{elem}" tail = "</#{elem}>" end unless atts . sub! ( / \b (class=('|"))(.*? \2 ) / ) { $1 + span + ' ' + $3 } atts << %{ class="#{span}"} end %{#{head}#{atts}>#{body}#{tail}} end end
Adds syntax coloring to <code> elements in this string.
Adds syntax coloring to <code > elements in this string .
#:nodoc: