Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #2 from torandi/master

Updated html2textile to work with ruby 1.9.2
  • Loading branch information...
commit dd83495eed4bc46fc12df09ffa163056b58269ca 2 parents 4c9d725 + f748094
@jystewart authored
Showing with 17 additions and 10 deletions.
  1. +1 −1  html2textile.gemspec
  2. +16 −9 lib/html2textile.rb
View
2  html2textile.gemspec
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'html2textile'
- s.version = "1.0.0.beta1"
+ s.version = "1.0.0.beta2"
s.summary = 'Converter from HTML to Textile'
s.description = 'Provides an SGML parser to convert HTML into the Textile format'
View
25 lib/html2textile.rb
@@ -17,6 +17,11 @@
# parser.feed(input_html)
# puts parser.to_textile
class HTMLToTextileParser < SgmlParser
+
+ PAIRS = { 'blockquote' => 'bq', 'p' => 'p' }
+ QUICKTAGS = { 'b' => '*', 'strong' => '*',
+ 'i' => '_', 'em' => '_', 'cite' => '??', 's' => '-',
+ 'sup' => '^', 'sub' => '~', 'code' => '@', 'span' => '%'}
attr_accessor :result
attr_accessor :in_block
@@ -77,11 +82,17 @@ def make_quicktag_end_pair(wrapchar)
end
def write(d)
+ if d.respond_to? :lines
+ d_a = d.lines.to_a
+ else
+ d_a = d.to_a
+ end
if self.data_stack.size < 2
- self.result += d.to_a
+ self.result += d_a
else
- self.data_stack[-1] += d.to_a
+ self.data_stack[-1] += d_a
end
+
end
def start_capture(tag)
@@ -108,10 +119,6 @@ def handle_data(data)
end
end
- PAIRS = { 'blockquote' => 'bq', 'p' => 'p' }
- QUICKTAGS = { 'b' => '*', 'strong' => '*',
- 'i' => '_', 'em' => '_', 'cite' => '??', 's' => '-',
- 'sup' => '^', 'sub' => '~', 'code' => '@', 'span' => '%'}
PAIRS.each do |key, value|
define_method "start_#{key}" do |attributes|
@@ -170,14 +177,14 @@ def start_a(attrs)
attrs = attrs_to_hash(attrs)
self.a_href = attrs['href']
- if self.a_href:
+ if self.a_href
write(" \"")
start_capture("a")
end
end
def end_a
- if self.a_href:
+ if self.a_href
stop_capture_and_write
write(["\":", self.a_href, " "])
self.a_href = false
@@ -252,4 +259,4 @@ def to_textile
# method(dict(attrs))
#
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.