facwparser 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +18 -1
- data/lib/facwparser/element.rb +49 -33
- data/lib/facwparser/parser.rb +2 -0
- data/lib/facwparser/version.rb +1 -1
- data/tests/all_tests.rb +1 -1
- data/tests/units/element/test_code.rb +15 -0
- data/tests/units/element/test_heading.rb +32 -0
- data/tests/units/element/test_horizontal_rule.rb +14 -0
- data/tests/units/element/test_list.rb +20 -0
- data/tests/units/element/test_list_item.rb +20 -0
- data/tests/units/element/test_noformat.rb +15 -0
- data/tests/units/element/test_p.rb +44 -0
- data/tests/units/element/test_quote.rb +15 -0
- data/tests/units/element/test_table.rb +21 -0
- data/tests/units/element/test_table_data.rb +20 -0
- data/tests/units/element/test_table_headers.rb +20 -0
- data/tests/units/{parse → parser}/test_parse_value.rb +9 -0
- metadata +17 -7
- /data/tests/units/{parse → parser}/test_add_list_elements.rb +0 -0
- /data/tests/units/{parse → parser}/test_parse1.rb +0 -0
    
        data/README.md
    CHANGED
    
    | @@ -2,6 +2,8 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            Fuxxing Atlassian Confluence Wiki Parser
         | 
| 4 4 |  | 
| 5 | 
            +
            This is a loose Atlassian Confluence Wiki parser.
         | 
| 6 | 
            +
             | 
| 5 7 | 
             
            ## Installation
         | 
| 6 8 |  | 
| 7 9 | 
             
            Add this line to your application's Gemfile:
         | 
| @@ -18,7 +20,22 @@ Or install it yourself as: | |
| 18 20 |  | 
| 19 21 | 
             
            ## Usage
         | 
| 20 22 |  | 
| 21 | 
            -
             | 
| 23 | 
            +
            ```ruby
         | 
| 24 | 
            +
            require 'facwparser'
         | 
| 25 | 
            +
            print <<EOS
         | 
| 26 | 
            +
            <!DOCTYPE html>
         | 
| 27 | 
            +
            <html>
         | 
| 28 | 
            +
            <head>
         | 
| 29 | 
            +
            <title>sample</title>
         | 
| 30 | 
            +
            </head>
         | 
| 31 | 
            +
            <body>
         | 
| 32 | 
            +
            EOS
         | 
| 33 | 
            +
            print Facwparser.to_html(ARGF.read)
         | 
| 34 | 
            +
            print <<EOS
         | 
| 35 | 
            +
            </body>
         | 
| 36 | 
            +
            </html>
         | 
| 37 | 
            +
            EOS
         | 
| 38 | 
            +
            ```
         | 
| 22 39 |  | 
| 23 40 | 
             
            ## Contributing
         | 
| 24 41 |  | 
    
        data/lib/facwparser/element.rb
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # -*- encoding: utf-8 -*-
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'cgi'
         | 
| 4 | 
            +
            require File.dirname(__FILE__) + '/parser'
         | 
| 4 5 |  | 
| 5 6 |  | 
| 6 7 | 
             
            module Facwparser
         | 
| @@ -18,6 +19,13 @@ module Facwparser | |
| 18 19 | 
             
                  def render_html(options)
         | 
| 19 20 | 
             
                    raise "TODO: render_html is not implemented: " + self.class.to_s + "\n"
         | 
| 20 21 | 
             
                  end
         | 
| 22 | 
            +
                  private
         | 
| 23 | 
            +
                  def render_html_by_name_and_value(name, value, element_join_char = '')
         | 
| 24 | 
            +
                    ["<#{CGI.escapeHTML name}>", CGI.escapeHTML(value), "</#{CGI.escapeHTML name}>"].join(element_join_char)
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                  def render_html_by_name_and_childlen(name, children, options, childlen_join_char = '', element_join_char = '')
         | 
| 27 | 
            +
                    ["<#{CGI.escapeHTML name}>", children.map {|c| c.render_html(options) }.join(childlen_join_char), "</#{CGI.escapeHTML name}>"].join(element_join_char)
         | 
| 28 | 
            +
                  end
         | 
| 21 29 | 
             
                end
         | 
| 22 30 |  | 
| 23 31 | 
             
                class P < ElementBase
         | 
