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

body_lines[R]

This contains the lines that “belong” to the headline.

export_state[RW]

The export state of this headline. See ValidExportStates.

headline_text[R]

This is the headline text – the part of the headline minus the leading asterisks, the keywords, and the tags.

keyword[R]

Optional keyword found at the beginning of the headline.

level[R]

This is the “level” of the headline

property_drawer[RW]

Include the property drawer items found for the headline

tags[R]

These are the headline tags

Public Class Methods

headline?(line) click to toggle source

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
new(line, parser = nil, offset=0) click to toggle source
Calls superclass method
# 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

comment_headline?() click to toggle source

Determines if a headline has the COMMENT keyword.

# File lib/org-ruby/headline.rb, line 82
def comment_headline?
  @headline_text =~ CommentHeadlineRegexp
end
output_text() click to toggle source

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
paragraph_type() click to toggle source

Overrides Orgmode::Line#paragraph_type.

# File lib/org-ruby/headline.rb, line 87
def paragraph_type
  :"heading#{@level}"
end

Private Instance Methods

parse_keywords() click to toggle source
# 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