Class: Qiita::Markdown::Filters::CustomBlock::Note

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita/markdown/filters/custom_block.rb

Constant Summary collapse

ALLOWED_TYPES =
%w[info warn alert].freeze
DEFAULT_TYPE =
"info"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, type) ⇒ Note

Returns a new instance of Note.

Parameters:

  • node (Nokogiri::XML::Node)
  • type (String, nil)


40
41
42
43
# File 'lib/qiita/markdown/filters/custom_block.rb', line 40

def initialize(node, type)
  @node = node
  @type = ALLOWED_TYPES.include?(type) ? type : DEFAULT_TYPE
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



33
34
35
# File 'lib/qiita/markdown/filters/custom_block.rb', line 33

def node
  @node
end

#typeObject (readonly)

Returns the value of attribute type.



33
34
35
# File 'lib/qiita/markdown/filters/custom_block.rb', line 33

def type
  @type
end

Instance Method Details

#convertObject



45
46
47
48
49
50
51
52
# File 'lib/qiita/markdown/filters/custom_block.rb', line 45

def convert
  children = node.children
  children.each(&:unlink)
  node.add_child("<div></div>")
  node.children.first.children = children
  node["class"] = "note #{type}"
  node.children.first.add_previous_sibling(icon) if icon
end