[DRE-commits] [ruby-org] 62/303: Now numbers headlines on demand.
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:28 UTC 2013
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository ruby-org.
commit 2495dac8fd8d49b1b019a3ac5b40f65b7a69fa3b
Author: Brian Dewey <bdewey at gmail.com>
Date: Tue Dec 29 17:04:30 2009 -0800
Now numbers headlines on demand.
---
History.txt | 4 +++-
lib/org-ruby.rb | 2 +-
lib/org-ruby/headline.rb | 6 +++++-
lib/org-ruby/parser.rb | 26 ++++++++++++++++++++++++++
spec/html_examples/export-keywords.html | 4 ++--
spec/parser_spec.rb | 14 ++++++++++++++
6 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/History.txt b/History.txt
index 1f6158b..271f877 100644
--- a/History.txt
+++ b/History.txt
@@ -1,9 +1,11 @@
-== X.X.X / 2009-12-XX
+== 0.5.0 / 2009-12-29
* Parse (but not necessarily *use*) in-buffer settings.
* Understand the #+TITLE: directive.
* Rewrite "file:(blah).org" links to "http:(blah).html" links. This
makes the inter-links to other org-mode files work.
+* Supports the in-buffer setting for exporting todo keywords.
+* Supports the in-buffer setting for numbering headlines.
== 0.4.2 / 2009-12-29
diff --git a/lib/org-ruby.rb b/lib/org-ruby.rb
index bef25db..5d2d057 100644
--- a/lib/org-ruby.rb
+++ b/lib/org-ruby.rb
@@ -3,7 +3,7 @@ unless defined? ::OrgRuby
module OrgRuby
# :stopdoc:
- VERSION = '0.4.2'
+ VERSION = '0.5.0'
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
# :startdoc:
diff --git a/lib/org-ruby/headline.rb b/lib/org-ruby/headline.rb
index ddc620e..7f08d61 100644
--- a/lib/org-ruby/headline.rb
+++ b/lib/org-ruby/headline.rb
@@ -73,8 +73,12 @@ module Orgmode
decoration = ""
end
output = "<h#{@level}#{decoration}>"
+ if @parser and @parser.export_heading_number? then
+ heading_number = @parser.get_next_headline_number(@level)
+ output << "<span class=\"heading-number heading-number-#{@level}\">#{heading_number} </span>"
+ end
if @parser and @parser.export_todo? then
- output << "<span class=\"#{@keyword}\">#{@keyword} </span>"
+ output << "<span class=\"todo-keyword #{@keyword}\">#{@keyword} </span>"
end
output << "#{@headline_text}</h#{@level}>\n"
output << Line.to_html(@body_lines)
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 6ddb5af..fd35dac 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -25,10 +25,35 @@ module Orgmode
# This contains in-buffer options; a special case of in-buffer settings.
attr_reader :options
+ # Returns true if we are to export todo keywords on headings.
def export_todo?
"t" == @options["todo"]
end
+ # This stack is used to do proper outline numbering of headlines.
+ attr_accessor :headline_number_stack
+
+ # Returns true if we are to export heading numbers.
+ def export_heading_number?
+ "t" == @options["num"]
+ end
+
+ # Gets the next headline number for a given level. The intent is
+ # this function is called sequentially for each headline that
+ # needs to get numbered. It does standard outline numbering.
+ def get_next_headline_number(level)
+ raise "Headline level not valid: #{level}" if level <= 0
+ while level > @headline_number_stack.length do
+ @headline_number_stack.push 0
+ end
+ while level < @headline_number_stack.length do
+ @headline_number_stack.pop
+ end
+ raise "Oops, shouldn't happen" unless level == @headline_number_stack.length
+ @headline_number_stack[@headline_number_stack.length - 1] += 1
+ @headline_number_stack.join(".")
+ end
+
# I can construct a parser object either with an array of lines
# or with a single string that I will split along \n boundaries.
def initialize(lines)
@@ -43,6 +68,7 @@ module Orgmode
@headlines = Array.new
@current_headline = nil
@header_lines = []
+ @headline_number_stack = []
@in_buffer_settings = { }
@options = { }
mode = :normal
diff --git a/spec/html_examples/export-keywords.html b/spec/html_examples/export-keywords.html
index 6cd4aa8..f9c95ad 100644
--- a/spec/html_examples/export-keywords.html
+++ b/spec/html_examples/export-keywords.html
@@ -1,4 +1,4 @@
<p class="title">export-keywords.org</p>
<p>Testing that I can export keywords.</p>
-<h1><span class="TODO">TODO </span>This is a todo item.</h1>
-<h1><span class="DONE">DONE </span>this item is done!</h1>
+<h1><span class="heading-number heading-number-1">3 </span><span class="todo-keyword TODO">TODO </span>This is a todo item.</h1>
+<h1><span class="heading-number heading-number-1">4 </span><span class="todo-keyword DONE">DONE </span>this item is done!</h1>
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
index 46cc110..1c498c8 100644
--- a/spec/parser_spec.rb
+++ b/spec/parser_spec.rb
@@ -61,6 +61,20 @@ describe Orgmode::Parser do
parser.export_todo?.should be_false
end
+ it "computes outline level numbering" do
+ parser = Orgmode::Parser.new ""
+ parser.get_next_headline_number(1).should eql("1")
+ parser.get_next_headline_number(1).should eql("2")
+ parser.get_next_headline_number(1).should eql("3")
+ parser.get_next_headline_number(1).should eql("4")
+ parser.get_next_headline_number(2).should eql("4.1")
+ parser.get_next_headline_number(2).should eql("4.2")
+ parser.get_next_headline_number(1).should eql("5")
+ parser.get_next_headline_number(2).should eql("5.1")
+ parser.get_next_headline_number(2).should eql("5.2")
+ parser.get_next_headline_number(4).should eql("5.2.0.1")
+ end
+
it "should skip in-buffer settings inside EXAMPLE blocks" do
parser = Orgmode::Parser.load(FreeformExampleFile)
parser.should have(0).in_buffer_settings
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-org.git
More information about the Pkg-ruby-extras-commits
mailing list