Class: Riven::Markup::CodeBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/riven/markup/code_block.rb

Overview

Class that contains data for a code block

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, language, code) ⇒ CodeBlock

Returns a new instance of CodeBlock.



11
12
13
# File 'lib/riven/markup/code_block.rb', line 11

public def initialize(id, language, code)
  @id, @language, @code = id, language, code
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/riven/markup/code_block.rb', line 9

def code
  @code
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/riven/markup/code_block.rb', line 9

def id
  @id
end

#languageObject (readonly)

Returns the value of attribute language.



9
10
11
# File 'lib/riven/markup/code_block.rb', line 9

def language
  @language
end

Instance Method Details

#highlightedString

Returns the code with syntax highlightning

Returns:

  • (String)


18
19
20
21
22
23
24
# File 'lib/riven/markup/code_block.rb', line 18

public def highlighted
  if @language
    CodeRay.scan(@code, @language).div(tab_width: 4, css: :class)
  else
    CodeRay.scan(@code, :text).div(tab_width: 4, css: :class)
  end
end