[DRE-commits] [ruby-org] 92/303: Implemented definition lists (e.g., + a :: b). Only works with HTML (Textile does not support definition lists AFAIK).
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:33 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 1520600146223a175347c4ead9a1ee04c5184fb9
Author: Rüdiger Sonderfeld <ruediger at c-plusplus.de>
Date: Thu Jul 21 00:51:47 2011 +0200
Implemented definition lists (e.g., + a :: b). Only works with HTML (Textile does not support definition lists AFAIK).
---
lib/org-ruby/html_output_buffer.rb | 21 +++++++++++++++++++--
lib/org-ruby/line.rb | 9 ++++++++-
lib/org-ruby/output_buffer.rb | 5 ++++-
lib/org-ruby/parser.rb | 2 +-
lib/org-ruby/textile_output_buffer.rb | 2 +-
spec/html_examples/deflist.html | 6 ++++++
spec/html_examples/deflist.org | 6 ++++++
7 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index f8111dd..665f904 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -8,6 +8,8 @@ module Orgmode
:paragraph => "p",
:ordered_list => "li",
:unordered_list => "li",
+ :definition_term => "dt",
+ :definition_descr => "dd",
:table_row => "tr",
:table_header => "tr",
:heading1 => "h1",
@@ -21,6 +23,7 @@ module Orgmode
ModeTag = {
:unordered_list => "ul",
:ordered_list => "ol",
+ :definition_list => "dl",
:table => "table",
:blockquote => "blockquote",
:example => "pre",
@@ -77,11 +80,25 @@ module Orgmode
@logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
@output << @buffer << "\n"
else
- if (@buffer.length > 0) then
+ if @buffer.length > 0 and @output_type == :definition_list then
+ unless buffer_mode_is_table? and skip_tables?
+ output_indentation
+ d = @buffer.split("::", 2)
+ @output << "<#{HtmlBlockTag[:definition_term]}#{@title_decoration}>" << inline_formatting(d[0].strip) \
+ << "</#{HtmlBlockTag[:definition_term]}>"
+ if d.length > 1 then
+ @output << "<#{HtmlBlockTag[:definition_descr]}#{@title_decoration}>" << inline_formatting(d[1].strip) \
+ << "</#{HtmlBlockTag[:definition_descr]}>\n"
+ else
+ @output << "\n"
+ end
+ @title_decoration = ""
+ end
+ elsif @buffer.length > 0 then
unless buffer_mode_is_table? and skip_tables?
@logger.debug "FLUSH ==========> #{@buffer_mode}"
output_indentation
- @output << "<#{HtmlBlockTag[@output_type]}#{@title_decoration}>"
+ @output << "<#{HtmlBlockTag[@output_type]}#{@title_decoration}>"
if (@buffered_lines[0].kind_of?(Headline)) then
headline = @buffered_lines[0]
raise "Cannot be more than one headline!" if @buffered_lines.length > 1
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index 2076f0e..64396c6 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -55,7 +55,7 @@ module Orgmode
end
def plain_list?
- ordered_list? or unordered_list?
+ ordered_list? or unordered_list? or definition_list?
end
UnorderedListRegexp = /^\s*(-|\+)\s*/
@@ -68,6 +68,12 @@ module Orgmode
@line.sub(UnorderedListRegexp, "")
end
+ DefinitionListRegexp = /^\s*(-|\+)\s*(.*?)::/
+
+ def definition_list?
+ check_assignment_or_regexp(:definition_list, DefinitionListRegexp)
+ end
+
OrderedListRegexp = /^\s*\d+(\.|\))\s*/
def ordered_list?
@@ -164,6 +170,7 @@ module Orgmode
# Determines the paragraph type of the current line.
def paragraph_type
return :blank if blank?
+ return :definition_list if definition_list? # order is important! A definition_list is also an unordered_list!
return :ordered_list if ordered_list?
return :unordered_list if unordered_list?
return :metadata if metadata?
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index 5e15878..e1a68c8 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -54,7 +54,7 @@ module Orgmode
push_mode(:normal)
end
- Modes = [:normal, :ordered_list, :unordered_list, :blockquote, :src, :example, :table, :inline_example]
+ Modes = [:normal, :ordered_list, :unordered_list, :definition_list, :blockquote, :src, :example, :table, :inline_example]
def current_mode
@mode_stack.last
@@ -187,6 +187,7 @@ module Orgmode
else
@list_indent_stack = []
while ((current_mode == :ordered_list) or
+ (current_mode == :definition_list) or
(current_mode == :unordered_list))
pop_mode
end
@@ -208,6 +209,7 @@ module Orgmode
# Currently only "paragraphs" get accumulated with previous output.
return false unless line.paragraph_type == :paragraph
if ((@output_type == :ordered_list) or
+ (@output_type == :definition_list) or
(@output_type == :unordered_list)) then
# If the previous output type was a list item, then we only put a paragraph in it
@@ -220,6 +222,7 @@ module Orgmode
return false unless
((@output_type == :paragraph) or
(@output_type == :ordered_list) or
+ (@output_type == :definition_list) or
(@output_type == :unordered_list))
true
end
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 752a226..d8afb8b 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -235,7 +235,7 @@ module Orgmode
output_buffer << line.line.lstrip
- when :unordered_list, :ordered_list
+ when :unordered_list, :ordered_list, :definition_list
output_buffer << line.output_text << " "
diff --git a/lib/org-ruby/textile_output_buffer.rb b/lib/org-ruby/textile_output_buffer.rb
index d4aa03d..a794f49 100644
--- a/lib/org-ruby/textile_output_buffer.rb
+++ b/lib/org-ruby/textile_output_buffer.rb
@@ -63,7 +63,7 @@ module Orgmode
end
@output << "bq. " if current_mode == :blockquote
@output << "#" * @list_indent_stack.length << " " if @output_type == :ordered_list
- @output << "*" * @list_indent_stack.length << " " if @output_type == :unordered_list
+ @output << "*" * @list_indent_stack.length << " " if @output_type == :unordered_list or @output_type == :definition_list
@output << inline_formatting(@buffer) << "\n"
end
clear_accumulation_buffer!
diff --git a/spec/html_examples/deflist.html b/spec/html_examples/deflist.html
new file mode 100644
index 0000000..fed5872
--- /dev/null
+++ b/spec/html_examples/deflist.html
@@ -0,0 +1,6 @@
+<p class="title">Hallo</p>
+<dl>
+ <dt>a</dt><dd>hello</dd>
+ <dt>b</dt><dd>world</dd>
+</dl>
+<p>Text</p>
diff --git a/spec/html_examples/deflist.org b/spec/html_examples/deflist.org
new file mode 100644
index 0000000..1b40a1f
--- /dev/null
+++ b/spec/html_examples/deflist.org
@@ -0,0 +1,6 @@
+#+TITLE: Hallo
+
+- a :: hello
+- b :: world
+
+Text
--
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