Class: Jekyll::PrismBlock
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Jekyll::PrismBlock
- Includes:
- Liquid::StandardFilters
- Defined in:
- lib/jekyll-prism-plugin.rb
Constant Summary collapse
- OPTIONS_SYNTAX =
%r{^([a-zA-Z0-9.+#-]+)((\s+\w+(=[0-9,-]+)?)*)$}
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ PrismBlock
constructor
A new instance of PrismBlock.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ PrismBlock
Returns a new instance of PrismBlock.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll-prism-plugin.rb', line 8 def initialize(tag_name, markup, tokens) super if markup.strip =~ OPTIONS_SYNTAX @lang = $1 if defined?($2) && $2 != '' = {} $2.split.each do |opt| key, value = opt.split('=') if value.nil? value = true end [key] = value end @options = else @options = { "linenos" => "" } end else raise SyntaxError.new("Syntax Error in 'prism' - Valid syntax: prism <lang> [linenos(='1-5')]") end end |
Instance Method Details
#render(context) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jekyll-prism-plugin.rb', line 30 def render(context) code = h(super).strip if @options["linenos"] == true @options["linenos"] = "1-#{code.lines.count}" end <<-HTML <div> <pre data-line='#{@options["linenos"]}'><code class='language-#{@lang}'>#{code}</code></pre> </div> HTML end |