Class: OrgParse::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/org-parse/node.rb

Overview

syntax tree node

children is Node array

Node kind

  • ROOT

    RootNode

lines (StructParser)

  • SECTION

    SectionNode

  • HEADLINE

    HeadlineNode

  • FN_DEFINE

    footnote definition

  • VARIABLE

    VarNode

  • WHITELINE

    WhitelineNode

  • TEXTBLOCK

    TextlineNode’s list will become paragraph

  • TEXTLINE

    TextlineNode

  • QUOTE

    HTML quoted text

  • BLOCK

    BlockNode (verse, example, src, html, …)

  • UNORDERED_LIST

    Unorderd list <UL>

  • ENUMLIST

    Ordered list <OL>

  • DESCLIST

    Description list <DL>

  • LISTITEM

    ListitemNode

  • TABLE

    TableNode

  • TABLE_SEP

    separator between th and td

  • TABLE_ROW

    TableRowNode

inlines (InlineParser)
  • BOLD

    bold

  • ITALIC

    italic

  • UNDER_LINE

    under line

  • VERBATIM

    verbatim

  • STRIKE_THROUGH

    strike through

  • CODE

    code

  • LINK

    LinkNode 参照

  • QUOTE

    @<br/> , #+HTML … 等

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind = nil, children = [], value = nil) ⇒ Node

Returns a new instance of Node.



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/org-parse/node.rb', line 50

def initialize(kind = nil, children = [], value = nil)
  @kind = kind
  @children = children
  @value = value
  @done = false
  @parent = nil
  @verse = false
  @example = false
  @html = false
  @src = false
end

Instance Attribute Details

#childrenObject

child nodes



44
45
46
# File 'lib/org-parse/node.rb', line 44

def children
  @children
end

#kindObject

Node type



42
43
44
# File 'lib/org-parse/node.rb', line 42

def kind
  @kind
end

#parentObject

Parent node



48
49
50
# File 'lib/org-parse/node.rb', line 48

def parent
  @parent
end

#valueObject

Node value



46
47
48
# File 'lib/org-parse/node.rb', line 46

def value
  @value
end

Instance Method Details

#doneObject



98
99
100
# File 'lib/org-parse/node.rb', line 98

def done
  @done = true
end

#done?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/org-parse/node.rb', line 94

def done?
  @done
end

#example?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/org-parse/node.rb', line 74

def example?
  @example
end

#html?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/org-parse/node.rb', line 90

def html?
  @html
end

#inspectObject

def is_container?

[:SECTION, :TEXTBLOCK, :LISTITEM, :UNORDERED_LIST, :ENUMLIST, :DESCLIST, :BLOCK].include? @kind

end



110
111
112
113
114
115
116
# File 'lib/org-parse/node.rb', line 110

def inspect
  c = ''
  c  = @children.collect{|i| indent2(i.inspect)}.join("\n") if @children
  val = @value ? @value.to_s : '(nil)'
  val = val.is_a?( Array) ? val.join(",") : val.gsub("\n", ' ')
  "<#{self.class.name} #{@kind}:#{val}>" + (c.empty? ? "" : "\n") + c
end

#is_leaf?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/org-parse/node.rb', line 102

def is_leaf?
  @children.empty?
end

#section_no_arrayObject



118
119
120
121
122
123
124
# File 'lib/org-parse/node.rb', line 118

def section_no_array
  if @section_no
    @section_no.split('.')
  else
    nil
  end
end

#set_exampleObject



70
71
72
# File 'lib/org-parse/node.rb', line 70

def set_example
  @example = true
end

#set_htmlObject



86
87
88
# File 'lib/org-parse/node.rb', line 86

def set_html
  @html = true
end

#set_srcObject



78
79
80
# File 'lib/org-parse/node.rb', line 78

def set_src
  @src = true
end

#set_to_descendant(method, val = nil) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# File 'lib/org-parse/node.rb', line 126

def set_to_descendant(method, val=nil)
  @children.each{|node|
    if val
      node.send method, *val
    else
      node.send method
    end
    node.set_to_descendant method, val
  }
end

#set_verseObject



62
63
64
# File 'lib/org-parse/node.rb', line 62

def set_verse
  @verse = true
end

#src?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/org-parse/node.rb', line 82

def src?
  @src
end

#verse?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/org-parse/node.rb', line 66

def verse?
  @verse
end