Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GiveCorps/html2textile
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: tipitnet/html2textile
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Aug 12, 2014

  1. Bug fixed

    nicopaez committed Aug 12, 2014
    Copy the full SHA
    5bd056c View commit details

Commits on Aug 14, 2014

  1. Copy the full SHA
    88ccc09 View commit details
  2. Merge pull request #1 from tipitnet/fixes_and_test_added

    Some bug fixes and tests added
    nicopaez committed Aug 14, 2014
    Copy the full SHA
    6d298ce View commit details
Showing with 53 additions and 5 deletions.
  1. +1 −0 html2textile.gemspec
  2. +3 −5 lib/html2textile.rb
  3. +49 −0 test/html2textile_test.rb
1 change: 1 addition & 0 deletions html2textile.gemspec
Original file line number Diff line number Diff line change
@@ -14,4 +14,5 @@ Gem::Specification.new do |s|

s.require_path = 'lib'
s.files = Dir.glob("{lib}/**/*") + %w(example.rb README.mdown)

end
8 changes: 3 additions & 5 deletions lib/html2textile.rb
Original file line number Diff line number Diff line change
@@ -17,11 +17,9 @@
# parser.feed(input_html)
# puts parser.to_textile
class HTMLToTextileParser < SgmlParser

# TDH removed span from quicktags and set p to empty string
# removed blockquote pair
# removed blockquote pair
PAIRS = { 'p' => ''}
QUICKTAGS = { 'b' => '*', 'strong' => '*',
QUICKTAGS = { 'b' => '*', 'strong' => '*', 'span' => '',
'i' => '_', 'em' => '_', 'cite' => '??', 's' => '-',
'sup' => '^', 'sub' => '~', 'code' => '@'}

@@ -120,7 +118,7 @@ def handle_data(data)

%w[1 2 3 4 5 6].each do |num|
define_method "start_h#{num}" do |attributes|
make_block_start_pair("h#{num}", attributes)
make_block_start_pair("h#{num}. ", attributes)
end

define_method "end_h#{num}" do
49 changes: 49 additions & 0 deletions test/html2textile_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'test/unit'
require_relative '../lib/html2textile'

class HTMLToTextileParserTest < Test::Unit::TestCase

def to_textile(html)
@parser = HTMLToTextileParser.new
@parser.feed(html)
@parser.to_textile
end

def test_should_parse_bold
assert_equal ' *bold* ', to_textile('<b>bold</b>')
end

def test_should_parse_italic
assert_equal ' _italic_ ', to_textile('<i>italic</i>')
end

def test_bold_with_spaces
assert_equal ' *b o l d* ', to_textile('<b> b o l d </b>')
end

def test_should_parse_bold_with_new_lines_inside
assert_equal ' *b o l d* ', to_textile("<b> b o\nl d\n</b>")
end

def test_should_parse_italic_with_spaces
assert_equal ' _i t a l i c_ ', to_textile('<i> i t a l i c</i>')
end

def test_should_parse_headings
assert_equal("h1. Heading 1\n\n", to_textile('<h1>Heading 1</h1>'))
assert_equal("h2. Heading 2\n\n", to_textile('<h2>Heading 2</h2>'))
assert_equal("h3. Heading 3\n\n", to_textile('<h3>Heading 3</h3>'))
end

def test_should_parse_heading_with_color
assert_equal "h1. Hello world \n\n",
to_textile('<h1>Hello <span style="color: red">world</span></h1>')
end

def test_should_parse_heading_with_spaces_and_new_lines
assert_equal "h1. Th is is a headi ng\n\n",
to_textile('<h1> Th
is is a headi ng </h1>')
end

end