Class: Orgmode::Headline
Overview
Represents a headline in an orgmode file.
Constant Summary collapse
- ValidExportStates =
Valid states for partial export.
- exclude
-
The entire subtree from this heading should be excluded.
- headline_only
-
The headline should be exported, but not the body.
- all
-
Everything should be exported, headline/body/children.
[:exclude, :headline_only, :all]
- LineRegexp =
This is the regex that matches a line
/^\*+\s+/
- TagsRegexp =
This matches the tags on a headline
/\s*:[\w:]*:\s*$/
- Keywords =
Special keywords allowed at the start of a line.
%w[TODO DONE]
- KeywordsRegexp =
Regexp.new("^(#{Keywords.join('|')})\$")
Constants inherited from Line
Line::BlockRegexp, Line::InBufferSettingRegexp, Line::InlineExampleRegexp, Line::OrderedListRegexp, Line::UnorderedListRegexp
Instance Attribute Summary collapse
-
#body_lines ⇒ Object
readonly
This contains the lines that “belong” to the headline.
-
#export_state ⇒ Object
The export state of this headline.
-
#headline_text ⇒ Object
readonly
This is the headline text – the part of the headline minus the leading asterisks, the keywords, and the tags.
-
#keyword ⇒ Object
readonly
Optional keyword found at the beginning of the headline.
-
#level ⇒ Object
readonly
This is the “level” of the headline.
-
#tags ⇒ Object
readonly
These are the headline tags.
Attributes inherited from Line
#assigned_paragraph_type, #indent, #line, #parser
Class Method Summary collapse
-
.headline?(line) ⇒ Boolean
Determines if a line is an orgmode “headline”: A headline begins with one or more asterisks.
Instance Method Summary collapse
-
#initialize(line, parser = nil) ⇒ Headline
constructor
A new instance of Headline.
-
#output_text ⇒ Object
Override Line.output_text.
-
#paragraph_type ⇒ Object
Overrides Line.paragraph_type.
-
#to_textile ⇒ Object
Converts this headline and its body to textile.
Methods inherited from Line
#begin_block?, #blank?, #block_type, #code_block_type?, #comment?, #end_block?, #in_buffer_setting?, #inline_example?, #metadata?, #nonprinting?, #ordered_list?, #plain_list?, #plain_text?, #strip_ordered_list_tag, #strip_unordered_list_tag, #table?, #table_header?, #table_row?, #table_separator?, #to_s, to_textile, #unordered_list?
Constructor Details
#initialize(line, parser = nil) ⇒ Headline
Returns a new instance of Headline.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/org-ruby/headline.rb', line 44 def initialize(line, parser = nil) super(line, parser) @body_lines = [] @body_lines << self # Make @body_lines contain the headline? @tags = [] @export_state = :exclude if (@line =~ LineRegexp) then @level = $&.strip.length @headline_text = $'.strip if (@headline_text =~ TagsRegexp) then @tags = $&.split(/:/) # split tag text on semicolon @tags.delete_at(0) # the first item will be empty; discard @headline_text.gsub!(TagsRegexp, "") # Removes the tags from the headline end @keyword = nil parse_keywords else raise "'#{line}' is not a valid headline" end end |
Instance Attribute Details
#body_lines ⇒ Object (readonly)
This contains the lines that “belong” to the headline.
16 17 18 |
# File 'lib/org-ruby/headline.rb', line 16 def body_lines @body_lines end |
#export_state ⇒ Object
The export state of this headline. See ValidExportStates
.
31 32 33 |
# File 'lib/org-ruby/headline.rb', line 31 def export_state @export_state end |
#headline_text ⇒ Object (readonly)
This is the headline text – the part of the headline minus the leading asterisks, the keywords, and the tags.
13 14 15 |
# File 'lib/org-ruby/headline.rb', line 13 def headline_text @headline_text end |
#keyword ⇒ Object (readonly)
Optional keyword found at the beginning of the headline.
22 23 24 |
# File 'lib/org-ruby/headline.rb', line 22 def keyword @keyword end |
#level ⇒ Object (readonly)
This is the “level” of the headline
9 10 11 |
# File 'lib/org-ruby/headline.rb', line 9 def level @level end |
#tags ⇒ Object (readonly)
These are the headline tags
19 20 21 |
# File 'lib/org-ruby/headline.rb', line 19 def @tags end |
Class Method Details
.headline?(line) ⇒ Boolean
Determines if a line is an orgmode “headline”: A headline begins with one or more asterisks.
73 74 75 |
# File 'lib/org-ruby/headline.rb', line 73 def self.headline?(line) line =~ LineRegexp end |
Instance Method Details
#output_text ⇒ Object
Override Line.output_text. For a heading, @headline_text is what we should output.
67 68 69 |
# File 'lib/org-ruby/headline.rb', line 67 def output_text return @headline_text end |
#paragraph_type ⇒ Object
Overrides Line.paragraph_type.
78 79 80 |
# File 'lib/org-ruby/headline.rb', line 78 def paragraph_type :"heading#{@level}" end |
#to_textile ⇒ Object
Converts this headline and its body to textile.
83 84 85 86 87 |
# File 'lib/org-ruby/headline.rb', line 83 def to_textile output = "h#{@level}. #{@headline_text}\n" output << Line.to_textile(@body_lines[1..-1]) output end |