Module: MDOM

Defined in:
lib/mdom.rb,
lib/mdom/node.rb,
lib/mdom/nodes.rb,
lib/mdom/parser.rb,
lib/mdom/builder.rb,
lib/mdom/version.rb,
lib/mdom/serializer.rb,
lib/mdom/inline_parser.rb

Defined Under Namespace

Modules: InlineContainer, InlineParser, Parser, Types Classes: BlockNode, Blockquote, Builder, Code, CodeBlock, Document, Emphasis, Hardbreak, Heading, Hrule, Image, InlineNode, Link, List, ListItem, Node, Paragraph, Serializer, Softbreak, Strong, Text

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.allocate_node(type, **attrs) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/mdom/nodes.rb', line 110

def self.allocate_node(type, **attrs)
  case type
  when Types::HEADING then Heading.new(attrs.fetch(:level, 1), attributes: attrs[:attributes])
  when Types::PARAGRAPH then Paragraph.new
  when Types::LIST then List.new(**attrs)
  when Types::LIST_ITEM then ListItem.new
  when Types::BLOCKQUOTE then Blockquote.new
  when Types::HRULE then Hrule.new
  else
    BlockNode.new(type, attributes: attrs)
  end
end

.build(&block) ⇒ Object



257
258
259
# File 'lib/mdom/builder.rb', line 257

def self.build(&block)
  Builder.build(&block)
end

.parse(source) ⇒ Object

Public entry point: parse source into an MDOM::Document tree.



282
283
284
# File 'lib/mdom/parser.rb', line 282

def self.parse(source)
  Parser.read(source)
end

.serialize(node) ⇒ Object

Serialize a node (or subtree) back to a Markdown string.



13
14
15
# File 'lib/mdom.rb', line 13

def self.serialize(node)
  Serializer.serialize(node)
end