| @@ -25,12 +33,13 @@ module Facwparser | |
| 25 33 | 
             
                    @source += source
         | 
| 26 34 | 
             
                  end
         | 
| 27 35 | 
             
                  def render_html(options)
         | 
| 28 | 
            -
                    if source =~ /\A *bq. (.+)/m
         | 
| 29 | 
            -
                       | 
| 30 | 
            -
             | 
| 36 | 
            +
                    if @source =~ /\A *bq. (.+)/m
         | 
| 37 | 
            +
                      "<blockquote>\n" +
         | 
| 38 | 
            +
                        render_html_by_name_and_value('p', $1).gsub("\n", '<br>') + "\n" +
         | 
| 39 | 
            +
                        "</blockquote>\n"
         | 
| 31 40 | 
             
                    else
         | 
| 32 | 
            -
                      @children ||= Parser.parse_value(source, options)
         | 
| 33 | 
            -
                       | 
| 41 | 
            +
                      @children ||= Parser.parse_value(@source, options)
         | 
| 42 | 
            +
                      render_html_by_name_and_childlen('p', @children, options) + "\n"
         | 
| 34 43 | 
             
                    end
         | 
| 35 44 | 
             
                  end
         | 
| 36 45 | 
             
                end
         | 
| @@ -47,7 +56,8 @@ module Facwparser | |
| 47 56 | 
             
                    @value = value
         | 
| 48 57 | 
             
                  end
         | 
| 49 58 | 
             
                  def render_html(options)
         | 
| 50 | 
            -
                     | 
| 59 | 
            +
                    @children = Parser.parse_value value, options
         | 
| 60 | 
            +
                    render_html_by_name_and_childlen("h#{level}", @children, options) + "\n"
         | 
| 51 61 | 
             
                  end
         | 
| 52 62 | 
             
                end
         | 
| 53 63 | 
             
                class List < ElementBase
         | 
| @@ -62,12 +72,7 @@ module Facwparser | |
| 62 72 | 
             
                    self
         | 
| 63 73 | 
             
                  end
         | 
| 64 74 | 
             
                  def render_html(options)
         | 
| 65 | 
            -
                     | 
| 66 | 
            -
                    when '#'
         | 
| 67 | 
            -
                      return "<ol>\n" + @children.map{ |c| c.render_html(options) }.join("") + "</ol>\n"
         | 
| 68 | 
            -
                    else
         | 
| 69 | 
            -
                      return "<ul>\n" + @children.map{ |c| c.render_html(options) }.join("") + "</ul>\n"
         | 
| 70 | 
            -
                    end
         | 
| 75 | 
            +
                    (render_html_by_name_and_childlen(@type == '#' ? 'ol' : 'ul', @children, options, "\n", "\n") + "\n").gsub("\n\n", "\n")
         | 
| 71 76 | 
             
                  end
         | 
| 72 77 | 
             
                end
         | 
| 73 78 | 
             
                class ListItem < ElementBase
         | 
| @@ -79,8 +84,8 @@ module Facwparser | |
| 79 84 | 
             
                    @value = value
         | 
| 80 85 | 
             
                  end
         | 
| 81 86 | 
             
                  def render_html(options)
         | 
| 82 | 
            -
                    @children  | 
| 83 | 
            -
                     | 
| 87 | 
            +
                    @children ||= Parser.parse_value value, options
         | 
| 88 | 
            +
                    render_html_by_name_and_childlen('li', @children, options)
         | 
| 84 89 | 
             
                  end
         | 
| 85 90 | 
             
                end
         | 
| 86 91 | 
             
                class Table < ElementBase
         | 
| @@ -93,21 +98,21 @@ module Facwparser | |
| 93 98 | 
             
                    self
         | 
| 94 99 | 
             
                  end
         | 
| 95 100 | 
             
                  def render_html(options)
         | 
| 96 | 
            -
                    "<table | 
| 97 | 
            -
                    "\n | 
| 98 | 
            -
                    @children.drop(1) | 
| 99 | 
            -
                    " | 
| 101 | 
            +
                    "<table>\n" +
         | 
| 102 | 
            +
                    render_html_by_name_and_childlen('thead', @children.take(1), options, "\n", "\n") + "\n" +
         | 
| 103 | 
            +
                    render_html_by_name_and_childlen('tbody', @children.drop(1), options, "\n", "\n") + "\n" +
         | 
