dtext_rb 1.0.2 → 1.0.3

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/dtext_ruby.rb CHANGED
@@ -282,7 +282,7 @@ class DTextRuby
282
282
  when /\[expand(?:\=([^\]]*))?\](?!\])/
283
283
  stack << "expandable"
284
284
  expand_html = '<div class="expandable"><div class="expandable-header">'
285
- expand_html << "<span>#{h($1)}</span>" if $1.present?
285
+ expand_html << "<span>#{h($1)}</span>" if $1
286
286
  expand_html << '<input type="button" value="Show" class="expandable-button"/></div>'
287
287
  expand_html << '<div class="expandable-content">'
288
288
  expand_html
data/test/dtext_test.rb CHANGED
@@ -81,6 +81,11 @@ class DTextTest < Minitest::Test
81
81
  assert_parse('<blockquote><p>test</p></blockquote>', "[quote]\ntest\n[/quote]")
82
82
  end
83
83
 
84
+ def test_quote_blocks_with_list
85
+ assert_parse("<blockquote><ul><li>hello</li><li>there<br></li></ul></blockquote><p>abc</p>", "[quote]\n* hello\n* there\n[/quote]\nabc")
86
+ assert_parse("<blockquote><ul><li>hello</li><li>there</li></ul></blockquote><p>abc</p>", "[quote]\n* hello\n* there\n\n[/quote]\nabc")
87
+ end
88
+
84
89
  def test_quote_blocks_nested
85
90
  assert_parse("<blockquote><p>a</p><blockquote><p>b</p></blockquote><p>c</p></blockquote>", "[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]")
86
91
  end
@@ -127,7 +132,7 @@ class DTextTest < Minitest::Test
127
132
  end
128
133
 
129
134
  def test_old_style_links_with_special_entities
130
- assert_parse('<p>"1" <a href="http://three.com">2 &amp; 3</a></p>', '"1" "2 & 3":http://three.com')
135
+ assert_parse('<p>&quot;1&quot; <a href="http://three.com">2 &amp; 3</a></p>', '"1" "2 & 3":http://three.com')
131
136
  end
132
137
 
133
138
  def test_new_style_links
@@ -183,10 +188,11 @@ class DTextTest < Minitest::Test
183
188
 
184
189
  def test_complex_links_1
185
190
  assert_parse("<p><a href=\"/wiki_pages/show_or_new?title=1\">2 3</a> | <a href=\"/wiki_pages/show_or_new?title=4\">5 6</a></p>", "[[1|2 3]] | [[4|5 6]]")
191
+ assert_parse("", "[[chaos_(dff)|Chaos]]")
186
192
  end
187
193
 
188
194
  def test_complex_links_2
189
- assert_parse("<p>Tags <strong>(<a href=\"/wiki_pages/show_or_new?title=howto:tag\">Tagging Guidelines</a> | <a href=\"/wiki_pages/show_or_new?title=howto:tag_checklist\">Tag Checklist</a> | <a href=\"/wiki_pages/show_or_new?title=tag_groups\">Tag Groups</a>)</strong></p>", "Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]")
195
+ assert_parse("<p>Tags <strong>(<a href=\"/wiki_pages/show_or_new?title=howto%3Atag\">Tagging Guidelines</a> | <a href=\"/wiki_pages/show_or_new?title=howto%3Atag_checklist\">Tag Checklist</a> | <a href=\"/wiki_pages/show_or_new?title=tag_groups\">Tag Groups</a>)</strong></p>", "Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]")
190
196
  end
191
197
 
192
198
  def test_table
@@ -205,6 +211,22 @@ class DTextTest < Minitest::Test
205
211
  assert_parse('<p><a rel="nofollow" href="/users?name=mack">@mack</a>&lt;</p>', "@mack<")
206
212
  end
207
213
 
214
+ def test_expand
215
+ assert_parse("<div class=\"expandable\"><div class=\"expandable-header\"><input type=\"button\" value=\"Show\" class=\"expandable-button\"/></div><div class=\"expandable-content\"><p>hello world</p></div></div>", "[expand]hello world[/expand]")
216
+ end
217
+
218
+ def test_aliased_expand
219
+ assert_parse("<div class=\"expandable\"><div class=\"expandable-header\"><span>hello</span><input type=\"button\" value=\"Show\" class=\"expandable-button\"/></div><div class=\"expandable-content\"><p>blah blah</p></div></div>", "[expand=hello]blah blah[/expand]")
220
+ end
221
+
222
+ def test_expand_with_nested_code
223
+ assert_parse("<div class=\"expandable\"><div class=\"expandable-header\"><input type=\"button\" value=\"Show\" class=\"expandable-button\"/></div><div class=\"expandable-content\"><pre>hello\n</pre></div></div>", "[expand]\n[code]\nhello\n[/code]\n[/expand]")
224
+ end
225
+
226
+ def test_expand_with_nested_list
227
+ assert_parse("<div class=\"expandable\"><div class=\"expandable-header\"><input type=\"button\" value=\"Show\" class=\"expandable-button\"/></div><div class=\"expandable-content\"><ul><li>a</li><li>b<br></li></ul></div></div><p>c</p>", "[expand]\n* a\n* b\n[/expand]\nc")
228
+ end
229
+
208
230
  def test_inline_mode
209
231
  assert_equal("hello", DTextRagel.parse_inline("hello").strip)
210
232
  end
@@ -212,4 +234,8 @@ class DTextTest < Minitest::Test
212
234
  def test_strip
213
235
  assert_equal("hellozworld", DTextRagel.parse_strip("h[b]e[/b]llo[quote]z[/quote]wo[expand]rld[/expand]"))
214
236
  end
237
+
238
+ def test_old_asterisks
239
+ assert_parse("<p>hello *world* neutral</p>", "hello *world* neutral")
240
+ end
215
241
  end
@@ -0,0 +1,13 @@
1
+ Dir["/dev_exclusions/dtext_bench/forum_posts/*.txt"].slice(80, 10).each do |file|
2
+ input = File.read(file)
3
+ o1 = DTextRagel.parse(input).gsub(/\s+<\/p>/, "</p>")
4
+ o2 = DTextRuby.parse(input).gsub(/\r/, "").gsub(/\s+<\/p>/, "</p>").gsub(/%3A/, ":")
5
+ if o1.size != o2.size
6
+ puts input
7
+ puts "---"
8
+ puts o1
9
+ puts "~~~"
10
+ puts o2
11
+ puts "==="
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ Dir["/dev_exclusions/dtext_bench/wiki_pages/*.txt"].sort.slice(20, 10).each do |file|
2
+ input = File.read(file)
3
+ o1 = DTextRagel.parse(input.dup).gsub(/\s+<\/p>/, "</p>")
4
+ o2 = DTextRuby.parse(input.dup).gsub(/\r/, "").gsub(/\s+<\/p>/, "</p>")
5
+ if o1.size != o2.size
6
+ puts input
7
+ puts "---"
8
+ puts o1
9
+ puts "~~~"
10
+ puts o2
11
+ puts "==="
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtext_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - r888888888
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-17 00:00:00.000000000 Z
11
+ date: 2016-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -73,6 +73,8 @@ files:
73
73
  - lib/dtext_ruby.rb
74
74
  - test/dtext_test.rb
75
75
  - test/ragel_output.txt
76
+ - test/test_forum_posts.rb
77
+ - test/test_wiki_pages.rb
76
78
  - test/wiki.txt
77
79
  homepage: http://github.com/r888888888/dtext_rb
78
80
  licenses: