Class: Wikitxt::Parser::Block
- Inherits:
-
Object
- Object
- Wikitxt::Parser::Block
- Defined in:
- lib/wikitxt/parser.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(text) ⇒ Block
constructor
A new instance of Block.
Constructor Details
#initialize(text) ⇒ Block
Returns a new instance of Block.
10 11 12 |
# File 'lib/wikitxt/parser.rb', line 10 def initialize(text) @text = text end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/wikitxt/parser.rb', line 8 def text @text end |
Instance Method Details
#body ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wikitxt/parser.rb', line 14 def body b = BodyNode.new in_pre = false text.lines.each do |line| if line == "---\n" node = !in_pre ? PreStartNode.new : PreEndNode.new b.children << node in_pre = !in_pre next end if in_pre b.children << PreNode.new(text: line) next end if match = line.match(/^(?<indent> {2,})(?<text>.*)$/) b.children << ListNode.new(text: match[:text], indent: match[:indent].length - 2) next end b.children << ParagraphNode.new(text: line.chomp) end b end |