facwparser 0.0.3 → 0.0.4
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/lib/facwparser/element.rb +11 -10
- data/lib/facwparser/parser.rb +7 -8
- data/lib/facwparser/version.rb +1 -1
- data/tests/units/element/test_br.rb +13 -0
- data/tests/units/element/test_color_end.rb +12 -0
- data/tests/units/element/test_color_start.rb +12 -0
- data/tests/units/element/test_emphasis.rb +12 -0
- data/tests/units/element/test_monospace.rb +12 -0
- data/tests/units/element/test_noformat.rb +1 -1
- data/tests/units/element/test_q.rb +12 -0
- data/tests/units/element/test_strike.rb +12 -0
- data/tests/units/element/test_strong.rb +12 -0
- data/tests/units/element/test_sub.rb +12 -0
- data/tests/units/element/test_sup.rb +12 -0
- data/tests/units/element/test_table.rb +3 -3
- data/tests/units/element/test_table_data.rb +2 -2
- data/tests/units/element/test_table_headers.rb +2 -2
- data/tests/units/element/test_text.rb +12 -0
- data/tests/units/element/test_under.rb +12 -0
- data/tests/units/parser/test_parse1.rb +2 -2
- data/tests/units/parser/test_parse_value.rb +1 -1
- metadata +14 -2
data/lib/facwparser/element.rb
CHANGED
@@ -124,9 +124,9 @@ module Facwparser
|
|
124
124
|
end
|
125
125
|
class TableHeaders < ElementBase
|
126
126
|
attr_reader :elements
|
127
|
-
def initialize(source)
|
127
|
+
def initialize(source, value)
|
128
128
|
super(source)
|
129
|
-
@elements =
|
129
|
+
@elements = value[2..-3].split('||')
|
130
130
|
end
|
131
131
|
def render_html(options)
|
132
132
|
"<tr>" +
|
@@ -136,11 +136,11 @@ module Facwparser
|
|
136
136
|
end
|
137
137
|
class TableData < ElementBase
|
138
138
|
attr_reader :elements
|
139
|
-
def initialize(source)
|
139
|
+
def initialize(source, value)
|
140
140
|
super(source)
|
141
141
|
@elements = []
|
142
142
|
element = ''
|
143
|
-
s = StringScanner.new(
|
143
|
+
s = StringScanner.new(value[1..-2])
|
144
144
|
in_link = false
|
145
145
|
while s.rest?
|
146
146
|
case
|
@@ -195,7 +195,7 @@ module Facwparser
|
|
195
195
|
@value = value
|
196
196
|
end
|
197
197
|
def render_html(options)
|
198
|
-
render_html_by_name_and_value('pre', @value, "\n") + "\n"
|
198
|
+
render_html_by_name_and_value(['pre', {'class' => 'noformat'}] , @value, "\n") + "\n"
|
199
199
|
end
|
200
200
|
end
|
201
201
|
class CodeMacro < MacroBase
|
@@ -260,9 +260,7 @@ module Facwparser
|
|
260
260
|
|
261
261
|
class Strike < InlineElementBase
|
262
262
|
def render_html(options)
|
263
|
-
'
|
264
|
-
CGI.escapeHTML(@text) +
|
265
|
-
'</span>'
|
263
|
+
render_html_by_name_and_value(['span', {'style' => 'text-decoration: line-through;'}] , @text)
|
266
264
|
end
|
267
265
|
end
|
268
266
|
|
@@ -278,13 +276,13 @@ module Facwparser
|
|
278
276
|
end
|
279
277
|
end
|
280
278
|
|
281
|
-
class
|
279
|
+
class Sup < InlineElementBase
|
282
280
|
def render_html(options)
|
283
281
|
render_html_by_name_and_value('sup', @text)
|
284
282
|
end
|
285
283
|
end
|
286
284
|
|
287
|
-
class
|
285
|
+
class Sub < InlineElementBase
|
288
286
|
def render_html(options)
|
289
287
|
render_html_by_name_and_value('sub', @text)
|
290
288
|
end
|
@@ -341,6 +339,9 @@ module Facwparser
|
|
341
339
|
end
|
342
340
|
|
343
341
|
class Br < InlineElementBase
|
342
|
+
def initialize(source)
|
343
|
+
super(source, source)
|
344
|
+
end
|
344
345
|
def render_html(options)
|
345
346
|
'<br>'
|
346
347
|
end
|
data/lib/facwparser/parser.rb
CHANGED
@@ -12,7 +12,6 @@ module Facwparser
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.process_elements(elements, options)
|
15
|
-
# TODO toc
|
16
15
|
processed = add_list_elements(elements, options)
|
17
16
|
processed = add_table_elements(processed, options)
|
18
17
|
processed = add_toc(processed, options)
|
@@ -97,12 +96,12 @@ module Facwparser
|
|
97
96
|
when s.scan(/([*\-#]+) +(.+)\n/)
|
98
97
|
p = nil
|
99
98
|
elements << Element::ListItem.new(s[0], s[1], s[2])
|
100
|
-
when s.scan(
|
99
|
+
when s.scan(/(\|\|.+\|\|) *\n/)
|
101
100
|
p = nil
|
102
|
-
elements << Element::TableHeaders.new(s[0])
|
103
|
-
when s.scan(
|
101
|
+
elements << Element::TableHeaders.new(s[0], s[1])
|
102
|
+
when s.scan(/(\|.+\|) *\n/)
|
104
103
|
p = nil
|
105
|
-
elements << Element::TableData.new(s[0])
|
104
|
+
elements << Element::TableData.new(s[0], s[1])
|
106
105
|
when s.scan(/\{toc(:.*)?\} *\n/)
|
107
106
|
p = nil
|
108
107
|
elements << Element::TocMacro.new(s[0], s[1] ? s[1][1,] : nil)
|
@@ -159,9 +158,9 @@ module Facwparser
|
|
159
158
|
when s.scan(/\+(.+?)(?<!\\)\+/)
|
160
159
|
children << Element::Under.new(s[0], unescape_text(s[1]))
|
161
160
|
when s.scan(/\^(.+?)(?<!\\)\^/)
|
162
|
-
children << Element::
|
161
|
+
children << Element::Sup.new(s[0], unescape_text(s[1]))
|
163
162
|
when s.scan(/\~(.+?)(?<!\\)\~/)
|
164
|
-
children << Element::
|
163
|
+
children << Element::Sub.new(s[0], unescape_text(s[1]))
|
165
164
|
when s.scan(/\?\?(.+?)(?<!\\)\?\?/)
|
166
165
|
children << Element::Q.new(s[0], unescape_text(s[1]))
|
167
166
|
when s.scan(/\{\{(.+?)(?<!\\)\}\}/)
|
@@ -179,7 +178,7 @@ module Facwparser
|
|
179
178
|
when s.scan(/[^\[^\\*_+{!-]+/)
|
180
179
|
children << Element::Text.new(s[0], unescape_text(s[0]))
|
181
180
|
when s.scan(/\\\\/)
|
182
|
-
children << Element::Br.new(s[0]
|
181
|
+
children << Element::Br.new(s[0])
|
183
182
|
when s.scan(/\\[\[\]\*+_?{}!^~-]/)
|
184
183
|
children << Element::Text.new(s[0], unescape_text(s[0]))
|
185
184
|
else
|
data/lib/facwparser/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
require 'test/unit'
|
4
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
5
|
+
|
6
|
+
class TestBr < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_br_1
|
9
|
+
br = Facwparser::Element::Br.new('\\\\')
|
10
|
+
assert_equal(%Q{<br>},
|
11
|
+
br.render_html({}))
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestColorEnd < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_color_end_1
|
8
|
+
ce = Facwparser::Element::ColorMacroEnd.new('{color}')
|
9
|
+
assert_equal(%Q{</span>},
|
10
|
+
ce.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestColorStart < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_color_start_1
|
8
|
+
cs = Facwparser::Element::ColorMacroStart.new('{color:red}', 'red')
|
9
|
+
assert_equal(%Q{<span style="color: red">},
|
10
|
+
cs.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestEmphasis < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_emphasis_1
|
8
|
+
emphasis = Facwparser::Element::Emphasis.new('_hoge_', 'hoge')
|
9
|
+
assert_equal(%Q{<em>hoge</em>},
|
10
|
+
emphasis.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestMonospace < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_monospace_1
|
8
|
+
monospace = Facwparser::Element::Monospace.new('{{hoge}}', 'hoge')
|
9
|
+
assert_equal(%Q{<code>hoge</code>},
|
10
|
+
monospace.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -7,7 +7,7 @@ class TestNoformat < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
def test_noformat_1
|
9
9
|
noformat = Facwparser::Element::NoformatMacro.new("{noformat}\n*a*\n{noformat}\n", '*a*')
|
10
|
-
assert_equal(%Q{<pre>\n*a*\n</pre>\n},
|
10
|
+
assert_equal(%Q{<pre class="noformat">\n*a*\n</pre>\n},
|
11
11
|
noformat.render_html({}))
|
12
12
|
end
|
13
13
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestQ < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_q_1
|
8
|
+
q = Facwparser::Element::Q.new('??hoge??', 'hoge')
|
9
|
+
assert_equal(%Q{<q>hoge</q>},
|
10
|
+
q.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestStrike < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_strike_1
|
8
|
+
strike = Facwparser::Element::Strike.new('-hoge-', 'hoge')
|
9
|
+
assert_equal(%Q{<span style="text-decoration: line-through;">hoge</span>},
|
10
|
+
strike.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestStrong < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_strong_1
|
8
|
+
strong = Facwparser::Element::Strong.new('*hoge*', 'hoge')
|
9
|
+
assert_equal(%Q{<strong>hoge</strong>},
|
10
|
+
strong.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestSub < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_sub_1
|
8
|
+
sub = Facwparser::Element::Sub.new('^hoge^', 'hoge')
|
9
|
+
assert_equal(%Q{<sub>hoge</sub>},
|
10
|
+
sub.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestSup < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_sup_1
|
8
|
+
sup = Facwparser::Element::Sup.new('^hoge^', 'hoge')
|
9
|
+
assert_equal(%Q{<sup>hoge</sup>},
|
10
|
+
sup.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -7,9 +7,9 @@ class TestTable < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
def test_table_1
|
9
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|')
|
10
|
+
tr = Facwparser::Element::TableHeaders.new("||hoge||kuke||\n", '||hoge||kuke||')
|
11
|
+
td1 = Facwparser::Element::TableData.new("|1|2|\n", '|1|2|')
|
12
|
+
td2 = Facwparser::Element::TableData.new("|3|4|\n", '|3|4|')
|
13
13
|
table.push tr
|
14
14
|
table.push td1
|
15
15
|
table.push td2
|
@@ -6,13 +6,13 @@ require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
|
6
6
|
class TestTableData < Test::Unit::TestCase
|
7
7
|
|
8
8
|
def test_table_data_1
|
9
|
-
td = Facwparser::Element::TableData.new('|hoge|kuke|')
|
9
|
+
td = Facwparser::Element::TableData.new("|hoge|kuke|\n", '|hoge|kuke|')
|
10
10
|
assert_equal(%Q{<tr><td>hoge</td><td>kuke</td></tr>},
|
11
11
|
td.render_html({}))
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_table_data_2
|
15
|
-
td = Facwparser::Element::TableData.new('|hoge|[hoge|http://www.unixuser.org]|')
|
15
|
+
td = Facwparser::Element::TableData.new("|hoge|[hoge|http://www.unixuser.org]|\n", '|hoge|[hoge|http://www.unixuser.org]|')
|
16
16
|
assert_equal(%Q{<tr><td>hoge</td><td><a href="http://www.unixuser.org">hoge</a></td></tr>},
|
17
17
|
td.render_html({}))
|
18
18
|
end
|
@@ -6,13 +6,13 @@ require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
|
6
6
|
class TestTableHeaders < Test::Unit::TestCase
|
7
7
|
|
8
8
|
def test_table_headers_1
|
9
|
-
tr = Facwparser::Element::TableHeaders.new('||hoge||kuke||')
|
9
|
+
tr = Facwparser::Element::TableHeaders.new("||hoge||kuke|| \n", '||hoge||kuke||')
|
10
10
|
assert_equal(%Q{<tr><th>hoge</th><th>kuke</th></tr>},
|
11
11
|
tr.render_html({}))
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_table_headers_2
|
15
|
-
tr = Facwparser::Element::TableHeaders.new('||hoge||[hoge|http://www.unixuser.org]||')
|
15
|
+
tr = Facwparser::Element::TableHeaders.new("||hoge||[hoge|http://www.unixuser.org]||\n", '||hoge||[hoge|http://www.unixuser.org]||')
|
16
16
|
assert_equal(%Q{<tr><th>hoge</th><th><a href="http://www.unixuser.org">hoge</a></th></tr>},
|
17
17
|
tr.render_html({}))
|
18
18
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestText < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_text_1
|
8
|
+
text = Facwparser::Element::Text.new('hoge>', 'hoge>')
|
9
|
+
assert_equal(%Q{hoge>},
|
10
|
+
text.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/facwparser/element'
|
4
|
+
|
5
|
+
class TestUnder < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_Under_1
|
8
|
+
under = Facwparser::Element::Under.new('+hoge+', 'hoge')
|
9
|
+
assert_equal(%Q{<u>hoge</u>},
|
10
|
+
under.render_html({}))
|
11
|
+
end
|
12
|
+
end
|
@@ -98,8 +98,8 @@ EOS
|
|
98
98
|
assert_equal(
|
99
99
|
[
|
100
100
|
Facwparser::Element::P.new("1\n"),
|
101
|
-
Facwparser::Element::TableHeaders.new("||2||3||\n"),
|
102
|
-
Facwparser::Element::TableData.new("|4|5|\n"),
|
101
|
+
Facwparser::Element::TableHeaders.new("||2||3||\n", '||2||3||'),
|
102
|
+
Facwparser::Element::TableData.new("|4|5|\n", '|4|5|'),
|
103
103
|
Facwparser::Element::P.new("6\n"),
|
104
104
|
],
|
105
105
|
Facwparser::Parser.parse1(source, {}))
|
@@ -87,7 +87,7 @@ class TestParseValue < Test::Unit::TestCase
|
|
87
87
|
def test_parse_value_br
|
88
88
|
assert_equal([
|
89
89
|
Facwparser::Element::Text.new('1', '1'),
|
90
|
-
Facwparser::Element::Br.new(
|
90
|
+
Facwparser::Element::Br.new('\\\\'),
|
91
91
|
Facwparser::Element::Text.new('2', '2')
|
92
92
|
], Facwparser::Parser.parse_value("1\\\\2", {}))
|
93
93
|
end
|
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.4
|
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-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Fuxxing Atlassian Confluence Wiki Parser
|
15
15
|
email:
|
@@ -32,18 +32,30 @@ files:
|
|
32
32
|
- sample/confluence2html.rb
|
33
33
|
- tests/all_tests.rb
|
34
34
|
- tests/units/element/test_a.rb
|
35
|
+
- tests/units/element/test_br.rb
|
35
36
|
- tests/units/element/test_code.rb
|
37
|
+
- tests/units/element/test_color_end.rb
|
38
|
+
- tests/units/element/test_color_start.rb
|
39
|
+
- tests/units/element/test_emphasis.rb
|
36
40
|
- tests/units/element/test_heading.rb
|
37
41
|
- tests/units/element/test_horizontal_rule.rb
|
38
42
|
- tests/units/element/test_list.rb
|
39
43
|
- tests/units/element/test_list_item.rb
|
44
|
+
- tests/units/element/test_monospace.rb
|
40
45
|
- tests/units/element/test_noformat.rb
|
41
46
|
- tests/units/element/test_p.rb
|
47
|
+
- tests/units/element/test_q.rb
|
42
48
|
- tests/units/element/test_quote.rb
|
49
|
+
- tests/units/element/test_strike.rb
|
50
|
+
- tests/units/element/test_strong.rb
|
51
|
+
- tests/units/element/test_sub.rb
|
52
|
+
- tests/units/element/test_sup.rb
|
43
53
|
- tests/units/element/test_table.rb
|
44
54
|
- tests/units/element/test_table_data.rb
|
45
55
|
- tests/units/element/test_table_headers.rb
|
56
|
+
- tests/units/element/test_text.rb
|
46
57
|
- tests/units/element/test_toc.rb
|
58
|
+
- tests/units/element/test_under.rb
|
47
59
|
- tests/units/parser/test_add_list_elements.rb
|
48
60
|
- tests/units/parser/test_parse1.rb
|
49
61
|
- tests/units/parser/test_parse_value.rb
|