[DRE-commits] [ruby-org] 65/303: Added table header support
Jérémy Bobbio
lunar at alioth.debian.org
Fri Aug 9 17:33:29 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 4009169b78553bc3a14fe776176590eed8645ef9
Author: Brian Dewey <bdewey at gmail.com>
Date: Tue Dec 29 20:23:17 2009 -0800
Added table header support
---
History.txt | 3 ++-
lib/org-ruby.rb | 2 +-
lib/org-ruby/html_output_buffer.rb | 8 +++++++-
lib/org-ruby/line.rb | 10 ++++++++--
lib/org-ruby/output_buffer.rb | 4 ++--
lib/org-ruby/parser.rb | 7 ++++++-
spec/html_examples/only-table.html | 2 +-
spec/html_examples/tables.html | 2 +-
8 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/History.txt b/History.txt
index 271f877..442523f 100644
--- a/History.txt
+++ b/History.txt
@@ -1,4 +1,4 @@
-== 0.5.0 / 2009-12-29
+== 1.0.0 / 2009-12-29
* Parse (but not necessarily *use*) in-buffer settings.
* Understand the #+TITLE: directive.
@@ -6,6 +6,7 @@
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.
+* Uses <th> tags inside table rows that precede table separators.
== 0.4.2 / 2009-12-29
diff --git a/lib/org-ruby.rb b/lib/org-ruby.rb
index 5d2d057..d339ddb 100644
--- a/lib/org-ruby.rb
+++ b/lib/org-ruby.rb
@@ -3,7 +3,7 @@ unless defined? ::OrgRuby
module OrgRuby
# :stopdoc:
- VERSION = '0.5.0'
+ VERSION = '1.0.0'
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
# :startdoc:
diff --git a/lib/org-ruby/html_output_buffer.rb b/lib/org-ruby/html_output_buffer.rb
index 96c53c9..409e3ae 100644
--- a/lib/org-ruby/html_output_buffer.rb
+++ b/lib/org-ruby/html_output_buffer.rb
@@ -8,7 +8,8 @@ module Orgmode
:paragraph => "p",
:ordered_list => "li",
:unordered_list => "li",
- :table_row => "tr"
+ :table_row => "tr",
+ :table_header => "tr"
}
ModeTag = {
@@ -120,6 +121,11 @@ module Orgmode
str.gsub!(/\s*\|$/, "</td>")
str.gsub!(/\s*\|\s*/, "</td><td>")
end
+ if (@output_type == :table_header) then
+ str.gsub!(/^\|\s*/, "<th>")
+ str.gsub!(/\s*\|$/, "</th>")
+ str.gsub!(/\s*\|\s*/, "</th><th>")
+ end
str
end
diff --git a/lib/org-ruby/line.rb b/lib/org-ruby/line.rb
index ebabc39..0e9b37c 100644
--- a/lib/org-ruby/line.rb
+++ b/lib/org-ruby/line.rb
@@ -94,8 +94,13 @@ module Orgmode
check_assignment_or_regexp(:table_separator, /^\s*\|[-\|\+]*\s*$/)
end
+ # Checks if this line is a table header.
+ def table_header?
+ @assigned_paragraph_type == :table_header
+ end
+
def table?
- table_row? or table_separator?
+ table_row? or table_separator? or table_header?
end
BlockRegexp = /^\s*#\+(BEGIN|END)_(\w*)/
@@ -142,6 +147,7 @@ module Orgmode
return :comment if comment?
return :table_separator if table_separator?
return :table_row if table_row?
+ return :table_header if table_header?
return :paragraph
end
@@ -182,7 +188,7 @@ module Orgmode
output_buffer << line.line if output_buffer.preserve_whitespace?
end
- when :table_row
+ when :table_row, :table_header
output_buffer << line.line.lstrip
diff --git a/lib/org-ruby/output_buffer.rb b/lib/org-ruby/output_buffer.rb
index 65ac9c5..826e9e1 100644
--- a/lib/org-ruby/output_buffer.rb
+++ b/lib/org-ruby/output_buffer.rb
@@ -81,13 +81,13 @@ module Orgmode
# Tests if we are entering a table mode.
def enter_table?
- ((@output_type == :table_row) || (@output_type == :table_separator)) &&
+ ((@output_type == :table_row) || (@output_type == :table_header) || (@output_type == :table_separator)) &&
(current_mode != :table)
end
# Tests if we are existing a table mode.
def exit_table?
- ((@output_type != :table_row) && (@output_type != :table_separator)) &&
+ ((@output_type != :table_row) && (@output_type != :table_header) && (@output_type != :table_separator)) &&
(current_mode == :table)
end
diff --git a/lib/org-ruby/parser.rb b/lib/org-ruby/parser.rb
index 702d7f0..54a69f2 100644
--- a/lib/org-ruby/parser.rb
+++ b/lib/org-ruby/parser.rb
@@ -72,6 +72,7 @@ module Orgmode
@headline_number_stack = []
@options = { }
mode = :normal
+ previous_line = nil
@lines.each do |line|
case mode
when :normal
@@ -85,6 +86,9 @@ module Orgmode
line.in_buffer_setting? do |key, value|
store_in_buffer_setting key, value
end
+ if line.table_separator? then
+ previous_line.assigned_paragraph_type = :table_header if previous_line and previous_line.paragraph_type == :table_row
+ end
mode = :code if line.begin_block? and line.block_type == "EXAMPLE"
if (@current_headline) then
@current_headline.body_lines << line
@@ -109,7 +113,8 @@ module Orgmode
@header_lines << line
end
end # case
- end
+ previous_line = line
+ end # @lines.each
end # initialize
# Creates a new parser from the data in a given file
diff --git a/spec/html_examples/only-table.html b/spec/html_examples/only-table.html
index 46f0e2f..0b2823c 100644
--- a/spec/html_examples/only-table.html
+++ b/spec/html_examples/only-table.html
@@ -1,5 +1,5 @@
<table>
- <tr><td>One</td><td>Two</td><td>Three</td><td>Four</td></tr>
+ <tr><th>One</th><th>Two</th><th>Three</th><th>Four</th></tr>
<tr><td>Five</td><td>Six</td><td>Seven</td><td>Eight</td></tr>
<tr><td>Nine</td><td>Ten</td><td>Eleven</td><td>Twelve</td></tr>
<tr><td><b>format</b></td><td><i>text</i></td><td><code>in</code></td><td><span style="text-decoration:underline;">cells</span></td></tr>
diff --git a/spec/html_examples/tables.html b/spec/html_examples/tables.html
index d3f3c51..76402ff 100644
--- a/spec/html_examples/tables.html
+++ b/spec/html_examples/tables.html
@@ -13,7 +13,7 @@
<p>And here’s some paragraph content. The line breaks will need to get removed here, but not for the tables.</p>
<h1>Table with header</h1>
<table>
- <tr><td>One</td><td>Two</td><td>Three</td></tr>
+ <tr><th>One</th><th>Two</th><th>Three</th></tr>
<tr><td>Four</td><td>Five</td><td>Six</td></tr>
<tr><td>Seven</td><td>Eight</td><td>Nine</td></tr>
</table>
--
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