Class: HtmlToProsemirror::Nodes::CodeBlock

Inherits:
Node
  • Object
show all
Defined in:
lib/html_to_prosemirror/nodes/code_block.rb

Instance Attribute Summary

Attributes inherited from Node

#type, #wrapper

Instance Method Summary collapse

Methods inherited from Node

#initialize

Constructor Details

This class inherits a constructor from HtmlToProsemirror::Nodes::Node

Instance Method Details

#dataObject



9
10
11
12
13
14
# File 'lib/html_to_prosemirror/nodes/code_block.rb', line 9

def data
  block = { type: "code_block" }
  lang = get_language
  block.merge({attrs: { language: lang } }) if lang
  block
end

#get_languageObject



16
17
18
19
20
21
22
# File 'lib/html_to_prosemirror/nodes/code_block.rb', line 16

def get_language
  lang = @node.attribute('class')
  if (lang && lang.value)
    return lang.value.gsub("/^language-/", "")
  end
  return nil
end

#matchingObject



5
6
7
# File 'lib/html_to_prosemirror/nodes/code_block.rb', line 5

def matching
  @node.name === 'code' && @node.parent.name === 'pre'
end