Class: Jekyll::Tags::HighlightBlock

### Home Classes Methods

### In Files

- lib/jekyll/tags/highlight.rb

### Parent

Liquid::Block

### Methods

- ::new
- #add_code_tags
- #render
- #render_codehighlighter
- #render_pygments

### Included Modules

- Liquid::StandardFilters

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Jekyll
- Jekyll::Command
- Jekyll::Commands
- Jekyll::Commands::Build
- Jekyll::Commands::Doctor
- Jekyll::Commands::New
- Jekyll::Commands::Serve
- Jekyll::Configuration
- Jekyll::Converter
- Jekyll::Converters
- Jekyll::Converters::Identity
- Jekyll::Converters::Markdown
- Jekyll::Converters::Markdown::KramdownParser
- Jekyll::Converters::Markdown::MarukuParser
- Jekyll::Converters::Markdown::RDiscountParser
- Jekyll::Converters::Markdown::RedcarpetParser
- Jekyll::Converters::Markdown::RedcarpetParser::CommonMethods
- Jekyll::Converters::Markdown::RedcarpetParser::WithPygments
- Jekyll::Converters::Markdown::RedcarpetParser::WithoutPygments
- Jekyll::Converters::Textile
- Jekyll::Convertible
- Jekyll::Deprecator
- Jekyll::Draft
- Jekyll::Excerpt
- Jekyll::FatalException
- Jekyll::Filters
- Jekyll::Generator
- Jekyll::Generators
- Jekyll::Generators::Pagination
- Jekyll::GistTag
- Jekyll::Layout
- Jekyll::Page
- Jekyll::Pager
- Jekyll::Plugin
- Jekyll::Post
- Jekyll::RelatedPosts
- Jekyll::Site
- Jekyll::Site::Cleaner
- Jekyll::StaticFile
- Jekyll::Stevenson
- Jekyll::Tags
- Jekyll::Tags::HighlightBlock
- Jekyll::Tags::IncludeTag
- Jekyll::Tags::PostComparer
- Jekyll::Tags::PostUrl
- Jekyll::URL
- Date
- Enumerable
- Hash
- Object

No matching classes.

# Jekyll::Tags::HighlightBlock

### Constants

SYNTAX

  The regular expression syntax checker. Start with the language specifier. Follow that by zero or more space separated options that take one of two forms:

  1. name

  2. name=value

### Public Class Methods

new(tag_name, markup, tokens) click to toggle source

    # File lib/jekyll/tags/highlight.rb, line 14
    def initialize(tag_name, markup, tokens)
      super
      if markup.strip =~ SYNTAX
        @lang = $1
        @options = {}
        if defined?($2) && $2 != ''
          $2.split.each do |opt|
            key, value = opt.split('=')
            if value.nil?
              if key == 'linenos'
                value = 'inline'
              else
                value = true
              end
            end
            @options[key] = value
          end
        end
      else
        raise SyntaxError.new Syntax Error in tag 'highlight' while parsing the following markup:  #{markup}Valid syntax: highlight <lang> [linenos]
      end
    end

### Public Instance Methods

add_code_tags(code, lang) click to toggle source

    # File lib/jekyll/tags/highlight.rb, line 75
    def add_code_tags(code, lang)
      # Add nested <code> tags to code blocks
      code = code.sub(/<pre>/,'<pre><code class="' + lang + '">')
      code = code.sub(/<\/pre>/,"</code></pre>")
    end

render(context) click to toggle source

    # File lib/jekyll/tags/highlight.rb, line 43
    def render(context)
      if context.registers[:site].pygments
        render_pygments(context, super)
      else
        render_codehighlighter(context, super)
      end
    end

render_codehighlighter(context, code) click to toggle source

    # File lib/jekyll/tags/highlight.rb, line 66
    def render_codehighlighter(context, code)
      #The div is required because RDiscount blows ass
        <div>    <pre><code class='#{@lang}'>#{h(code).strip}</code></pre>  </div>
    end

render_pygments(context, code) click to toggle source

    # File lib/jekyll/tags/highlight.rb, line 51
    def render_pygments(context, code)
      require 'pygments'

      @options[:encoding] = 'utf-8'

      output = add_code_tags(
        Pygments.highlight(code, :lexer => @lang, :options => @options),
        @lang
      )

      output = context["pygments_prefix"] + output if context["pygments_prefix"]
      output = output + context["pygments_suffix"] if context["pygments_suffix"]
      output
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.