tartan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +130 -0
  3. data/TODO +17 -0
  4. data/lib/core_ext/array.rb +12 -0
  5. data/lib/core_ext/file.rb +15 -0
  6. data/lib/core_ext/hash.rb +16 -0
  7. data/lib/core_ext/match_data.rb +62 -0
  8. data/lib/core_ext/module.rb +17 -0
  9. data/lib/core_ext/regexp.rb +33 -0
  10. data/lib/markdown.yml +499 -0
  11. data/lib/symbolize.rb +78 -0
  12. data/lib/table.yml +63 -0
  13. data/lib/tartan.rb +359 -0
  14. data/lib/tartan_markdown.rb +8 -0
  15. data/lib/tartan_markdown_def.rb +7 -0
  16. data/lib/tartan_table_def.rb +7 -0
  17. data/lib/tartan_test_base_def.rb +5 -0
  18. data/lib/tartan_wikilink_def.rb +14 -0
  19. data/lib/test_base.yml +18 -0
  20. data/lib/wiki-test.rb +94 -0
  21. data/lib/wiki_rule.rb +240 -0
  22. data/lib/wikilink.yml +18 -0
  23. data/test/MarkdownTest_1.0/Amps and angle encoding.html +17 -0
  24. data/test/MarkdownTest_1.0/Amps and angle encoding.text +21 -0
  25. data/test/MarkdownTest_1.0/Auto links.html +18 -0
  26. data/test/MarkdownTest_1.0/Auto links.text +13 -0
  27. data/test/MarkdownTest_1.0/Backslash codeescapes.html +68 -0
  28. data/test/MarkdownTest_1.0/Backslash codeescapes.text +68 -0
  29. data/test/MarkdownTest_1.0/Backslash simpleescapes.html +33 -0
  30. data/test/MarkdownTest_1.0/Backslash simpleescapes.text +33 -0
  31. data/test/MarkdownTest_1.0/Blockquotes with code blocks.html +15 -0
  32. data/test/MarkdownTest_1.0/Blockquotes with code blocks.text +11 -0
  33. data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.html +8 -0
  34. data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.text +8 -0
  35. data/test/MarkdownTest_1.0/Horizontal rules.html +71 -0
  36. data/test/MarkdownTest_1.0/Horizontal rules.text +67 -0
  37. data/test/MarkdownTest_1.0/Inline HTML (Advanced).html +14 -0
  38. data/test/MarkdownTest_1.0/Inline HTML (Advanced).text +14 -0
  39. data/test/MarkdownTest_1.0/Inline HTML (Simple).html +72 -0
  40. data/test/MarkdownTest_1.0/Inline HTML (Simple).text +69 -0
  41. data/test/MarkdownTest_1.0/Inline HTML comments.html +13 -0
  42. data/test/MarkdownTest_1.0/Inline HTML comments.text +13 -0
  43. data/test/MarkdownTest_1.0/Links, inline style.html +9 -0
  44. data/test/MarkdownTest_1.0/Links, inline style.text +9 -0
  45. data/test/MarkdownTest_1.0/Links, reference style.html +18 -0
  46. data/test/MarkdownTest_1.0/Links, reference style.text +31 -0
  47. data/test/MarkdownTest_1.0/Literal quotes in titles.html +3 -0
  48. data/test/MarkdownTest_1.0/Literal quotes in titles.text +7 -0
  49. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.html +314 -0
  50. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.text +306 -0
  51. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.html +942 -0
  52. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.text +888 -0
  53. data/test/MarkdownTest_1.0/Nested blockquotes.html +9 -0
  54. data/test/MarkdownTest_1.0/Nested blockquotes.text +5 -0
  55. data/test/MarkdownTest_1.0/Ordered and unordered lists.html +137 -0
  56. data/test/MarkdownTest_1.0/Ordered and unordered lists.text +122 -0
  57. data/test/MarkdownTest_1.0/Strong and em together.html +7 -0
  58. data/test/MarkdownTest_1.0/Strong and em together.text +7 -0
  59. data/test/MarkdownTest_1.0/Tabs.html +25 -0
  60. data/test/MarkdownTest_1.0/Tabs.text +21 -0
  61. data/test/MarkdownTest_1.0/Tidyness.html +8 -0
  62. data/test/MarkdownTest_1.0/Tidyness.text +5 -0
  63. data/test/MarkdownTest_1.0/run-markdown.rb +56 -0
  64. data/test/MarkdownTest_1.0/test-fireball-markdown.rb +177 -0
  65. data/test/MarkdownTest_1.0/testdiff.rb +42 -0
  66. data/test/harder/test-markdown-harder.rb +11 -0
  67. data/test/harder/test-markdown-harder.yml +111 -0
  68. data/test/redcloth/redcloth-markdown-tests.rb +29 -0
  69. data/test/redcloth/redcloth-markdown-tests.yml +218 -0
  70. data/test/test-combo.rb +23 -0
  71. data/test/test-hash.rb +31 -0
  72. data/test/test-markdown.rb +11 -0
  73. data/test/test-markdown.yml +1144 -0
  74. data/test/test-match-data.rb +54 -0
  75. data/test/test-readme-example.rb +48 -0
  76. data/test/test-tables.rb +16 -0
  77. data/test/test-tables.yml +82 -0
  78. data/test/test-tartan-markdown.rb +11 -0
  79. data/test/test-tartan.rb +306 -0
  80. data/test/test-wikilink.rb +18 -0
  81. data/test/test-wikilink.yml +22 -0
  82. data/test/wikilink-test-helper.rb +14 -0
  83. metadata +139 -0
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tempfile'
4
+ require './run-markdown'
5
+
6
+ def translate_file(fileIn, initialText)
7
+
8
+ if fileIn.class == String
9
+ file = open(fileIn)
10
+ else
11
+ file = fileIn
12
+ end
13
+
14
+ tmpFile = Tempfile.new('wikiparser')
15
+
16
+ tmpFile.puts(initialText)
17
+
18
+ file.each {|line|
19
+ line.gsub!(/ /, '.')
20
+ line.gsub!(/\t/, '\t')
21
+
22
+ tmpFile.write line
23
+ }
24
+
25
+ tmpFile.flush
26
+ tmpFile
27
+ end
28
+
29
+ termWidth = `stty -a`.gsub(/[^0-9;]/, '').sub(/^(?:.*?;){2}([0-9]+).*$/m, '\1')
30
+
31
+ base = ARGV[0]
32
+
33
+ outFile = WikiparserRunner.run(base)
34
+
35
+ htmlTmp = translate_file(base + ".html", "Refernce HTML\n\n")
36
+ outTmp = translate_file(outFile, "Generated HTML\n\n")
37
+
38
+ pager = ENV['PAGER']? ENV['PAGER'] : "less"
39
+
40
+ system("sdiff -w #{termWidth} #{htmlTmp.path} #{outTmp.path} | #{pager}")
41
+
42
+
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ #$Id: test-markdown.rb 75 2006-02-07 00:09:26Z larry $
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+
6
+ require 'tartan_markdown'
7
+ require 'wiki-test'
8
+
9
+ cases = WikiTestCases.new(TartanMarkdown, "test-markdown-harder.yml")
10
+
11
+
@@ -0,0 +1,111 @@
1
+ #$Id: test-markdown-harder.yml 161 2006-05-20 11:19:30Z larry $
2
+ ---
3
+ # Fails
4
+ title: MixedListsSpaced
5
+ in: |-
6
+ 1. First
7
+
8
+ 2. Second:
9
+
10
+ * Fee
11
+ * Fie
12
+ * Foe
13
+
14
+ 3. Third
15
+ html: |-
16
+ <ol>
17
+ <li><p>First</p></li>
18
+ <li><p>Second:</p><ul>
19
+
20
+ <li>Fee</li>
21
+ <li>Fie</li>
22
+ <li>Foe</li>
23
+ </ul></li>
24
+ <li><p>Third</p></li>
25
+ </ol>
26
+ ---
27
+ # Fails
28
+ title: LinkWithAmpInURL
29
+ in: |-
30
+ A [link] [1] with an ampersand in the URL.
31
+
32
+ [1]: http://example.com/?foo=1&bar=2
33
+ [2]: http://att.com/ "AT&T"
34
+ html: |-
35
+ <p>A <a href="http://example.com/?foo=1&amp;bar=2">link</a> with an ampersand in the URL.</p>
36
+ ---
37
+ # Fails
38
+ title: AmpInLinkText
39
+ in: |-
40
+ A link with an amersand in the link text: [AT&T] [2].
41
+
42
+ [1]: http://example.com/?foo=1&bar=2
43
+ [2]: http://att.com/ "AT&T"
44
+ html: |-
45
+ <p>A link with an amersand in the link text: <a href="http://att.com/" title="AT&amp;T">AT&amp;T</a>.</p>
46
+ ---
47
+ # Fails
48
+ title: AmpInInlineLink
49
+ in: "An inline [link](</script?foo=1&bar=2>)."
50
+ html: |-
51
+ <p>An inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
52
+ ---
53
+ # Fails
54
+ title: Tidyness
55
+ in: |-
56
+ > A list within a blockquote:
57
+ >
58
+ > * asterisk 1
59
+ > * asterisk 2
60
+ > * asterisk 3
61
+ html: |-
62
+ <blockquote>
63
+ <p>A list within a blockquote:</p>
64
+ <ul>
65
+ <li>asterisk 1</li>
66
+ <li>asterisk 2</li>
67
+ <li>asterisk 3</li>
68
+ </ul>
69
+ </blockquote>
70
+ ---
71
+ # Fails
72
+ title: Links
73
+ in: |-
74
+ Here's a [link] [1] with an ampersand in the URL.
75
+
76
+ Here's a link with an amersand in the link text: [AT&T] [2].
77
+
78
+ [1]: http://example.com/?foo=1&bar=2
79
+ [2]: http://att.com/ "AT&T"
80
+ html: |-
81
+ <p>Here's a <a href="http://example.com/?foo=1&amp;bar=2">link</a> with an amper
82
+ sand in the URL.</p>
83
+
84
+ <p>Here's a link with an amersand in the link text: <a href="http://att.com/" ti
85
+ tle="AT&amp;T">AT&amp;T</a>.</p>
86
+ ---
87
+ # Fails
88
+ title: InlineLinks
89
+ in: |-
90
+ Here's an inline [link](/script?foo=1&bar=2).
91
+
92
+ Here's an inline [link](</script?foo=1&bar=2>).
93
+ html: |-
94
+ <p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
95
+
96
+ <p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
97
+ ---
98
+ # Fails
99
+ title: BackslashQuotingInCodeBlock
100
+ in: |-
101
+ These should not, because they occur within a code block:
102
+
103
+ Backslash: \\
104
+
105
+ Backtick: \`
106
+ html: |-
107
+ <p>These should not, because they occur within a code block:</p>
108
+ <pre><code>
109
+ Backslash: \\
110
+
111
+ Backtick: \`
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ #$Id: redcloth-markdown-tests.rb 148 2006-07-22 14:04:20Z larry $
3
+
4
+ # Adapted from the Redcloth tests
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__), "../..", "lib")
7
+
8
+ require 'yaml'
9
+ require 'markdown'
10
+ require 'tartan'
11
+
12
+ Dir["./redcloth*.yml"].each do |testfile|
13
+ YAML::load_documents( File.open( testfile ) ) do |doc|
14
+ if doc['in'] and doc['out']
15
+ wp = Wikiparser.new( doc['in'] )
16
+ html = wp.to_html
17
+ puts "---"
18
+
19
+ html.gsub!( /\n+/, "\n" )
20
+ doc['out'].gsub!( /\n+/, "\n" )
21
+ if html == doc['out']
22
+ puts "success: true"
23
+ else
24
+ puts "expected: "; p doc['out']
25
+ puts "out: "; p html
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,218 @@
1
+ in: |
2
+ This is a regular paragraph.
3
+
4
+ <table>
5
+ <tr>
6
+ <td>Foo</td>
7
+ </tr>
8
+ </table>
9
+
10
+ This is another regular paragraph.
11
+ html: |-
12
+ <p>This is a regular paragraph.</p>
13
+
14
+
15
+ <table>
16
+ <tr>
17
+ <td>Foo</td>
18
+ </tr>
19
+ </table>
20
+ <p>This is another regular paragraph.</p>
21
+ ---
22
+ in: '"Larry Bird":http://images.google.com/images?num=30&q=larry+bird'
23
+ html: '<p>"Larry Bird":http://images.google.com/images?num=30&#38;q=larry+bird</p>'
24
+ ---
25
+ in: '&copy;'
26
+ html: <p>&copy;</p>
27
+ ---
28
+ in: AT&T
29
+ html: <p>AT&#38;T</p>
30
+
31
+ # We don't do this.
32
+ # ---
33
+ # in: 4 < 5
34
+ # out: 4 &lt; 5
35
+ ---
36
+ in: |
37
+ This is an H1
38
+ =============
39
+
40
+ This is an H2
41
+ -------------
42
+ html: |-
43
+ <h1>This is an H1</h1>
44
+
45
+ <h2>This is an H2</h2>
46
+ ---
47
+ in: |
48
+ # This is an H1
49
+
50
+ ## This is an H2
51
+
52
+ ###### This is an H6
53
+ html: |-
54
+ <h1>This is an H1</h1>
55
+
56
+ <h2>This is an H2</h2>
57
+
58
+ <h6>This is an H6</h6>
59
+ ---
60
+ in: |
61
+ > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
62
+ > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
63
+ > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
64
+ >
65
+ > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
66
+ > id sem consectetuer libero luctus adipiscing.
67
+ html: |-
68
+ <blockquote>
69
+ <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
70
+ consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
71
+ Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
72
+
73
+ <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
74
+ id sem consectetuer libero luctus adipiscing.</p>
75
+
76
+ </blockquote>
77
+ ---
78
+ in: |
79
+ > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
80
+ consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
81
+ Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
82
+ >
83
+ > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
84
+ id sem consectetuer libero luctus adipiscing.
85
+ html: |-
86
+ <blockquote>
87
+ <p>This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
88
+ consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
89
+ Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.</p>
90
+
91
+ <p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
92
+ id sem consectetuer libero luctus adipiscing.</p>
93
+
94
+ </blockquote>
95
+ ---
96
+ in: |
97
+ > This is the first level of quoting.
98
+ >
99
+ > > This is nested blockquote.
100
+ >
101
+ > Back to the first level.
102
+ html: |-
103
+ <blockquote>
104
+ <p>This is the first level of quoting.</p>
105
+ <blockquote>
106
+ <p>This is nested blockquote.</p>
107
+
108
+ </blockquote>
109
+
110
+
111
+
112
+ <p>Back to the first level.</p>
113
+
114
+ </blockquote>
115
+ ---
116
+ in: |
117
+ > ## This is a header.
118
+ >
119
+ > 1. This is the first list item.
120
+ > 2. This is the second list item.
121
+ >
122
+ > Here's some example code:
123
+ >
124
+ > return shell_exec("echo $input | $markdown_script");
125
+ html: |-
126
+ <blockquote>
127
+ <h2>This is a header.</h2>
128
+
129
+
130
+
131
+ <p>1. This is the first list item.
132
+ 2. This is the second list item.</p>
133
+
134
+ <p>Here's some example code:</p>
135
+ <pre><code>return shell_exec("echo $input | $markdown_script");</code></pre>
136
+
137
+ </blockquote>
138
+ ---
139
+ in: |
140
+ * * *
141
+
142
+ ***
143
+
144
+ *****
145
+
146
+ - - -
147
+
148
+ ---------------------------------------
149
+
150
+ _ _ _
151
+ html: |-
152
+ <hr />
153
+
154
+ <hr />
155
+
156
+ <hr />
157
+
158
+ <hr />
159
+
160
+ <hr />
161
+
162
+ <hr />
163
+ ---
164
+ in: |
165
+ This is [an example](http://example.com/ "Title") inline link.
166
+
167
+ [This link](http://example.net/) has no title attribute.
168
+ html: |-
169
+ <p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
170
+
171
+ <p><a href="http://example.net/">This link</a> has no title attribute.</p>
172
+ ---
173
+ in: See my [About](/about/) page for details.
174
+ html: <p>See my <a href="/about/">About</a> page for details.</p>
175
+ ---
176
+ in: |
177
+ This is [an example][id] reference-style link.
178
+
179
+ This is [an example] [id] reference-style link.
180
+
181
+ [id]: http://example.com/ "Optional Title Here"
182
+ html: |-
183
+ <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
184
+
185
+ <p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.</p>
186
+ ---
187
+ in: |
188
+ [Google][]
189
+ [Google]: http://google.com/
190
+ html: <p><a href="http://google.com/">Google</a></p>
191
+ ---
192
+ in: |
193
+ Visit [Daring Fireball][] for more information.
194
+ [Daring Fireball]: http://daringfireball.net/
195
+ html: <p>Visit <a href="http://daringfireball.net/">Daring Fireball</a> for more information.</p>
196
+ ---
197
+ in: |
198
+ I get 10 times more traffic from [Google] [1] than from
199
+ [Yahoo] [2] or [MSN] [3].
200
+
201
+ [1]: http://google.com/ "Google"
202
+ [2]: http://search.yahoo.com/ "Yahoo Search"
203
+ [3]: http://search.msn.com/ "MSN Search"
204
+
205
+ html: |-
206
+ <p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from
207
+ <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
208
+ ---
209
+ in: |
210
+ I get 10 times more traffic from [Google][] than from
211
+ [Yahoo][] or [MSN][].
212
+
213
+ [google]: http://google.com/ "Google"
214
+ [yahoo]: http://search.yahoo.com/ "Yahoo Search"
215
+ [msn]: http://search.msn.com/ "MSN Search"
216
+ html: |-
217
+ <p>I get 10 times more traffic from <a href="http://google.com/" title="Google">Google</a> than from
218
+ <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ #$Id: test-combo.rb 159 2006-07-24 08:13:02Z larry $
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+
6
+ require 'tartan_markdown'
7
+ require 'tartan_wikilink_def'
8
+ require 'tartan_table_def'
9
+ require 'wikilink-test-helper'
10
+ require 'wiki-test'
11
+
12
+ class TartanTestAll < Tartan
13
+ include TartanMarkdownDef
14
+ include TartanWikilinkDef
15
+ include TartanTableDef
16
+ include WikilinkTestHelper
17
+ end
18
+
19
+ cases = WikiTestCases.new(TartanTestAll,
20
+ [ "test-wikilink.yml",
21
+ "test-markdown.yml",
22
+ "test-tables.yml"])
23
+
data/test/test-hash.rb ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ # $Id: test-hash.rb 159 2006-07-24 08:13:02Z larry $
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
+
6
+ require 'test/unit'
7
+ require 'core_ext/hash'
8
+
9
+ class TestHash < Test::Unit::TestCase
10
+ def test_simple_merge
11
+ h1 = {:x => 'a', :y => 'b'}
12
+ h2 = {:x => 'p', :z => 'd'}
13
+
14
+ hm1 = h1.merge(h2)
15
+ hm2 = h1.deep_merge(h2)
16
+
17
+ assert_equal hm1, hm2
18
+ end
19
+
20
+ def test_two_level
21
+ h1 = {:x => {:a => 1, :b => 2}, :y => 3, :z => 4}
22
+ h2 = {:x => {:a => 10, :c => 20}, :y =>30, :p => 40 }
23
+
24
+ hm = h1.deep_merge(h2)
25
+ assert_equal( {:x => {:a => 10, :b => 2, :c => 20},
26
+ :y => 30, :z => 4, :p => 40 },
27
+ hm )
28
+
29
+ assert_not_equal(hm, h1.merge(h2))
30
+ end
31
+ end