lib/dnote/notes.rb in dnote-1.2.1 vs lib/dnote/notes.rb in dnote-1.3.0

- old
+ new

@@ -32,15 +32,19 @@ attr_accessor :labels # Require label colon? Default is +true+. attr_accessor :colon + # Alternate remark marker. Default is '#'. + attr_accessor :marker + # New set of notes for give +files+ and optional special labels. def initialize(files, options={}) @files = [files].flatten - @labels = [options[:labels]].flatten.compact + @labels = [options[:labels] || DEFAULT_LABELS].flatten.compact @colon = options[:colon].nil? ? true : options[:colon] + @marker = options[:marker] || '#' parse end # Array of notes. def notes @@ -87,18 +91,19 @@ text = save.text #save = {'label'=>label,'file'=>file,'line'=>line_no,'note'=>text} records << save else if text - if line =~ /^\s*[#]{0,1}\s*$/ or line !~ /^\s*#/ or line =~ /^\s*#[+][+]/ + case line + when /^\s*#{remark}+\s*$/, /(?!^\s*#{remark})/, /^\s*#{remark}[+][+]/ text.strip! text = nil else if text[-1,1] == "\n" - text << line.gsub(/^\s*#\s*/,'') + text << line.gsub(/^\s*#{remark}\s*/,'') else - text << "\n" << line.gsub(/^\s*#\s*/,'') + text << "\n" << line.gsub(/^\s*#{remark}\s*/,'') end end end end end @@ -133,13 +138,13 @@ #-- # TODO: ruby-1.9.1-p378 reports: `match': invalid byte sequence in UTF-8 #++ def match_special_regex(label) if colon - /\#\s*#{Regexp.escape(label)}[:]\s*(.*?)$/ + /#{remark}\s*#{Regexp.escape(label)}[:]\s*(.*?)$/ else - /\#\s*#{Regexp.escape(label)}[:]?\s*(.*?)$/ + /#{remark}\s*#{Regexp.escape(label)}[:]?\s*(.*?)$/ end end # Match notes that are labeled with a colon. def match_general(line, lineno, file) @@ -153,13 +158,13 @@ end # def match_general_regex if colon - /\#\s*([A-Z]+)[:]\s+(.*?)$/ + /#{remark}\s*([A-Z]+)[:]\s+(.*?)$/ else - /\#\s*([A-Z]+)[:]?\s+(.*?)$/ + /#{remark}\s*([A-Z]+)[:]?\s+(.*?)$/ end end # Organize notes into a hash with labels for keys. def by_label @@ -223,9 +228,14 @@ end # Same as #by_label. def to_h by_label + end + + # + def remark + @remark ||= Regexp.escape(marker) end # Convert to array of hashes then to YAML. #def to_yaml # require 'yaml'