From 095cdfa47a25483d1f94ea70c5354402bdf7a4ee Mon Sep 17 00:00:00 2001 From: Zach Schneider Date: Mon, 1 Feb 2021 12:25:05 -0600 Subject: [PATCH 1/2] Update test suite, add Gemfile, add Circle config --- .circleci/config.yml | 20 ++++++++++++++++++++ .gitignore | 1 + Gemfile | 3 +++ README.mdown => README.md | 0 html2confluence.gemspec | 2 ++ spec/combination_examples_spec.rb | 15 ++++++++------- spec/complex_tables_spec.rb | 5 ----- spec/jira_examples_spec.rb | 11 ++++++----- 8 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 .gitignore create mode 100644 Gemfile rename README.mdown => README.md (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..0fd2499 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,20 @@ +version: 2 +jobs: + test: + working_directory: ~/html2confluence + docker: + - image: circleci/ruby:2.5 + steps: + - checkout + - run: + name: Bundle + command: bundle install --jobs=4 --retry=3 + - run: + name: RSpec + command: bundle exec rspec + +workflows: + version: 2 + test: + jobs: + - test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b844b14 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..fa75df1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gemspec diff --git a/README.mdown b/README.md similarity index 100% rename from README.mdown rename to README.md diff --git a/html2confluence.gemspec b/html2confluence.gemspec index 2608c18..abbb9dc 100644 --- a/html2confluence.gemspec +++ b/html2confluence.gemspec @@ -15,4 +15,6 @@ Gem::Specification.new do |s| s.files = Dir.glob("{lib,spec}/**/*") + %w(example.rb README.mdown) s.add_dependency "nokogiri" + + s.add_development_dependency "rspec" end diff --git a/spec/combination_examples_spec.rb b/spec/combination_examples_spec.rb index f1ef51e..37c9be1 100644 --- a/spec/combination_examples_spec.rb +++ b/spec/combination_examples_spec.rb @@ -3,7 +3,6 @@ require 'html2confluence' describe HTMLToConfluenceParser, "when running combination examples" do - it "should match complex examples" do html = <<-END
    @@ -106,7 +105,13 @@ END markup = <<-END -{quote}\nbq. content here\n{quote} +{quote} + +{quote} +content here +{quote} + +{quote} END parser = HTMLToConfluenceParser.new @@ -207,9 +212,5 @@ parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) - end - + end end - - - diff --git a/spec/complex_tables_spec.rb b/spec/complex_tables_spec.rb index 1c8fa12..7cb9ce6 100644 --- a/spec/complex_tables_spec.rb +++ b/spec/complex_tables_spec.rb @@ -3,7 +3,6 @@ require 'html2confluence' describe HTMLToConfluenceParser, "when running complex tables examples" do - it "should handle table with newlines" do html = <<-END
    As a...I would like...Because...

    Student
    or

    Teacher

    There to be more candy

    Candy is:

    • Delicious
    • Shiny
    • Good for my teeth
    @@ -83,8 +82,4 @@ parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end - end - - - diff --git a/spec/jira_examples_spec.rb b/spec/jira_examples_spec.rb index 3310541..77ff73a 100644 --- a/spec/jira_examples_spec.rb +++ b/spec/jira_examples_spec.rb @@ -3,7 +3,6 @@ require 'html2confluence' describe HTMLToConfluenceParser, "when running JIRA examples" do - before :all do html = <<-END

    Biggest heading

    @@ -147,7 +146,10 @@ ^superscript^ ~subscript~ {{monospaced}} -bq. Some block quoted text + +{quote} +Some block quoted text +{quote} {quote} here is quotable @@ -264,7 +266,7 @@ end it "should convert block quotes" do - expect(@textile).to match(/^bq. Some block quoted text/) + expect(@textile).to match(/^{quote}\nSome block quoted text\n{quote}/) expect(@textile).to match(/^\{quote\}\s*here is quotable\s*content to be quoted\s*{quote}/) end @@ -311,6 +313,5 @@ expect(@textile).to include("(!)") expect(@textile).to include("(off)") expect(@textile).to include("(/)") - end - + end end From 68419384d073578f7cd2b1ae8bc66622d99787ce Mon Sep 17 00:00:00 2001 From: Zach Schneider Date: Mon, 1 Feb 2021 12:41:27 -0600 Subject: [PATCH 2/2] Add test cleanup from #16 --- .rspec | 3 +- spec/checkbox_examples_spec.rb | 17 +- spec/combination_examples_spec.rb | 20 +- spec/complex_tables_spec.rb | 18 +- spec/html2confluence_spec.rb | 101 +++--- spec/jira_examples_spec.rb | 565 +++++++++++++++--------------- spec/spec_helper.rb | 8 + 7 files changed, 353 insertions(+), 379 deletions(-) create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec index 5052887..83e16f8 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ ---color \ No newline at end of file +--color +--require spec_helper diff --git a/spec/checkbox_examples_spec.rb b/spec/checkbox_examples_spec.rb index 0b81c83..112b348 100644 --- a/spec/checkbox_examples_spec.rb +++ b/spec/checkbox_examples_spec.rb @@ -1,8 +1,5 @@ -# encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' - describe HTMLToConfluenceParser, "when running checkbox examples" do + let(:parser) { HTMLToConfluenceParser.new } it "should match checkboxes" do html = <<-END @@ -17,16 +14,14 @@ END markup = <<-END -* (/) Example 1 -* (/) Example 2 -* (x) Example 3 -* (/) Example 4 -* (x) Example 5 +* (/) Example 1 +* (/) Example 2 +* (x) Example 3 +* (/) Example 4 +* (x) Example 5 END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end - end diff --git a/spec/combination_examples_spec.rb b/spec/combination_examples_spec.rb index 37c9be1..3ecd116 100644 --- a/spec/combination_examples_spec.rb +++ b/spec/combination_examples_spec.rb @@ -1,8 +1,6 @@ -# encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' - describe HTMLToConfluenceParser, "when running combination examples" do + let(:parser) { HTMLToConfluenceParser.new } + it "should match complex examples" do html = <<-END
      @@ -17,9 +15,7 @@ # numbered *item* that is +underlined+. # list END - - - parser = HTMLToConfluenceParser.new + parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -94,7 +90,6 @@ h1. With +nice+ formatting. END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -114,7 +109,6 @@ {quote} END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -127,7 +121,6 @@ markup = "Previous\n\n*Scenario 4a: Existing deletes their ID*\n*Given* I am an existing user" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -141,7 +134,6 @@ markup = "Previous line\n\n*Scenario 4a: Existing deletes their ID*\n*Given* I am an existing user" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -151,7 +143,6 @@ markup = "*And* first line\n\n*second line*" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -161,7 +152,6 @@ markup = "!a source!" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -170,7 +160,6 @@ html = "
      familiar with the XMLHttpRequest Object
      \n\n" markup = "familiar with the XMLHttpRequest Object" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) @@ -184,7 +173,6 @@ markup = "Previous line\n\n----" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -196,7 +184,6 @@ markup = "A" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -209,7 +196,6 @@ markup = "A" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end diff --git a/spec/complex_tables_spec.rb b/spec/complex_tables_spec.rb index 7cb9ce6..ef69972 100644 --- a/spec/complex_tables_spec.rb +++ b/spec/complex_tables_spec.rb @@ -1,9 +1,7 @@ -# encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' - describe HTMLToConfluenceParser, "when running complex tables examples" do - it "should handle table with newlines" do + let(:parser) { HTMLToConfluenceParser.new } + + it "should handle table with newlines" do html = <<-END
      As a...I would like...Because...

      Student
      or

      Teacher

      There to be more candy

      Candy is:

      • Delicious
      • Shiny
      • Good for my teeth
      END @@ -20,12 +18,11 @@ * Good for my teeth| END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end - it "should handle table empty cells" do + it "should handle table empty cells" do html = <<-END


      Empty


      END @@ -34,12 +31,11 @@ | |Empty| | END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end - it "should handle pre in table empty cells" do + it "should handle pre in table empty cells" do html = <<-END
      a
      d
      b
      c
      END @@ -51,12 +47,11 @@ b{noformat} |c | END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end - it "should handle pre in table" do + it "should handle pre in table" do html = <<-END @@ -78,7 +73,6 @@ 2{noformat} |3 | END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end diff --git a/spec/html2confluence_spec.rb b/spec/html2confluence_spec.rb index 027f194..f8171b2 100644 --- a/spec/html2confluence_spec.rb +++ b/spec/html2confluence_spec.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' - describe HTMLToConfluenceParser, "when converting html to textile" do + let(:parser) { HTMLToConfluenceParser.new } + context "in a large html document" do - before :all do + before do html = <<-END
      @@ -126,105 +124,105 @@ |Not table
      END - parser = HTMLToConfluenceParser.new + parser.feed(html) - @textile = parser.to_wiki_markup + @confluence = parser.to_wiki_markup end it "should convert heading tags" do - expect(@textile).to match(/^h1(\([^\)]+\))?\./) + expect(@confluence).to match(/^h1(\([^\)]+\))?\./) end it "should convert underline tags" do - expect(@textile).to include("text with +underlining+ is here") + expect(@confluence).to include("text with +underlining+ is here") end it "should not explicitly markup paragraphs unnecessarily" do - expect(@textile).to_not include("p. test paragraph without id or class attributes") + expect(@confluence).to_not include("p. test paragraph without id or class attributes") end it "should treat divs as block level elements, but ignore any attributes (effectively converting them to paragraphs)" do - expect(@textile).to include("\n\nA note\n\nFollowed by another note\n\n") + expect(@confluence).to include("\n\nA note\n\nFollowed by another note\n\n") end it "should not convert pointless spans to textile (i.e. without supported attributes)" do - expect(@textile).to_not include("%a useless span%") + expect(@confluence).to_not include("%a useless span%") end it "should convert class and id attributes" do - # We don't convert classes. expect(@textile).to include("h1(story.title entry-title#post-312).") + # We don't convert classes. expect(@confluence).to include("h1(story.title entry-title#post-312).") end it "should convert tables" do - expect(@textile).to include("\n\n||heading 1 ||heading 2 || \n|value 1 |value 2 | \n") + expect(@confluence).to include("\n\n||heading 1 ||heading 2 || \n|value 1 |value 2 | \n") end it "should convert tables with text immediately preceding the opening table tag" do - expect(@textile).to include("Some text before a table\n\n||heading 1 ||heading 2 || \n|value 1 |value 2 | \n") + expect(@confluence).to include("Some text before a table\n\n||heading 1 ||heading 2 || \n|value 1 |value 2 | \n") end it "should respect line breaks within block level elements" do - expect(@textile).to include("\n# test 1 \n# test 2\nwith a line break in the middle") + expect(@confluence).to include("\n# test 1 \n# test 2\nwith a line break in the middle") end it "should handle paragraphs nested within blockquote" do - expect(@textile).to include("{quote}\n\nparagraph inside a blockquote\n\nanother paragraph inside a blockquote\n\n{quote}") + expect(@confluence).to include("{quote}\n\nparagraph inside a blockquote\n\nanother paragraph inside a blockquote\n\n{quote}") end it "should retain leading and trailing whitespace within inline elements" do - expect(@textile).to include("test *invalid* list item 1") + expect(@confluence).to include("test *invalid* list item 1") end it "should respect trailing line break tags within other elements" do - expect(@textile).to include("*Please apply online at:*\n[www.something.co.uk/careers|http://www.something.co.uk/careers]") + expect(@confluence).to include("*Please apply online at:*\n[www.something.co.uk/careers|http://www.something.co.uk/careers]") end it "should handle nested inline elements" do - expect(@textile).to include(" *_test emphasised bold text_* test") + expect(@confluence).to include(" *_test emphasised bold text_* test") end it "should remove empty quicktags before returning" do - expect(@textile).to_not include("*more bold text* *\n*") + expect(@confluence).to_not include("*more bold text* *\n*") end it "should remove unsupported elements (e.g. script)" do - expect(@textile).to_not include('script') + expect(@confluence).to_not include('script') end it "should remove unsupported attributes (i.e. everything but class and id)" do - expect(@textile).to_not include('summary') - expect(@textile).to_not include('a table with a caption') - expect(@textile).to_not include('style') - expect(@textile).to_not include('color:red;') + expect(@confluence).to_not include('summary') + expect(@confluence).to_not include('a table with a caption') + expect(@confluence).to_not include('style') + expect(@confluence).to_not include('color:red;') end it "should clean up multiple blank lines created by tolerant parsing before returning" do - expect(@textile).to_not match(/(\n\n\s*){2,}/) + expect(@confluence).to_not match(/(\n\n\s*){2,}/) end it "should keep entity references" do - expect(@textile).to include("©") + expect(@confluence).to include("©") end it "should output unknown named entity references" do - expect(@textile).to include("&unknownref;") + expect(@confluence).to include("&unknownref;") end it "should convert numerical entity references to a utf-8 character" do - expect(@textile).to include("…") + expect(@confluence).to include("…") end it "should ignore entities that are already converted" do - expect(@textile).to include("Æïœü") + expect(@confluence).to include("Æïœü") end it "should ignore ampersands that are not part of an entity reference" do - expect(@textile).to include("Hughes & Hughes") + expect(@confluence).to include("Hughes & Hughes") end it "should retain whitespace surrounding entity references" do - expect(@textile).to include("… € 100") - expect(@textile).to include("Something & something") + expect(@confluence).to include("… € 100") + expect(@confluence).to include("Something & something") end it "should escape special characters" do @@ -232,22 +230,22 @@ # characters that would otherwise be mistaken for markup. It should not # escape every instance of these characters. pending 'only escape correct characters' - expect(@textile).to include("\\# Not a list") - expect(@textile).to include("\\* Not a list") - expect(@textile).to include("\\- Not a list") - expect(@textile).to include("\\*Not bold\\*") - expect(@textile).to include("\\_Not a emph\\_") - expect(@textile).to include("\\{Not curly\\}") - expect(@textile).to include("\\|Not table") + expect(@confluence).to include("\\# Not a list") + expect(@confluence).to include("\\* Not a list") + expect(@confluence).to include("\\- Not a list") + expect(@confluence).to include("\\*Not bold\\*") + expect(@confluence).to include("\\_Not a emph\\_") + expect(@confluence).to include("\\{Not curly\\}") + expect(@confluence).to include("\\|Not table") end it "should support strikethrough" do - expect(@textile).to include("-strike 1-") - expect(@textile).to include("-strike 2-") + expect(@confluence).to include("-strike 1-") + expect(@confluence).to include("-strike 2-") end it "should transform code" do - expect(@textile).to include("{code}some_good_code{code}") + expect(@confluence).to include("{code}some_good_code{code}") end end @@ -265,11 +263,10 @@ END - parser = HTMLToConfluenceParser.new parser.feed(html) - @textile = parser.to_wiki_markup + @confluence = parser.to_wiki_markup - expect(@textile).to eq("{quote}\n{noformat}\n\n{noformat} \n\n{noformat}\n\n{noformat} \n\n{quote}") + expect(@confluence).to eq("{quote}\n{noformat}\n\n{noformat} \n\n{noformat}\n\n{noformat} \n\n{quote}") end it "should convert ending blockquotes without a leading pre" do @@ -284,11 +281,10 @@ END - parser = HTMLToConfluenceParser.new parser.feed(html) - @textile = parser.to_wiki_markup + @confluence = parser.to_wiki_markup - expect(@textile).to eq("{quote}\n\n{noformat}\n\n{noformat} \n\n{quote}") + expect(@confluence).to eq("{quote}\n\n{noformat}\n\n{noformat} \n\n{quote}") end it "should convert ending blockquotes without a nested pre" do @@ -303,10 +299,9 @@ END - parser = HTMLToConfluenceParser.new parser.feed(html) - @textile = parser.to_wiki_markup + @confluence = parser.to_wiki_markup - expect(@textile).to eq("{quote}\n{noformat}\n\n{noformat} \n\n{quote}") + expect(@confluence).to eq("{quote}\n{noformat}\n\n{noformat} \n\n{quote}") end end diff --git a/spec/jira_examples_spec.rb b/spec/jira_examples_spec.rb index 77ff73a..a3390d4 100644 --- a/spec/jira_examples_spec.rb +++ b/spec/jira_examples_spec.rb @@ -1,317 +1,312 @@ -# encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' - describe HTMLToConfluenceParser, "when running JIRA examples" do - before :all do - html = <<-END -

      Biggest heading

      -

      Bigger heading

      -

      Big heading

      -

      Normal heading

      -
      Small heading
      -
      Smallest heading
      + let(:parser) { HTMLToConfluenceParser.new } -

      strong
      -emphasis
      -citation
      -deleted
      -inserted
      -superscript
      -subscript
      -monospaced

      -
      Some block quoted text
      + it "should convert images within a link" do + imagetarget = "https://example.com/image.jpg" + link = "https://example.com/index.html" + test_html = %{ +

      + + + +

      + } -
      -

      here is quotable
      - content to be quoted

      + parser.feed test_html + @textile = parser.to_wiki_markup -


      - look ma, red text!

      + expect(@textile).to eq("[!#{imagetarget}!|#{link}]") + end -

      a
      b

      + context "with large document" do + before do + html = <<-END +

      Biggest heading

      +

      Bigger heading

      +

      Big heading

      +

      Normal heading

      +
      Small heading
      +
      Smallest heading
      -

      a
      -b

      +

      strong
      + emphasis
      + citation
      + deleted
      + inserted
      + superscript
      + subscript
      + monospaced

      +
      Some block quoted text
      -
      +
      +

      here is quotable
      + content to be quoted

      -

      a – b
      -a — b

      +


      + look ma, red text!

      -

      anchor

      +

      a
      b

      -

      http://jira.atlassian.com
      -Atlassian

      +

      a
      + b

      -

      file:///c:/temp/foo.txt

      +
      -

      +

      a – b
      + a — b

      -
        -
      • some
      • -
      • bullet -
          -
        • indented
        • -
        • bullets
        • -
        -
      • -
      • points
      • -
      +

      anchor

      +

      http://jira.atlassian.com
      + Atlassian

      -
        -
      • different
      • -
      • bullet
      • -
      • types
      • -
      +

      file:///c:/temp/foo.txt

      +

      -
        -
      1. a
      2. -
      3. numbered
      4. -
      5. list
      6. -
      +
        +
      • some
      • +
      • bullet +
          +
        • indented
        • +
        • bullets
        • +
        +
      • +
      • points
      • +
      -
        -
      1. a
      2. -
      3. numbered -
          -
        • with
        • -
        • nested
        • +
            +
          • different
          • bullet
          • +
          • types
          - -
        • list
        • -
      -
        -
      • a
      • -
      • bulleted
          -
        1. with
        2. -
        3. nested
        4. +
        5. a
        6. numbered
        7. +
        8. list
        -
      • -
      • list
      • -
      - - -
      - - - - - - - - - - - - - - - -
      heading 1heading 2heading 3
      col A1col A2col A3
      col B1col B2col B3
      - - - - - - -
      -
      preformatted piece of text
      - so *no* further _formatting_ is done here
      -
      -
      - END - - markup = <<-END - h1. Biggest heading -h2. Bigger heading -h3. Big heading -h4. Normal heading -h5. Small heading -h6. Smallest heading - -*strong* -_emphasis_ -??citation?? --deleted- -+inserted+ -^superscript^ -~subscript~ -{{monospaced}} - -{quote} -Some block quoted text -{quote} - -{quote} - here is quotable - content to be quoted -{quote} - -{color:red} - look ma, red text! -{color} - -a\\b - -a -b - ----- - -a -- b -a --- b - -[#anchor] - -[http://jira.atlassian.com] -[Atlassian|http://atlassian.com] - -[file:///c:/temp/foo.txt] - -{anchor:anchorname} - -* some -* bullet -** indented -** bullets -* points - -- different -- bullet -- types - -# a -# numbered -# list - -# a -# numbered -#* with -#* nested -#* bullet -# list - -* a -* bulleted -*# with -*# nested -*# numbered -* list - -||heading 1||heading 2||heading 3|| -|col A1|col A2|col A3| -|col B1|col B2|col B3| - -{noformat} -preformatted piece of text - so *no* further _formatting_ is done here -{noformat} - END - - - parser = HTMLToConfluenceParser.new - parser.feed(html) - @textile = parser.to_wiki_markup - #puts @textile - #puts RedCloth.new(@textile).to_html - end - it "should convert images within a link" do - imagetarget = "https://example.com/image.jpg" - link = "https://example.com/index.html" - test_html = %{ -

      - - - -

      - } - parser = HTMLToConfluenceParser.new - parser.feed test_html - @textile = parser.to_wiki_markup +
        +
      1. a
      2. +
      3. numbered +
          +
        • with
        • +
        • nested
        • +
        • bullet
        • +
        +
      4. +
      5. list
      6. +
      - expect(@textile).to eq("[!#{imagetarget}!|#{link}]") - end - it "should convert heading tags" do - expect(@textile).to match(/^h1. Biggest heading/) - expect(@textile).to match(/^h2. Bigger heading/) - expect(@textile).to match(/^h3. Big heading/) - expect(@textile).to match(/^h4. Normal heading/) - expect(@textile).to match(/^h5. Small heading/) - expect(@textile).to match(/^h6. Smallest heading/) - end - - it "should convert inline formatting" do - expect(@textile).to match(/^\*strong\*/) - expect(@textile).to match(/^_emphasis_/) - expect(@textile).to match(/^\?\?citation\?\?/) - expect(@textile).to match(/^-deleted-/) - expect(@textile).to match(/^\+inserted\+/) - expect(@textile).to match(/^\^superscript\^/) - expect(@textile).to match(/^\~subscript\~/) - expect(@textile).to match(/^\{\{monospaced\}\}/) - end - - it "should convert block quotes" do - expect(@textile).to match(/^{quote}\nSome block quoted text\n{quote}/) - expect(@textile).to match(/^\{quote\}\s*here is quotable\s*content to be quoted\s*{quote}/) - end - - it "should handle text color" do - expect(@textile).to match(/^\{color\:red\}\s*look ma, red text!\s*\{color\}/) - end - - it "should convert horizontal rules" do - expect(@textile).to match(/^----/) - end - - it "should convert dashes" do - expect(@textile).to match(/^a -- b/) - expect(@textile).to match(/^a --- b/) - end - - it "should convert links" do - expect(@textile).to match(/^\[\#anchor\]/) - expect(@textile).to match(/^\[http\:\/\/jira.atlassian.com\]/) - expect(@textile).to match(/^\[Atlassian\|http\:\/\/atlassian.com\]/) - expect(@textile).to match(/^\[file\:\/\/\/c\:\/temp\/foo.txt\]/) - end - - it "should convert bullets" do - expect(@textile).to match(/\* some\s*\* bullet\s*\*\* indented\s*\*\* bullets\s*\* points/) - expect(@textile).to match(/- different\s*- bullet\s*- types/) - expect(@textile).to match(/# a\s*# numbered\s*# list/) - expect(@textile).to match(/# a\s*# numbered\s*#\* with\s*#\* nested\s*#\* bullet\s*# list/) - expect(@textile).to match(/\* a\s*\* bulleted\s*\*# with\s*\*# nested\s*\*# numbered\s*\* list/) - end - - it "should convert pre blocks" do - expect(@textile).to match(/^\{noformat\}\s*preformatted piece of text\s*so \*no\* further _formatting_ is done here\s*\{noformat\}/) - end - - it "should convert tables" do - expect(@textile).to include("||heading 1 ||heading 2 ||heading 3 ||") - expect(@textile).to include("|col A1 |col A2 |col A3 |") - expect(@textile).to include("|col B1 |col B2 |col B3 |") - end +
        +
      • a
      • +
      • bulleted +
          +
        1. with
        2. +
        3. nested
        4. +
        5. numbered
        6. +
        +
      • +
      • list
      • +
      + - it "should convert emoji from jira" do - expect(@textile).to include(":)") - expect(@textile).to include("(!)") - expect(@textile).to include("(off)") - expect(@textile).to include("(/)") - end + + + + + + + + + + + + + + + + +
      heading 1heading 2heading 3
      col A1col A2col A3
      col B1col B2col B3
      + + + + + + +
      +
      preformatted piece of text
      +   so *no* further _formatting_ is done here
      +  
      +
      + END + + markup = <<-END + h1. Biggest heading + h2. Bigger heading + h3. Big heading + h4. Normal heading + h5. Small heading + h6. Smallest heading + + *strong* + _emphasis_ + ??citation?? + -deleted- + +inserted+ + ^superscript^ + ~subscript~ + {{monospaced}} + + {quote} + Some block quoted text + {quote} + + {quote} + here is quotable + content to be quoted + {quote} + + {color:red} + look ma, red text! + {color} + + a\\b + + a + b + + ---- + + a -- b + a --- b + + [#anchor] + + [http://jira.atlassian.com] + [Atlassian|http://atlassian.com] + + [file:///c:/temp/foo.txt] + + {anchor:anchorname} + + * some + * bullet + ** indented + ** bullets + * points + + - different + - bullet + - types + + # a + # numbered + # list + + # a + # numbered + #* with + #* nested + #* bullet + # list + + * a + * bulleted + *# with + *# nested + *# numbered + * list + + ||heading 1||heading 2||heading 3|| + |col A1|col A2|col A3| + |col B1|col B2|col B3| + + {noformat} + preformatted piece of text + so *no* further _formatting_ is done here + {noformat} + END + + parser.feed(html) + @confluence = parser.to_wiki_markup + end + + it "should convert heading tags" do + expect(@confluence).to match(/^h1. Biggest heading/) + expect(@confluence).to match(/^h2. Bigger heading/) + expect(@confluence).to match(/^h3. Big heading/) + expect(@confluence).to match(/^h4. Normal heading/) + expect(@confluence).to match(/^h5. Small heading/) + expect(@confluence).to match(/^h6. Smallest heading/) + end + + it "should convert inline formatting" do + expect(@confluence).to match(/^\*strong\*/) + expect(@confluence).to match(/^_emphasis_/) + expect(@confluence).to match(/^\?\?citation\?\?/) + expect(@confluence).to match(/^-deleted-/) + expect(@confluence).to match(/^\+inserted\+/) + expect(@confluence).to match(/^\^superscript\^/) + expect(@confluence).to match(/^\~subscript\~/) + expect(@confluence).to match(/^\{\{monospaced\}\}/) + end + + it "should convert block quotes" do + expect(@confluence).to match(/^{quote}\nSome block quoted text\n{quote}/) + expect(@confluence).to match(/^\{quote\}\s*here is quotable\s*content to be quoted\s*{quote}/) + end + + it "should handle text color" do + expect(@confluence).to match(/^\{color\:red\}\s*look ma, red text!\s*\{color\}/) + end + + it "should convert horizontal rules" do + expect(@confluence).to match(/^----/) + end + + it "should convert dashes" do + expect(@confluence).to match(/^a -- b/) + expect(@confluence).to match(/^a --- b/) + end + + it "should convert links" do + expect(@confluence).to match(/^\[\#anchor\]/) + expect(@confluence).to match(/^\[http\:\/\/jira.atlassian.com\]/) + expect(@confluence).to match(/^\[Atlassian\|http\:\/\/atlassian.com\]/) + expect(@confluence).to match(/^\[file\:\/\/\/c\:\/temp\/foo.txt\]/) + end + + it "should convert bullets" do + expect(@confluence).to match(/\* some\s*\* bullet\s*\*\* indented\s*\*\* bullets\s*\* points/) + expect(@confluence).to match(/- different\s*- bullet\s*- types/) + expect(@confluence).to match(/# a\s*# numbered\s*# list/) + expect(@confluence).to match(/# a\s*# numbered\s*#\* with\s*#\* nested\s*#\* bullet\s*# list/) + expect(@confluence).to match(/\* a\s*\* bulleted\s*\*# with\s*\*# nested\s*\*# numbered\s*\* list/) + end + + it "should convert pre blocks" do + expect(@confluence).to match(/^\{noformat\}\s*preformatted piece of text\s*so \*no\* further _formatting_ is done here\s*\{noformat\}/) + end + + it "should convert tables" do + expect(@confluence).to include("||heading 1 ||heading 2 ||heading 3 ||") + expect(@confluence).to include("|col A1 |col A2 |col A3 |") + expect(@confluence).to include("|col B1 |col B2 |col B3 |") + end + + it "should convert emoji from jira" do + expect(@confluence).to include(":)") + expect(@confluence).to include("(!)") + expect(@confluence).to include("(off)") + expect(@confluence).to include("(/)") + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..8c3b69f --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,8 @@ +require 'rspec' +require 'html2confluence' + +RSpec.configure do |config| + config.filter_gems_from_backtrace "rspec-core", "rspec" + config.run_all_when_everything_filtered = true + config.order = :random +end