Class: PublifyApp::Textfilter::Code
- Inherits:
-
TextFilterPlugin::MacroPre
- Object
- TextFilterPlugin::MacroPre
- PublifyApp::Textfilter::Code
- Defined in:
- lib/publify_app/textfilter_code.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ css: :class, wrap: :span, line_numbers: nil, tab_width: 2, bold_every: 5, hint: false, line_number_start: 1 }.freeze
Class Method Summary collapse
Class Method Details
.help_text ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/publify_app/textfilter_code.rb', line 18 def self.help_text %{ You can use `<publify:code>` to include syntax-highlighted code blocks. Example: <publify:code lang="ruby"> class Foo def bar "abcde" end end </publify:code> This uses the Ruby [Syntax](http://coderay.rubychan.de) module. Options: * **lang**. Sets the programming language. Currently supported languages are *C, C++ (*), CSS, Delphi, diff, Groovy (*), HTML, Java, JavaScript, JSON, PHP (*), Python (*), RHTML, Ruby, Scheme, SQL (*), XHTML, XML, YAML. * Only available in CodeRay >= 0.9.1 * **linenumber**. Turns on line numbering. Use `linenumber="true"` to enable. * **title**. Adds a title block to the top of the code block. } end |
.macrofilter(attrib, text = '') ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/publify_app/textfilter_code.rb', line 41 def self.macrofilter(attrib, text = '') lang = attrib['lang'] title = attrib['title'] = if attrib['linenumber'] == 'true' DEFAULT_OPTIONS.merge(line_numbers: :table, wrap: :div) else DEFAULT_OPTIONS end text = text.to_s.delete("\r").gsub(/\A\n/, '').chomp begin text = CodeRay.scan(text, lang.downcase.to_sym).span() rescue text = HTMLEntities.new('xhtml1').encode(text) end text = "<notextile>#{text}</notextile>" titlecode = if title "<div class=\"codetitle\">#{title}</div>" else '' end "<div class=\"CodeRay\"><pre>#{titlecode}#{text}</pre></div>" end |