class TDiary::Style::MarkdownDiary

Public Class Methods

new(date, title, body, modified = Time.now) click to toggle source
# File lib/tdiary/style/markdown.rb, line 154
def initialize(date, title, body, modified = Time.now)
        init_diary
        replace( date, title, body )
        @last_modified = modified
end

Public Instance Methods

add_section(subtitle, body) click to toggle source
# File lib/tdiary/style/markdown.rb, line 192
def add_section(subtitle, body)
        @sections = MarkdownSection.new("\# #{subtitle}\n\n#{body}")
        @sections.size
end
append(body, author = nil) click to toggle source
# File lib/tdiary/style/markdown.rb, line 164
def append(body, author = nil)
        in_code_block = false
        section = nil
        body.each_line do |l|
                case l
                when /^\#[^\#]/
                        if in_code_block
                                section << l
                        else
                                @sections << MarkdownSection.new(section, author) if section
                                section = l
                        end
                when /^```/
                        in_code_block = !in_code_block
                        section << l
                else
                        section = '' unless section
                        section << l
                end
        end
        if section
                section << "\n" unless section =~ /\n\n\z/
                @sections << MarkdownSection.new(section, author)
        end
        @last_modified = Time.now
        self
end
style() click to toggle source
# File lib/tdiary/style/markdown.rb, line 160
def style
        'Markdown'
end