[DRE-commits] [ruby-org] 60/303: Started supporting the #+TITLE: directive. Better handling of links between ORG files.
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 cc49ea20dc2a6ebfe3289e8c416629da42d47fae
Author: Brian Dewey <bdewey at gmail.com>
Date: Tue Dec 29 16:20:52 2009 -0800
Started supporting the #+TITLE: directive. Better handling of links between ORG files.
---
History.txt | 5 ++++-
lib/org-ruby/headline.rb | 4 ++--
lib/org-ruby/html_output_buffer.rb | 8 ++++++++
lib/org-ruby/line.rb | 6 +++++-
lib/org-ruby/parser.rb | 11 ++++++++---
spec/html_examples/export-title.html | 2 ++
spec/html_examples/export-title.org | 4 ++++
spec/html_examples/link-features.html | 8 ++++++++
spec/html_examples/link-features.org | 19 +++++++++++++++++++
9 files changed, 60 insertions(+), 7 deletions(-)
diff --git a/History.txt b/History.txt
index 517a725..1f6158b 100644
--- a/History.txt
+++ b/History.txt
@@ -1,6 +1,9 @@
== X.X.X / 2009-12-XX
-* Parse in-buffer settings.
+* 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.
== 0.4.2 / 2009-12-29
diff --git a/lib/org-ruby/headline.rb b/lib/org-ruby/headline.rb
index dd33c76..2df59cf 100644
--- a/lib/org-ruby/headline.rb
+++ b/lib/org-ruby/headline.rb
@@ -32,8 +32,8 @@ module Orgmode
KeywordsRegexp = Regexp.new("\\s*(#{Keywords.join('|')})\\s*")
- def initialize(line)
- super(line)
+ def initialize(line, parser = nil)
+ super(line, parser)
@body_lines = []
@tags = []
if (@line =~ LineRegexp) then
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 88e5495..96c53c9 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -105,6 +105,14 @@ module Orgmode
end
str = @re_help.rewrite_links(str) do |link, text|
text ||= link
+ link = link.sub(/^file:(.*)::(.*?)$/) do
+
+ # We don't support search links right now. Get rid of it.
+
+ "file:#{$1}"
+ end
+ link = link.sub(/^file:/i, "") # will default to HTTP
+ link = link.sub(/\.org$/i, ".html")
"<a href=\"#{link}\">#{text}</a>"
end
if (@output_type == :table_row) then
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index ae2adb6..ebabc39 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -11,6 +11,9 @@ module Orgmode
# TODO 2009-12-20 bdewey: Handle tabs
attr_reader :indent
+ # Backpointer to the parser that owns this line.
+ attr_reader :parser
+
# A line can have its type assigned instead of inferred from its
# content. For example, something that parses as a "table" on its
# own ("| one | two|\n") may just be a paragraph if it's inside
@@ -18,7 +21,8 @@ module Orgmode
# type. This will then affect the value of +paragraph_type+.
attr_accessor :assigned_paragraph_type
- def initialize(line)
+ def initialize(line, parser = nil)
+ @parser = parser
@line = line
@indent = 0
@line =~ /\s*/
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 0b9c538..ba4144e 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -47,10 +47,10 @@ module Orgmode
when :normal
if (Headline.headline? line) then
- @current_headline = Headline.new line
+ @current_headline = Headline.new line, self
@headlines << @current_headline
else
- line = Line.new line
+ line = Line.new line, self
# If there is a setting on this line, remember it.
line.in_buffer_setting? do |key, value|
store_in_buffer_setting key, value
@@ -101,7 +101,12 @@ module Orgmode
# Converts the loaded org-mode file to HTML.
def to_html
output = ""
- decorate = true
+ if @in_buffer_settings["TITLE"] then
+ output << "<p class=\"title\">#{@in_buffer_settings["TITLE"]}</p>\n"
+ decorate = false
+ else
+ decorate = true
+ end
output << Line.to_html(@header_lines, :decorate_title => decorate)
decorate = (output.length == 0)
@headlines.each do |headline|
diff --git a/spec/html_examples/export-title.html b/spec/html_examples/export-title.html
new file mode 100644
index 0000000..9b611b2
--- /dev/null
+++ b/spec/html_examples/export-title.html
@@ -0,0 +1,2 @@
+<p class="title">Export Title</p>
+<p>This simple org document should get a title from the <code>TITLE</code> option at the front of the file.</p>
diff --git a/spec/html_examples/export-title.org b/spec/html_examples/export-title.org
new file mode 100644
index 0000000..6b37537
--- /dev/null
+++ b/spec/html_examples/export-title.org
@@ -0,0 +1,4 @@
+#+TITLE: Export Title
+
+This simple org document should get a title from the =TITLE= option at
+the front of the file.
diff --git a/spec/html_examples/link-features.html b/spec/html_examples/link-features.html
new file mode 100644
index 0000000..2214dec
--- /dev/null
+++ b/spec/html_examples/link-features.html
@@ -0,0 +1,8 @@
+<p class="title">link-features.org</p>
+<p>Org-mode export supports a lot of link features. I’ve covered “simple” HTML links elsewhere. Now let’s cover links to other org files, other sections within documents, etc.</p>
+<h1>Links to other org files</h1>
+<p>This is a link to the <code>code-comment.org</code> file in the same directory. In <code>emacs</code>, if you click it, the other file opens. We want the same behavior in the HTML export.</p>
+<p><a href="code-comment.html">Code Comment</a></p>
+<h1>Search links</h1>
+<p>This is a search link into code-comment.org.</p>
+<p><a href="code-comment.html">Code Comment</a></p>
diff --git a/spec/html_examples/link-features.org b/spec/html_examples/link-features.org
new file mode 100644
index 0000000..3779550
--- /dev/null
+++ b/spec/html_examples/link-features.org
@@ -0,0 +1,19 @@
+#+TITLE: link-features.org
+
+Org-mode export supports a lot of link features. I've covered "simple"
+HTML links elsewhere. Now let's cover links to other org files, other
+sections within documents, etc.
+
+* Links to other org files
+
+ This is a link to the ~code-comment.org~ file in the same
+ directory. In ~emacs~, if you click it, the other file opens. We
+ want the same behavior in the HTML export.
+
+ [[file:code-comment.org][Code Comment]]
+
+* Search links
+
+ This is a search link into code-comment.org.
+
+ [[file:code-comment.org::*Code%20Comment][Code Comment]]
--
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