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('|')})\$")
- CommentHeadlineRegexp =
This matches a headline marked as COMMENT
/^COMMENT\s+/
Constants inherited from Line
Line::BlockRegexp, Line::DefinitionListRegexp, Line::HorizontalRuleRegexp, Line::InBufferSettingRegexp, Line::InlineExampleRegexp, Line::OrderedListRegexp, Line::PropertyDrawerItemRegexp, Line::PropertyDrawerRegexp, Line::RawTextRegexp, 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, #major_mode, #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
-
#comment_headline? ⇒ Boolean
Determines if a headline has the COMMENT keyword.
-
#initialize(line, parser = nil, offset = 0) ⇒ Headline
constructor
A new instance of Headline.
-
#output_text ⇒ Object
Override Line.output_text.
-
#paragraph_type ⇒ Object
Overrides Line.paragraph_type.
Methods inherited from Line
#begin_block?, #blank?, #block_lang, #block_type, #code_block?, #comment?, #definition_list?, #determine_major_mode, #determine_paragraph_type, #end_block?, #horizontal_rule?, #in_buffer_setting?, #inline_example?, #metadata?, #nonprinting?, #ordered_list?, #plain_list?, #plain_text?, #property_drawer?, #property_drawer_begin_block?, #property_drawer_end_block?, #property_drawer_item?, #raw_text?, #raw_text_tag, #strip_ordered_list_tag, #strip_raw_text_tag, #strip_unordered_list_tag, #table?, #table_header?, #table_row?, #table_separator?, #to_s, #unordered_list?
Constructor Details
#initialize(line, parser = nil, offset = 0) ⇒ Headline
Returns a new instance of Headline.
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 45 def initialize(line, parser = nil, offset=0) super(line, parser) @body_lines = [] @tags = [] @export_state = :exclude if (@line =~ LineRegexp) then @level = $&.strip.length + offset @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.
14 15 16 |
# File 'lib/org-ruby/headline.rb', line 14 def body_lines @body_lines end |
#export_state ⇒ Object
The export state of this headline. See ValidExportStates
.
29 30 31 |
# File 'lib/org-ruby/headline.rb', line 29 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.
11 12 13 |
# File 'lib/org-ruby/headline.rb', line 11 def headline_text @headline_text end |
#keyword ⇒ Object (readonly)
Optional keyword found at the beginning of the headline.
20 21 22 |
# File 'lib/org-ruby/headline.rb', line 20 def keyword @keyword end |
#level ⇒ Object (readonly)
This is the “level” of the headline
7 8 9 |
# File 'lib/org-ruby/headline.rb', line 7 def level @level end |
#tags ⇒ Object (readonly)
These are the headline tags
17 18 19 |
# File 'lib/org-ruby/headline.rb', line 17 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
#comment_headline? ⇒ Boolean
Determines if a headline has the COMMENT keyword.
78 79 80 |
# File 'lib/org-ruby/headline.rb', line 78 def comment_headline? @headline_text =~ CommentHeadlineRegexp end |
#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.
83 84 85 |
# File 'lib/org-ruby/headline.rb', line 83 def paragraph_type :"heading#{@level}" end |