Permalink
Browse files

Merge branch 'vonavi/list_indentation' into master (Fixes #38)

  • Loading branch information...
2 parents a0da860 + 17c8ac5 commit 7cc4bfc9970d06b54e3002373cc4b1b718bc9b92 @wallyqs wallyqs committed Jan 14, 2013
Showing with 877 additions and 897 deletions.
  1. +81 −110 lib/org-ruby/html_output_buffer.rb
  2. +63 −19 lib/org-ruby/line.rb
  3. +128 −114 lib/org-ruby/output_buffer.rb
  4. +2 −43 lib/org-ruby/parser.rb
  5. +28 −20 lib/org-ruby/textile_output_buffer.rb
  6. +35 −19 spec/html_code_syntax_highlight_examples/advanced-code-coderay.html
  7. +15 −9 spec/html_code_syntax_highlight_examples/advanced-code-no-color.html
  8. +34 −19 spec/html_code_syntax_highlight_examples/advanced-code-pygments.html
  9. +2 −1 spec/html_code_syntax_highlight_examples/code-coderay.html
  10. +4 −2 spec/html_code_syntax_highlight_examples/code-no-color.html
  11. +2 −1 spec/html_code_syntax_highlight_examples/code-pygments.html
  12. +17 −15 spec/html_code_syntax_highlight_examples/src-code-list-coderay.html
  13. +17 −15 spec/html_code_syntax_highlight_examples/src-code-list-no-color.html
  14. +14 −13 spec/html_code_syntax_highlight_examples/src-code-list-pygments.html
  15. +31 −46 spec/html_examples/advanced-lists.html
  16. +4 −6 spec/html_examples/block_code.html
  17. +1 −1 spec/html_examples/blockcomment.html
  18. +1 −1 spec/html_examples/blockquote.html
  19. +1 −1 spec/html_examples/center.html
  20. +22 −26 spec/html_examples/code-block-lists.html
  21. +7 −7 spec/html_examples/code-comment.html
  22. +70 −76 spec/html_examples/code-lists.html
  23. +1 −1 spec/html_examples/comment-trees.html
  24. +5 −7 spec/html_examples/custom-seq-todo.html
  25. +5 −7 spec/html_examples/custom-todo.html
  26. +5 −7 spec/html_examples/custom-typ-todo.html
  27. +1 −1 spec/html_examples/deflist.html
  28. +109 −109 spec/html_examples/emphasis.html
  29. +4 −4 spec/html_examples/entities.html
  30. +5 −5 spec/html_examples/escape-pre.html
  31. +15 −15 spec/html_examples/export-exclude-only.html
  32. +1 −1 spec/html_examples/export-keywords.html
  33. +14 −14 spec/html_examples/export-tags.html
  34. +1 −1 spec/html_examples/export-title.html
  35. +6 −4 spec/html_examples/footnotes.html
  36. +1 −1 spec/html_examples/horizontal_rule.html
  37. +2 −2 spec/html_examples/html-literal.html
  38. +13 −18 spec/html_examples/inline-formatting.html
  39. +7 −11 spec/html_examples/inline-images.html
  40. +11 −17 spec/html_examples/link-features.html
  41. +24 −31 spec/html_examples/lists.html
  42. +2 −2 spec/html_examples/metadata-comment.html
  43. +5 −8 spec/html_examples/only-list.html
  44. +2 −2 spec/html_examples/only-table.html
  45. +1 −1 spec/html_examples/properties_drawer.html
  46. +1 −1 spec/html_examples/skip-header.html
  47. +2 −2 spec/html_examples/skip-table.html
  48. +1 −1 spec/html_examples/subsupscript-nil.html
  49. +1 −1 spec/html_examples/subsupscript.html
  50. +2 −2 spec/html_examples/tables.html
  51. +13 −13 spec/html_examples/text.html
  52. +3 −12 spec/line_spec.rb
  53. +6 −6 spec/textile_examples/block_code.textile
  54. +5 −3 spec/textile_examples/blockquote.textile
  55. +2 −2 spec/textile_examples/center.textile
  56. +4 −4 spec/textile_examples/footnotes.textile
  57. +4 −4 spec/textile_examples/keywords.textile
  58. +2 −2 spec/textile_examples/links.textile
  59. +3 −3 spec/textile_examples/lists.textile
  60. +2 −2 spec/textile_examples/single-space-plain-list.textile
  61. +7 −6 spec/textile_examples/tables.textile
@@ -15,12 +15,20 @@ class HtmlOutputBuffer < OutputBuffer
HtmlBlockTag = {
:paragraph => "p",
- :ordered_list => "li",
- :unordered_list => "li",
+ :unordered_list => "ul",
+ :ordered_list => "ol",
+ :list_item => "li",
+ :definition_list => "dl",
:definition_term => "dt",
:definition_descr => "dd",
+ :table => "table",
:table_row => "tr",
:table_header => "tr",
+ :blockquote => "blockquote",
+ :example => "pre",
+ :src => "pre",
+ :inline_example => "pre",
+ :center => "div",
:heading1 => "h1",
:heading2 => "h2",
:heading3 => "h3",
@@ -29,18 +37,6 @@ class HtmlOutputBuffer < OutputBuffer
:heading6 => "h6"
}
- ModeTag = {
- :unordered_list => "ul",
- :ordered_list => "ol",
- :definition_list => "dl",
- :table => "table",
- :blockquote => "blockquote",
- :example => "pre",
- :src => "pre",
- :inline_example => "pre",
- :center => "div"
- }
-
attr_reader :options
def initialize(output, opts = {})
@@ -51,61 +47,71 @@ def initialize(output, opts = {})
@title_decoration = ""
end
@options = opts
+ @indentation = :start
@footnotes = {}
@unclosed_tags = []
@logger.debug "HTML export options: #{@options.inspect}"
end
# Output buffer is entering a new mode. Use this opportunity to
- # write out one of the block tags in the ModeTag constant to put
- # this information in the HTML stream.
- def push_mode(mode)
- if ModeTag[mode] then
- output_indentation
- css_class = ""
- css_class = " class=\"src\"" if mode == :src and @block_lang.empty?
- css_class = " class=\"src src-#{@block_lang}\"" if mode == :src and not @block_lang.empty?
- css_class = " class=\"example\"" if (mode == :example || mode == :inline_example)
- css_class = " style=\"text-align: center\"" if mode == :center
-
- unless ((mode == :table and skip_tables?) or
+ # write out one of the block tags in the HtmlBlockTag constant to
+ # put this information in the HTML stream.
+ def push_mode(mode, indent)
+ super(mode)
+ @list_indent_stack.push(indent)
+
+ if HtmlBlockTag[mode]
+ unless ((mode_is_table?(mode) and skip_tables?) or
(mode == :src and defined? Pygments))
- @logger.debug "#{mode}: <#{ModeTag[mode]}#{css_class}>\n"
- @output << "<#{ModeTag[mode]}#{css_class}>\n"
+ css_class = case
+ when (mode == :src and @block_lang.empty?)
+ " class=\"src\""
+ when (mode == :src and not @block_lang.empty?)
+ " class=\"src src-#{@block_lang}\""
+ when (mode == :example || mode == :inline_example)
+ " class=\"example\""
+ when mode == :center
+ " style=\"text-align: center\""
+ else
+ @title_decoration
+ end
+
+ @output << "\n" unless @indentation == :start
+ @indentation = :output
+ output_indentation
+ @logger.debug "#{mode}: <#{HtmlBlockTag[mode]}#{css_class}>"
+ @output << "<#{HtmlBlockTag[mode]}#{css_class}>"
+ # Entering a new mode obliterates the title decoration
+ @title_decoration = ""
end
- # Entering a new mode obliterates the title decoration
- @title_decoration = ""
end
- super(mode)
end
# We are leaving a mode. Close any tags that were opened when
# entering this mode.
def pop_mode(mode = nil)
m = super(mode)
- if ModeTag[m] then
- output_indentation
- # Need to close the floating li elements before closing the list
- if (m == :unordered_list or
- m == :ordered_list or
- m == :definition_list) and
- (not @unclosed_tags.empty?)
- close_floating_li_tags
- end
-
- unless ((mode == :table and skip_tables?) or
- (mode == :src and defined? Pygments))
- @logger.debug "</#{ModeTag[m]}>\n"
- @output << "</#{ModeTag[m]}>\n"
+ if HtmlBlockTag[m]
+ unless ((mode_is_table?(m) and skip_tables?) or
+ (m == :src and defined? Pygments))
+ if @indentation
+ @output << "\n"
+ output_indentation
+ end
+ @indentation = :output
+ @logger.debug "</#{HtmlBlockTag[m]}>"
+ @output << "</#{HtmlBlockTag[m]}>"
end
-
- # In case it was a sublist, close it here
- close_last_li_tag_maybe
end
+ @list_indent_stack.pop
end
def flush!
- @buffer = @buffer.rstrip
+ if @buffer.length > 0 and not preserve_whitespace?
+ @buffer.lstrip!
+ @indentation = nil
+ end
+
if buffer_mode_is_src_block?
# Only try to colorize #+BEGIN_SRC blocks with a specified language,
@@ -115,6 +121,7 @@ def flush!
# NOTE: CodeRay and Pygments already escape the html once, so no need to escape_buffer!
if defined? Pygments
+ @output << "\n"
begin
@buffer = Pygments.highlight(@buffer, :lexer => lang)
rescue
@@ -138,68 +145,51 @@ def flush!
@logger.debug "FLUSH SRC CODE ==========> #{@buffer.inspect}"
@output << @buffer
- elsif mode_is_code(@buffer_mode) then
+ elsif mode_is_code?(@buffer_mode) then
escape_buffer!
# Whitespace is significant in :code mode. Always output the buffer
# and do not do any additional translation.
@logger.debug "FLUSH CODE ==========> #{@buffer.inspect}"
- @output << @buffer << "\n"
+ @output << @buffer
else
escape_buffer!
if @buffer.length > 0 and @output_type == :horizontal_rule then
- @output << "<hr />\n"
- elsif @buffer.length > 0 and @output_type == :definition_list then
- unless buffer_mode_is_table? and skip_tables?
+ @output << "\n"
+ @indentation = :output
+ output_indentation
+ @output << "<hr />"
+ elsif @buffer.length > 0 and @buffer_mode == :definition_item then
+ unless mode_is_table?(@buffer_mode) and skip_tables?
+ @output << "\n"
+ @indentation = :output
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"
+ << "</#{HtmlBlockTag[:definition_descr]}>"
end
@title_decoration = ""
end
elsif @buffer.length > 0 then
- unless buffer_mode_is_table? and skip_tables?
+ unless mode_is_table?(@buffer_mode) and skip_tables?
@logger.debug "FLUSH ==========> #{@buffer_mode}"
- output_indentation
- if ((@buffered_lines[0].plain_list?) and
- (@unclosed_tags.count == @list_indent_stack.count))
- @output << @unclosed_tags.pop
- output_indentation
- end
- @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
if @options[:export_heading_number] then
level = headline.level
heading_number = get_next_headline_number(level)
- output << "<span class=\"heading-number heading-number-#{level}\">#{heading_number} </span>"
+ @output << "<span class=\"heading-number heading-number-#{level}\">#{heading_number} </span>"
end
if @options[:export_todo] and headline.keyword then
keyword = headline.keyword
- output << "<span class=\"todo-keyword #{keyword}\">#{keyword} </span>"
+ @output << "<span class=\"todo-keyword #{keyword}\">#{keyword} </span>"
end
end
@output << inline_formatting(@buffer)
-
- # Only close the list when it is the last element from that list,
- # or when starting another list
- if (@output_type == :unordered_list or
- @output_type == :ordered_list or
- @output_type == :definition_list) and
- (not @list_indent_stack.empty?)
- @unclosed_tags.push("</#{HtmlBlockTag[@output_type]}>\n")
- @output << "\n"
- else
- @output << "</#{HtmlBlockTag[@output_type]}>\n"
- end
- @title_decoration = ""
else
@logger.debug "SKIP ==========> #{@buffer_mode}"
end
@@ -211,12 +201,12 @@ def flush!
def output_footnotes!
return false unless @options[:export_footnotes] and not @footnotes.empty?
- @output << "<div id=\"footnotes\">\n<h2 class=\"footnotes\">Footnotes: </h2>\n<div id=\"text-footnotes\">\n"
+ @output << "\n<div id=\"footnotes\">\n<h2 class=\"footnotes\">Footnotes:</h2>\n<div id=\"text-footnotes\">\n"
@footnotes.each do |name, defi|
@output << "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.#{name}\" href=\"#fnr.#{name}\">#{name}</a></sup>" \
<< inline_formatting(defi) \
- << "</p>\n"
+ << "\n</p>\n"
end
@output << "</div>\n</div>\n"
@@ -232,8 +222,9 @@ def skip_tables?
@options[:skip_tables]
end
- def buffer_mode_is_table?
- @buffer_mode == :table
+ def mode_is_table?(mode)
+ (mode == :table or mode == :table_row or
+ mode == :table_separator or mode == :table_header)
end
def buffer_mode_is_src_block?
@@ -247,8 +238,13 @@ def escape_buffer!
@buffer.gsub!(/>/, "&gt;")
end
+ def buffer_indentation
+ indent = " " * @list_indent_stack.length
+ self << indent
+ end
+
def output_indentation
- indent = " " * (@mode_stack.length - 1)
+ indent = " " * (@list_indent_stack.length - 1)
@output << indent
end
@@ -264,7 +260,6 @@ def output_indentation
# Applies inline formatting rules to a string.
def inline_formatting(str)
- str.rstrip!
str = @re_help.rewrite_emphasis(str) do |marker, s|
"#{Tags[marker][:open]}#{s}#{Tags[marker][:close]}"
end
@@ -320,30 +315,6 @@ def inline_formatting(str)
str
end
- def close_floating_li_tags
- unless @final_list_node
- unless @unclosed_tags.empty?
- @output << " " << @unclosed_tags.pop
- output_indentation
- end
- end
-
- @final_list_node = false
- end
-
- def close_last_li_tag_maybe
- if (@list_indent_stack.count < @unclosed_tags.count) and not
- (@list_indent_stack.empty? and @unclosed_tags.empty?)
- output_indentation
- @output << @unclosed_tags.pop
- if (@list_indent_stack.count == @unclosed_tags.count) and not
- (@list_indent_stack.empty? and @unclosed_tags.empty?)
- @final_list_node = true
- pop_mode
- end
- end
- end
-
def normalize_lang(lang)
case lang
when 'emacs-lisp', 'common-lisp', 'lisp'
Oops, something went wrong.

0 comments on commit 7cc4bfc

Please sign in to comment.