class Polites::Block
A block represents a structural element in a Polites
document, mapping to block-level elements in HTML. Examples include paragraphs and headings.
Blocks may technically contain other blocks, as well as {Text} and {Span} elements.
Public Class Methods
build(children = [], kind: 'paragraph', level: 0, syntax: nil)
click to toggle source
Build the proper kind of span from the given arguments.
@param [Array<Node>] children @param [String] kind the type Polites
has given to this node. @param [Fixnum] level the indentation level used by list items. @param [String] syntax the syntax attribute used in code blocks. @raise [ParseError] when encountering unexpected `kind` @return [Span]
# File lib/polites/block.rb, line 21 def self.build(children = [], kind: 'paragraph', level: 0, syntax: nil) case kind when 'heading1' Heading1.new(children) when 'heading2' Heading2.new(children) when 'heading3' Heading3.new(children) when 'heading4' Heading4.new(children) when 'heading5' Heading5.new(children) when 'heading6' Heading6.new(children) when 'paragraph' Paragraph.new(children) when 'unorderedList' UnorderedList.new(children, level) when 'orderedList' OrderedList.new(children, level) when 'blockquote' Blockquote.new(children) when 'divider' Divider.new(children) when 'codeblock' CodeBlock.new(children, syntax) else raise ParseError, "unknown block type #{kind.inspect}" end end