class Orgmode::Headline
Represents a headline in an orgmode file.
Constants
- CommentHeadlineRegexp
This matches a headline marked as COMMENT
- Keywords
Special keywords allowed at the start of a line.
- KeywordsRegexp
- LineRegexp
This is the regex that matches a line
- TagsRegexp
This matches the tags on a headline
- 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.
Attributes
This contains the lines that “belong” to the headline.
The export state of this headline. See ValidExportStates
.
This is the headline text – the part of the headline minus the leading asterisks, the keywords, and the tags.
Optional keyword found at the beginning of the headline.
This is the “level” of the headline
Include the property drawer items found for the headline
Public Class Methods
Determines if a line is an orgmode “headline”: A headline begins with one or more asterisks.
# File lib/org-ruby/headline.rb, line 77 def self.headline?(line) line =~ LineRegexp end
# File lib/org-ruby/headline.rb, line 48 def initialize(line, parser = nil, offset=0) super(line, parser) @body_lines = [] @tags = [] @export_state = :exclude @property_drawer = { } 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
Public Instance Methods
Determines if a headline has the COMMENT keyword.
# File lib/org-ruby/headline.rb, line 82 def comment_headline? @headline_text =~ CommentHeadlineRegexp end
Override Orgmode::Line#output_text. For a heading, @headline_text is what we should output.
# File lib/org-ruby/headline.rb, line 71 def output_text return @headline_text end
Overrides Orgmode::Line#paragraph_type.
# File lib/org-ruby/headline.rb, line 87 def paragraph_type :"heading#{@level}" end
Private Instance Methods
# File lib/org-ruby/headline.rb, line 94 def parse_keywords re = @parser.custom_keyword_regexp if @parser re ||= KeywordsRegexp words = @headline_text.split if words.length > 0 && words[0] =~ re then @keyword = words[0] @headline_text.sub!(Regexp.new("^#{@keyword}\s*"), "") end end