class Qiita::Markdown::Filters::CustomBlock::Note

Constants

ALLOWED_TYPES
DEFAULT_TYPE

Attributes

node[R]
type[R]

Public Class Methods

new(node, type) click to toggle source

@param node [Nokogiri::XML::Node] @param type [String, nil]

# 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

Public Instance Methods

convert() click to toggle source
# 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

Private Instance Methods

icon() click to toggle source
# File lib/qiita/markdown/filters/custom_block.rb, line 56
def icon
  {
    info: %(<span class="fa fa-fw fa-check-circle"></span>),
    warn: %(<span class="fa fa-fw fa-exclamation-circle"></span>),
    alert: %(<span class="fa fa-fw fa-times-circle"></span>),
  }[type.to_sym]
end