Sha256: aa130546b399ca6e90c029df162ab5460e5059bd046e9b667672aa24d0c246cf

Contents?: true

Size: 1.9 KB

Versions: 46

Compression:

Stored size: 1.9 KB

Contents

# -*- coding: utf-8 -*-
#
# coderay.rb - easy syntax highlighting for selected languages
#  refer to the URL below.
#  http://coderay.rubychan.de/
#
# Copyright (C) 2013, tamoot <tamoot+tdiary@gmail.com>
# You can redistribute it and/or modify it under GPL2.
#

require 'cgi'
require 'erb'
require 'coderay'

@coderay_default_css ||= ::CodeRay::Encoders[:html]::CSS.new(:default).stylesheet

def coderay(lang, text, options = {})
   html = ::CodeRay.scan(text, lang).html(:line_numbers => :inline, :bold_every => false, :line_number_anchors => false)
   %Q|<div class="CodeRay"><pre>#{html}</pre></div>|
end

add_header_proc do
   coderay_css = ''
   if @conf['coderay.css.url'] && @conf['coderay.css.url'].size > 0
      coderay_css = %Q|<link rel="stylesheet" href="#{h @conf['coderay.css.url']}" type="text/css" media="all">|
   else
      coderay_css = <<-STYLE
   <style type="text/css"><!--
   #{@coderay_default_css}
   -->
   </style>
STYLE
   end

   coderay_css
end

add_conf_proc( 'coderay', 'CodeRay' ) do
   if @mode == 'saveconf' then
      @conf['coderay.css.url'] = @cgi.params['coderay.css.url'][0]

   end

   coderay_conf = <<-HTML
   <h3 class="subtitle">custom style</h3>

   <p>The stylesheet path is used instead of CodeRay default. </p>
   <p>Path: <input name="coderay.css.url" value="#{h @conf['coderay.css.url']}" size="70"></p>
   <pre>
   sample:
   #{CGI::escape_html('<link rel="stylesheet" href="/your/tdiary/path/coderay.css" type="text/css" media="all">')}
   </pre>


   <h4>Print default stylesheet of CodeRay</h4>
   <p>1. The coderay command installed along with the CodeRay gem can print out a stylesheet for you.</p>
   <pre>
   bundle exec coderay stylesheet > /your/tdiary/path/coderay.css
   </pre>
   <p>2. Edit your stylesheet and modify permissions.</p>

   HTML

   coderay_conf

end

# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:
# vim: ts=3

Version data entries

46 entries across 40 versions & 2 rubygems

Version Path
tdiary-contrib-5.3.0 plugin/coderay.rb
tdiary-contrib-5.2.4 plugin/coderay.rb
tdiary-contrib-5.2.3 plugin/coderay.rb
tdiary-contrib-5.2.2 plugin/coderay.rb
tdiary-contrib-5.2.1 plugin/coderay.rb
tdiary-contrib-5.2.0 plugin/coderay.rb
tdiary-contrib-5.1.7 plugin/coderay.rb
tdiary-contrib-5.1.6 plugin/coderay.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/plugin/coderay.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/bundler/gems/tdiary-contrib-d1e41204db13/plugin/coderay.rb
tdiary-contrib-5.1.5 plugin/coderay.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-contrib-5.1.4/plugin/coderay.rb
tdiary-contrib-5.1.4 plugin/coderay.rb
tdiary-contrib-5.1.3 plugin/coderay.rb
tdiary-contrib-5.1.2 plugin/coderay.rb
tdiary-contrib-5.1.1 plugin/coderay.rb
tdiary-contrib-5.1.0 plugin/coderay.rb
tdiary-contrib-5.0.13 plugin/coderay.rb
tdiary-contrib-5.0.12 plugin/coderay.rb
tdiary-contrib-5.0.11 plugin/coderay.rb