| 104 | 
            +
                    "</table>\n"
         | 
| 100 105 | 
             
                  end
         | 
| 101 106 | 
             
                end
         | 
| 102 107 | 
             
                class TableHeaders < ElementBase
         | 
| 103 108 | 
             
                  attr_reader :elements
         | 
| 104 109 | 
             
                  def initialize(source)
         | 
| 105 110 | 
             
                    super(source)
         | 
| 106 | 
            -
                    @elements = source.split('||') | 
| 111 | 
            +
                    @elements = source[2..-3].split('||')
         | 
| 107 112 | 
             
                  end
         | 
| 108 113 | 
             
                  def render_html(options)
         | 
| 109 114 | 
             
                    "<tr>" +
         | 
| 110 | 
            -
                      @elements.map { |e| ' | 
| 115 | 
            +
                      @elements.map { |e| render_html_by_name_and_childlen('th', Parser.parse_value(e, options), options) }.join() +
         | 
| 111 116 | 
             
                    "</tr>"
         | 
| 112 117 | 
             
                  end
         | 
| 113 118 | 
             
                end
         | 
| @@ -145,7 +150,7 @@ module Facwparser | |
| 145 150 | 
             
                  end
         | 
| 146 151 | 
             
                  def render_html(options)
         | 
| 147 152 | 
             
                    "<tr>" +
         | 
| 148 | 
            -
                      @elements.map { |e| ' | 
| 153 | 
            +
                      @elements.map { |e| render_html_by_name_and_childlen('td', Parser.parse_value(e, options), options) }.join() +
         | 
| 149 154 | 
             
                    "</tr>"
         | 
| 150 155 | 
             
                  end
         | 
| 151 156 | 
             
                end
         | 
| @@ -176,7 +181,7 @@ module Facwparser | |
| 176 181 | 
             
                    @value = value
         | 
| 177 182 | 
             
                  end
         | 
| 178 183 | 
             
                  def render_html(options)
         | 
| 179 | 
            -
                     | 
| 184 | 
            +
                    render_html_by_name_and_value('pre', @value, "\n") + "\n"
         | 
| 180 185 | 
             
                  end
         | 
| 181 186 | 
             
                end
         | 
| 182 187 | 
             
                class CodeMacro < MacroBase
         | 
| @@ -186,7 +191,9 @@ module Facwparser | |
| 186 191 | 
             
                    @value = value
         | 
| 187 192 | 
             
                  end
         | 
| 188 193 | 
             
                  def render_html(options)
         | 
| 189 | 
            -
                    "< | 
| 194 | 
            +
                    "<pre class=\"#{CGI.escapeHTML(@options[1..-1])}\">\n" +
         | 
| 195 | 
            +
                      render_html_by_name_and_value('code', @value, "\n") + "\n" +
         | 
| 196 | 
            +
                      "</pre>" + "\n"
         | 
| 190 197 | 
             
                  end
         | 
| 191 198 | 
             
                end
         | 
| 192 199 | 
             
                class QuoteMacro < MacroBase
         | 
| @@ -195,7 +202,9 @@ module Facwparser | |
| 195 202 | 
             
                    @value = value
         | 
| 196 203 | 
             
                  end
         | 
| 197 204 | 
             
                  def render_html(options)
         | 
| 198 | 
            -
                    "<blockquote>\n | 
| 205 | 
            +
                    "<blockquote>\n" +
         | 
| 206 | 
            +
                      render_html_by_name_and_value('p', @value).gsub("\n", '<br>') + "\n" +
         | 
| 207 | 
            +
                      "</blockquote>\n"
         | 
| 199 208 | 
             
                  end
         | 
| 200 209 | 
             
                end
         | 
| 201 210 |  | 
| @@ -224,49 +233,49 @@ module Facwparser | |
| 224 233 |  | 
| 225 234 | 
             
                class Bold < InlineElementBase
         | 
| 226 235 | 
             
                  def render_html(options)
         | 
| 227 | 
            -
                     | 
| 236 | 
            +
                    render_html_by_name_and_value('b', @text)
         | 
| 228 237 | 
             
                  end
         | 
| 229 238 | 
             
                end
         | 
| 230 239 |  | 
| 231 240 | 
             
                class Italic < InlineElementBase
         | 
| 232 241 | 
             
                  def render_html(options)
         | 
| 233 | 
            -
                     | 
| 242 | 
            +
                    render_html_by_name_and_value('i', @text)
         | 
| 234 243 | 
             
                  end
         | 
| 235 244 | 
             
                end
         | 
| 236 245 |  | 
| 237 246 | 
             
                class Strike < InlineElementBase
         | 
| 238 247 | 
             
                  def render_html(options)
         | 
| 239 | 
            -
                     | 
| 248 | 
            +
                    render_html_by_name_and_value('s', @text)
         | 
| 240 249 | 
             
                  end
         | 
| 241 250 | 
             
                end
         | 
| 242 251 |  | 
| 243 252 | 
             
                class Under < InlineElementBase
         | 
| 244 253 | 
             
                  def render_html(options)
         | 
| 245 | 
            -
                     | 
| 254 | 
            +
                    render_html_by_name_and_value('u', @text)
         | 
| 246 255 | 
             
                  end
         | 
| 247 256 | 
             
                end
         | 
| 248 257 |  | 
| 249 258 | 
             
                class Q < InlineElementBase
         | 
| 250 259 | 
             
                  def render_html(options)
         | 
| 251 | 
            -
                     | 
| 260 | 
            +
                    render_html_by_name_and_value('q', @text)
         | 
| 252 261 | 
             
                  end
         | 
| 253 262 | 
             
                end
         | 
| 254 263 |  | 
| 255 264 | 
             
                class SUP < InlineElementBase
         | 
| 256 265 | 
             
                  def render_html(options)
         | 
| 257 | 
            -
                     | 
| 266 | 
            +
                    render_html_by_name_and_value('sup', @text)
         | 
| 258 267 | 
             
                  end
         | 
| 259 268 | 
             
                end
         | 
| 260 269 |  | 
| 261 270 | 
             
                class SUB < InlineElementBase
         | 
| 262 271 | 
             
                  def render_html(options)
         | 
| 263 | 
            -
                     | 
| 272 | 
            +
                    render_html_by_name_and_value('sub', @text)
         | 
| 264 273 | 
             
                  end
         | 
| 265 274 | 
             
                end
         | 
| 266 275 |  | 
| 267 276 | 
             
                class TT < InlineElementBase
         | 
| 268 277 | 
             
                  def render_html(options)
         | 
| 269 | 
            -
                     | 
| 278 | 
            +
                    render_html_by_name_and_value('tt', @text)
         | 
| 270 279 | 
             
                  end
         | 
| 271 280 | 
             
                end
         | 
| 272 281 |  | 
| @@ -284,7 +293,7 @@ module Facwparser | |
| 284 293 | 
             
                  end
         | 
| 285 294 | 
             
                  def render_html(options)
         | 
| 286 295 | 
             
                    jira_browse_url = (options && options['jira_browse_url']) || ''
         | 
| 287 | 
            -
                    return '<a href="' + CGI.escapeHTML(jira_browse_url | 
| 296 | 
            +
                    return '<a href="' + CGI.escapeHTML(jira_browse_url + @options) +'">' + CGI.escapeHTML(@options) + '</a>'
         | 
| 288 297 | 
             
                  end
         | 
| 289 298 | 
             
                end
         | 
| 290 299 |  | 
| @@ -313,5 +322,12 @@ module Facwparser | |
| 313 322 | 
             
                    CGI.escapeHTML @source
         | 
| 314 323 | 
             
                  end
         | 
| 315 324 | 
             
                end
         | 
| 325 | 
            +
             | 
| 326 | 
            +
                class Br < InlineElementBase
         | 
| 327 | 
            +
                  def render_html(options)
         | 
| 328 | 
            +
                    '<br>'
         | 
| 329 | 
            +
                  end
         | 
| 330 | 
            +
                end
         | 
| 331 | 
            +
             | 
| 316 332 | 
             
              end
         | 
| 317 333 | 
             
            end
         | 
    
        data/lib/facwparser/parser.rb
    CHANGED
    
    | @@ -163,6 +163,8 @@ module Facwparser | |
| 163 163 | 
             
                        children << Element::ColorMacroEnd.new(s[0])
         | 
| 164 164 | 
             
                      when s.scan(/[^\[^\\*_+{!-]+/)
         | 
| 165 165 | 
             
                        children << Element::Text.new(s[0], unescape_text(s[0]))
         | 
| 166 | 
            +
                      when s.scan(/\\\\/)
         | 
| 167 | 
            +
                        children << Element::Br.new(s[0], unescape_text(s[0]))
         | 
| 166 168 | 
             
                      when s.scan(/\\[\[\]\*+_?{}!^~-]/)
         | 
| 167 169 | 
             
                        children << Element::Text.new(s[0], unescape_text(s[0]))
         | 
| 168 170 | 
             
                      else
         | 
    
        data/lib/facwparser/version.rb
    CHANGED
    
    
    
        data/tests/all_tests.rb
    CHANGED
    
    
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestCode < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_code_1
         | 
| 9 | 
            +
                code = Facwparser::Element::CodeMacro.new("{code:perl}\n*a*\n{code}\n", ':perl', '*a*')
         | 
| 10 | 
            +
                assert_equal(%Q{<pre class="perl">\n<code>\n*a*\n</code>\n</pre>\n},
         | 
| 11 | 
            +
                             code.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestHeading < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_heading_1
         | 
| 9 | 
            +
                heading = Facwparser::Element::Heading.new('h1. hoge', 1, 'hoge')
         | 
| 10 | 
            +
                assert_equal("<h1>hoge</h1>\n",
         | 
| 11 | 
            +
                             heading.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def test_heading_2
         | 
| 15 | 
            +
                heading = Facwparser::Element::Heading.new('h3. hoge>', 3, 'hoge>')
         | 
| 16 | 
            +
                assert_equal("<h3>hoge></h3>\n",
         | 
| 17 | 
            +
                             heading.render_html({}))
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def test_heading_3
         | 
| 21 | 
            +
                heading = Facwparser::Element::Heading.new('h1. hoge[http://www.unixuser.org]', 1, 'hoge[http://www.unixuser.org]')
         | 
| 22 | 
            +
                assert_equal(%Q{<h1>hoge<a href="http://www.unixuser.org">http://www.unixuser.org</a></h1>\n},
         | 
| 23 | 
            +
                             heading.render_html({}))
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def test_heading_4
         | 
| 27 | 
            +
                heading = Facwparser::Element::Heading.new('h1. hoge [http://www.unixuser.org]', 1, 'hoge [http://www.unixuser.org]')
         | 
| 28 | 
            +
                assert_equal(%Q{<h1>hoge <a href="http://www.unixuser.org">http://www.unixuser.org</a></h1>\n},
         | 
| 29 | 
            +
                             heading.render_html({}))
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| 32 | 
            +
             | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestHr < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_hr
         | 
| 9 | 
            +
                hr = Facwparser::Element::HorizontalRule.new('----')
         | 
| 10 | 
            +
                assert_equal("<hr>\n",
         | 
| 11 | 
            +
                             hr.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| 14 | 
            +
             | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestList < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_list_1
         | 
| 9 | 
            +
                ul = Facwparser::Element::List.new('*')
         | 
| 10 | 
            +
                ul.push Facwparser::Element::ListItem.new('* hoge', '*', 'hoge')
         | 
| 11 | 
            +
                ol = Facwparser::Element::List.new('#')
         | 
| 12 | 
            +
                ul.push ol
         | 
| 13 | 
            +
                ol.push Facwparser::Element::ListItem.new('## kuke', '##', 'kuke')
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                assert_equal(%Q{<ul>\n<li>hoge</li>\n<ol>\n<li>kuke</li>\n</ol>\n</ul>\n},
         | 
| 16 | 
            +
                             ul.render_html({}))
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestListItem < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_list_item_1
         | 
| 9 | 
            +
                li = Facwparser::Element::ListItem.new('* hoge', '*', 'hoge')
         | 
| 10 | 
            +
                assert_equal(%Q{<li>hoge</li>},
         | 
| 11 | 
            +
                             li.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def test_list_item_2
         | 
| 15 | 
            +
                li = Facwparser::Element::ListItem.new('## hoge*nyo*', '##', 'hoge*nyo*')
         | 
| 16 | 
            +
                assert_equal(%Q{<li>hoge<b>nyo</b></li>},
         | 
| 17 | 
            +
                             li.render_html({}))
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestNoformat < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_noformat_1
         | 
| 9 | 
            +
                noformat = Facwparser::Element::NoformatMacro.new("{noformat}\n*a*\n{noformat}\n", '*a*')
         | 
| 10 | 
            +
                assert_equal(%Q{<pre>\n*a*\n</pre>\n},
         | 
| 11 | 
            +
                             noformat.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestP < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_p_1
         | 
| 9 | 
            +
                p = Facwparser::Element::P.new('hoge')
         | 
| 10 | 
            +
                assert_equal("<p>hoge</p>\n",
         | 
| 11 | 
            +
                             p.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def test_p_2
         | 
| 15 | 
            +
                p = Facwparser::Element::P.new("hoge\nkuke")
         | 
| 16 | 
            +
                assert_equal("<p>hogekuke</p>\n",
         | 
| 17 | 
            +
                             p.render_html({}))
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def test_p_3
         | 
| 21 | 
            +
                p = Facwparser::Element::P.new("hoge\\\\\nkuke")
         | 
| 22 | 
            +
                assert_equal("<p>hoge<br>kuke</p>\n",
         | 
| 23 | 
            +
                             p.render_html({}))
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def test_p_4
         | 
| 27 | 
            +
                p = Facwparser::Element::P.new("<>")
         | 
| 28 | 
            +
                assert_equal("<p><></p>\n",
         | 
| 29 | 
            +
                             p.render_html({}))
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def test_p_blockquote
         | 
| 33 | 
            +
                p = Facwparser::Element::P.new('bq. hoge')
         | 
| 34 | 
            +
                assert_equal("<blockquote>\n<p>hoge</p>\n</blockquote>\n",
         | 
| 35 | 
            +
                             p.render_html({}))
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              def test_p_blockquote_2
         | 
| 39 | 
            +
                p = Facwparser::Element::P.new(" bq. hoge\n kuke")
         | 
| 40 | 
            +
                assert_equal("<blockquote>\n<p>hoge<br> kuke</p>\n</blockquote>\n",
         | 
| 41 | 
            +
                             p.render_html({}))
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
            end
         | 
| 44 | 
            +
             | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestQuote < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_quote_=
         | 
| 9 | 
            +
                quote = Facwparser::Element::QuoteMacro.new("{qoute}\n*a*\n\n{quote}\n", "*a*\n")
         | 
| 10 | 
            +
                assert_equal(%Q{<blockquote>\n<p>*a*<br></p>\n</blockquote>\n},
         | 
| 11 | 
            +
                             quote.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestTable < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_table_1
         | 
| 9 | 
            +
                table = Facwparser::Element::Table.new
         | 
| 10 | 
            +
                tr = Facwparser::Element::TableHeaders.new('||hoge||kuke||')
         | 
| 11 | 
            +
                td1 = Facwparser::Element::TableData.new('|1|2|')
         | 
| 12 | 
            +
                td2 = Facwparser::Element::TableData.new('|3|4|')
         | 
| 13 | 
            +
                table.push tr
         | 
| 14 | 
            +
                table.push td1
         | 
| 15 | 
            +
                table.push td2
         | 
| 16 | 
            +
                assert_equal(%Q{<table>\n<thead>\n<tr><th>hoge</th><th>kuke</th></tr>\n</thead>\n<tbody>\n<tr><td>1</td><td>2</td></tr>\n<tr><td>3</td><td>4</td></tr>\n</tbody>\n</table>\n},
         | 
| 17 | 
            +
                             table.render_html({}))
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestTableData < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_table_data_1
         | 
| 9 | 
            +
                td = Facwparser::Element::TableData.new('|hoge|kuke|')
         | 
| 10 | 
            +
                assert_equal(%Q{<tr><td>hoge</td><td>kuke</td></tr>},
         | 
| 11 | 
            +
                             td.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def test_table_data_2
         | 
| 15 | 
            +
                td = Facwparser::Element::TableData.new('|hoge|[hoge|http://www.unixuser.org]|')
         | 
| 16 | 
            +
                assert_equal(%Q{<tr><td>hoge</td><td><a href="http://www.unixuser.org">hoge</a></td></tr>},
         | 
| 17 | 
            +
                             td.render_html({}))
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            require 'test/unit'
         | 
| 3 | 
            +
            require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            class TestTableHeaders < Test::Unit::TestCase
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def test_table_headers_1
         | 
| 9 | 
            +
                tr = Facwparser::Element::TableHeaders.new('||hoge||kuke||')
         | 
| 10 | 
            +
                assert_equal(%Q{<tr><th>hoge</th><th>kuke</th></tr>},
         | 
| 11 | 
            +
                             tr.render_html({}))
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def test_table_headers_2
         | 
| 15 | 
            +
                tr = Facwparser::Element::TableHeaders.new('||hoge||[hoge|http://www.unixuser.org]||')
         | 
| 16 | 
            +
                assert_equal(%Q{<tr><th>hoge</th><th><a href="http://www.unixuser.org">hoge</a></th></tr>},
         | 
| 17 | 
            +
                             tr.render_html({}))
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| @@ -79,6 +79,15 @@ class TestParseValue < Test::Unit::TestCase | |
| 79 79 | 
             
                ], Facwparser::Parser.parse_value('1{jira:SYSTEMRD-1}2', {}))
         | 
| 80 80 | 
             
              end
         | 
| 81 81 |  | 
| 82 | 
            +
              def test_parse_value_br
         | 
| 83 | 
            +
                  assert_equal([
         | 
| 84 | 
            +
                    Facwparser::Element::Text.new('1', '1'),
         | 
| 85 | 
            +
                    Facwparser::Element::Br.new("\\\\", "\\\\"),
         | 
| 86 | 
            +
                    Facwparser::Element::Text.new('2', '2')
         | 
| 87 | 
            +
                ], Facwparser::Parser.parse_value("1\\\\2", {}))
         | 
| 88 | 
            +
              end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
             | 
| 82 91 | 
             
              def test_parse_value_jira_misc
         | 
| 83 92 | 
             
                  assert_equal([
         | 
| 84 93 | 
             
                    Facwparser::Element::Text.new('1', '1'),
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: facwparser
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013-02- | 
| 12 | 
            +
            date: 2013-02-14 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies: []
         | 
| 14 14 | 
             
            description: Fuxxing Atlassian Confluence Wiki Parser
         | 
| 15 15 | 
             
            email:
         | 
| @@ -31,9 +31,20 @@ files: | |
| 31 31 | 
             
            - lib/facwparser/version.rb
         | 
| 32 32 | 
             
            - sample/confluence2html.rb
         | 
| 33 33 | 
             
            - tests/all_tests.rb
         | 
| 34 | 
            -
            - tests/units/ | 
| 35 | 
            -
            - tests/units/ | 
| 36 | 
            -
            - tests/units/ | 
| 34 | 
            +
            - tests/units/element/test_code.rb
         | 
| 35 | 
            +
            - tests/units/element/test_heading.rb
         | 
| 36 | 
            +
            - tests/units/element/test_horizontal_rule.rb
         | 
| 37 | 
            +
            - tests/units/element/test_list.rb
         | 
| 38 | 
            +
            - tests/units/element/test_list_item.rb
         | 
| 39 | 
            +
            - tests/units/element/test_noformat.rb
         | 
| 40 | 
            +
            - tests/units/element/test_p.rb
         | 
| 41 | 
            +
            - tests/units/element/test_quote.rb
         | 
| 42 | 
            +
            - tests/units/element/test_table.rb
         | 
| 43 | 
            +
            - tests/units/element/test_table_data.rb
         | 
| 44 | 
            +
            - tests/units/element/test_table_headers.rb
         | 
| 45 | 
            +
            - tests/units/parser/test_add_list_elements.rb
         | 
| 46 | 
            +
            - tests/units/parser/test_parse1.rb
         | 
| 47 | 
            +
            - tests/units/parser/test_parse_value.rb
         | 
| 37 48 | 
             
            homepage: https://github.com/haruyama/facwparser
         | 
| 38 49 | 
             
            licenses: []
         | 
| 39 50 | 
             
            post_install_message: 
         | 
| @@ -54,9 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 54 65 | 
             
                  version: '0'
         | 
| 55 66 | 
             
            requirements: []
         | 
| 56 67 | 
             
            rubyforge_project: 
         | 
| 57 | 
            -
            rubygems_version: 1.8. | 
| 68 | 
            +
            rubygems_version: 1.8.25
         | 
| 58 69 | 
             
            signing_key: 
         | 
| 59 70 | 
             
            specification_version: 3
         | 
| 60 71 | 
             
            summary: Parser of Atlassian Confluence Wiki Markup.
         | 
| 61 72 | 
             
            test_files: []
         | 
| 62 | 
            -
            has_rdoc: 
         | 
| 
            File without changes
         | 
| 
            File without changes
         |