Sha256: 43bc20f2e76cfb129567f2c741281ee45f43e18a5c5db5b433d158e3bf7b4b4b

Contents?: true

Size: 1.55 KB

Versions: 43

Compression:

Stored size: 1.55 KB

Contents

# A hack to make MaRuKu use UltraViolet for highlighting
# To specify the style to use use for example:
#     uv_style: amy
#     html_use_syntax: true
#     code_lang: ruby
# In the document header area.

require 'maruku'

module MaRuKu
  module Out
    module HTML
      def uv_highlight(source, lang, style)
        require 'uv'

        html = Uv.parse(source, 'xhtml', lang, lines = false, style)

        # Prepare <code> containing <pre>
        code = Document.new(html, :respect_whitespace => :all).root
        code.name = 'code'
        code.attributes['class'] = lang
        code.attributes['lang'] = lang

        # Prepare <pre>
        pre = Element.new('pre')
        pre << code
        pre.attributes['class'] = style
        pre
      rescue => ex
        puts ex
        to_html_code_using_pre(source)
      end

      def to_html_code
        source = self.raw_code
        use_syntax = get_setting(:html_use_syntax)
        uv_style = get_setting(:uv_style)

        lang = self.attributes[:lang] || @doc.attributes[:code_lang]
        lang ||= 'ruby' if attributes[:ruby]

        # we always use syntax highlighting, this is a doc wiki
        if lang and use_syntax
          element = uv_highlight(source, lang, uv_style)
        else
          element = to_html_code_using_pre(source)
        end

        color = get_setting(:code_background_color)

        if color != Globals[:code_background_color]
          element.attributes['style'] = "background-color: #{color};"
        end

        add_ws element
      end
    end # HTML
  end # Out
end # MaRuKu

Version data entries

43 entries across 43 versions & 5 rubygems

Version Path
Pistos-ramaze-2008.09 lib/ramaze/contrib/maruku_uv.rb
Pistos-ramaze-2008.12 lib/ramaze/contrib/maruku_uv.rb
Pistos-ramaze-2009.01 lib/ramaze/contrib/maruku_uv.rb
Pistos-ramaze-2009.02 lib/ramaze/contrib/maruku_uv.rb
Pistos-ramaze-2009.04.08 lib/ramaze/contrib/maruku_uv.rb
Pistos-ramaze-2009.06.12 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2008.09 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2008.10 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2008.12 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.01 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.04.01 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.04.08 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.04.18 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.04.22 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.04 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.05.08 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.05 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.06.04 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.06.12 lib/ramaze/contrib/maruku_uv.rb
manveru-ramaze-2009.06 lib/ramaze/contrib/maruku_uv.rb