class PseudoHiki::BlockParser
Constants
- HEAD_TO_LEAF
- ID_TAG_PAT
- IRREGULAR_LEAFS
- NUMBER_OF_IRREGULAR_LEAFS
- PARENT_NODE
- PLUGIN_BEGIN
- PLUGIN_END
- REGULAR_HEADS
- VERBATIM_BEGIN
- VERBATIM_END
Attributes
auto_linker[RW]
auto_linker[R]
stack[R]
Public Class Methods
assign_head_re(head_to_leaf_table)
click to toggle source
# File lib/pseudohiki/blockparser.rb, line 297 def self.assign_head_re(head_to_leaf_table) irregular_head_pats, regular_heads = [], [] head_to_leaf_table.each do |head, leaf| leaf_is_irregular = IRREGULAR_LEAFS.include?(leaf) escaped_head = leaf_is_irregular ? head : Regexp.escape(head) head_pat = leaf.with_depth? ? "#{escaped_head}+" : "#{escaped_head}" leaf.head_re = /\A#{head_pat}/ irregular_head_pats.push "(#{escaped_head})" if leaf_is_irregular regular_heads.push head unless leaf_is_irregular end return /\A(?:#{irregular_head_pats.join('|')})/, regular_heads end
assign_node_id(leaf, node)
click to toggle source
# File lib/pseudohiki/blockparser.rb, line 20 def self.assign_node_id(leaf, node) # return unless tree[0].kind_of? Array ** block_leaf:[inline_node:[token or inline_node]] head = leaf[0] return unless head.kind_of? String if m = ID_TAG_PAT.match(head) node.node_id = m[1] leaf[0] = head.sub(ID_TAG_PAT, "".freeze) end node end
new(auto_linker=BlockParser.auto_linker)
click to toggle source
# File lib/pseudohiki/blockparser.rb, line 312 def initialize(auto_linker=BlockParser.auto_linker) root_node = BlockNode.new def root_node.breakable?(breaker) false end @stack = BlockStack.new(root_node) @auto_linker = auto_linker || AutoLink::URL end
parse(lines, tmp_auto_linker=BlockParser.auto_linker)
click to toggle source
# File lib/pseudohiki/blockparser.rb, line 35 def self.parse(lines, tmp_auto_linker=BlockParser.auto_linker) parser = new(tmp_auto_linker) parser.read_lines(lines) parser.stack.tree end
Public Instance Methods
breakable?(breaker)
click to toggle source
# File lib/pseudohiki/blockparser.rb, line 321 def breakable?(breaker) @stack.current_node.breakable?(breaker) end
read_lines(lines)
click to toggle source
# File lib/pseudohiki/blockparser.rb, line 332 def read_lines(lines) each_line = lines.respond_to?(:each_line) ? :each_line : :each lines.send(each_line) {|line| @stack.current_node.add_leaf(line, self) } @stack.pop end
select_leaf_type(line)
click to toggle source
# File lib/pseudohiki/blockparser.rb, line 325 def select_leaf_type(line) matched = IRREGULAR_HEAD_PAT.match(line) 1.upto(NUMBER_OF_IRREGULAR_LEAFS) {|i| return IRREGULAR_LEAFS[i] if matched[i] } if matched REGULAR_HEADS.each {|head| return HEAD_TO_LEAF[head] if line.start_with?(head) } ParagraphLeaf end