tartan 0.1.1 → 0.2.0

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.
Files changed (88) hide show
  1. data/History.txt +11 -0
  2. data/Manifest.txt +42 -0
  3. data/{README → README.txt} +12 -8
  4. data/Rakefile +78 -0
  5. data/lib/core_ext/array.rb +9 -10
  6. data/lib/core_ext/module.rb +2 -0
  7. data/lib/{symbolize.rb → core_ext/symbolize.rb} +0 -0
  8. data/lib/core_ext.rb +7 -0
  9. data/lib/{markdown.yml → tartan/markdown/markdown.yml} +67 -25
  10. data/lib/tartan/markdown/rules.rb +11 -0
  11. data/lib/tartan/markdown.rb +14 -0
  12. data/lib/tartan/table/rules.rb +11 -0
  13. data/lib/{table.yml → tartan/table/table.yml} +1 -1
  14. data/lib/tartan/test/base_rules.rb +9 -0
  15. data/lib/{test_base.yml → tartan/test/test_base.yml} +0 -0
  16. data/lib/{wiki-test.rb → tartan/test/wiki-test.rb} +15 -12
  17. data/lib/tartan/wiki_rule.rb +242 -0
  18. data/lib/tartan/wikilink/rules.rb +18 -0
  19. data/lib/{wikilink.yml → tartan/wikilink/wikilink.yml} +4 -2
  20. data/lib/tartan.rb +259 -270
  21. data/test/test-combo.rb +21 -14
  22. data/test/test-combo.yml +17 -0
  23. data/test/test-markdown-and-wikilink.rb +22 -0
  24. data/test/test-markdown-and-wikilink.yml +6 -0
  25. data/test/test-markdown.rb +4 -5
  26. data/test/test-markdown.yml +194 -1
  27. data/test/test-readme-example.rb +6 -5
  28. data/test/test-tables.rb +11 -7
  29. data/test/test-tartan.rb +8 -7
  30. data/test/test-wikilink.rb +13 -9
  31. data/test/test-wikilink.yml +3 -0
  32. metadata +47 -86
  33. data/lib/tartan_markdown.rb +0 -8
  34. data/lib/tartan_markdown_def.rb +0 -7
  35. data/lib/tartan_table_def.rb +0 -7
  36. data/lib/tartan_test_base_def.rb +0 -5
  37. data/lib/tartan_wikilink_def.rb +0 -14
  38. data/lib/wiki_rule.rb +0 -240
  39. data/test/MarkdownTest_1.0/Amps and angle encoding.html +0 -17
  40. data/test/MarkdownTest_1.0/Amps and angle encoding.text +0 -21
  41. data/test/MarkdownTest_1.0/Auto links.html +0 -18
  42. data/test/MarkdownTest_1.0/Auto links.text +0 -13
  43. data/test/MarkdownTest_1.0/Backslash codeescapes.html +0 -68
  44. data/test/MarkdownTest_1.0/Backslash codeescapes.text +0 -68
  45. data/test/MarkdownTest_1.0/Backslash simpleescapes.html +0 -33
  46. data/test/MarkdownTest_1.0/Backslash simpleescapes.text +0 -33
  47. data/test/MarkdownTest_1.0/Blockquotes with code blocks.html +0 -15
  48. data/test/MarkdownTest_1.0/Blockquotes with code blocks.text +0 -11
  49. data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.html +0 -8
  50. data/test/MarkdownTest_1.0/Hard-wrapped paragraphs with list-like lines.text +0 -8
  51. data/test/MarkdownTest_1.0/Horizontal rules.html +0 -71
  52. data/test/MarkdownTest_1.0/Horizontal rules.text +0 -67
  53. data/test/MarkdownTest_1.0/Inline HTML (Advanced).html +0 -14
  54. data/test/MarkdownTest_1.0/Inline HTML (Advanced).text +0 -14
  55. data/test/MarkdownTest_1.0/Inline HTML (Simple).html +0 -72
  56. data/test/MarkdownTest_1.0/Inline HTML (Simple).text +0 -69
  57. data/test/MarkdownTest_1.0/Inline HTML comments.html +0 -13
  58. data/test/MarkdownTest_1.0/Inline HTML comments.text +0 -13
  59. data/test/MarkdownTest_1.0/Links, inline style.html +0 -9
  60. data/test/MarkdownTest_1.0/Links, inline style.text +0 -9
  61. data/test/MarkdownTest_1.0/Links, reference style.html +0 -18
  62. data/test/MarkdownTest_1.0/Links, reference style.text +0 -31
  63. data/test/MarkdownTest_1.0/Literal quotes in titles.html +0 -3
  64. data/test/MarkdownTest_1.0/Literal quotes in titles.text +0 -7
  65. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.html +0 -314
  66. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.out +0 -316
  67. data/test/MarkdownTest_1.0/Markdown Documentation - Basics.text +0 -306
  68. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.html +0 -942
  69. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.out +0 -947
  70. data/test/MarkdownTest_1.0/Markdown Documentation - Syntax.text +0 -888
  71. data/test/MarkdownTest_1.0/Nested blockquotes.html +0 -9
  72. data/test/MarkdownTest_1.0/Nested blockquotes.text +0 -5
  73. data/test/MarkdownTest_1.0/Ordered and unordered lists.html +0 -137
  74. data/test/MarkdownTest_1.0/Ordered and unordered lists.text +0 -122
  75. data/test/MarkdownTest_1.0/Strong and em together.html +0 -7
  76. data/test/MarkdownTest_1.0/Strong and em together.text +0 -7
  77. data/test/MarkdownTest_1.0/Tabs.html +0 -25
  78. data/test/MarkdownTest_1.0/Tabs.text +0 -21
  79. data/test/MarkdownTest_1.0/Tidyness.html +0 -8
  80. data/test/MarkdownTest_1.0/Tidyness.text +0 -5
  81. data/test/MarkdownTest_1.0/run-markdown.rb +0 -56
  82. data/test/MarkdownTest_1.0/test-fireball-markdown.rb +0 -177
  83. data/test/MarkdownTest_1.0/testdiff.rb +0 -42
  84. data/test/harder/test-markdown-harder.rb +0 -11
  85. data/test/harder/test-markdown-harder.yml +0 -111
  86. data/test/redcloth/redcloth-markdown-tests.rb +0 -29
  87. data/test/redcloth/redcloth-markdown-tests.yml +0 -218
  88. data/test/test-tartan-markdown.rb +0 -11
data/lib/wiki_rule.rb DELETED
@@ -1,240 +0,0 @@
1
- # $Id: wiki_rule.rb 159 2006-07-24 08:13:02Z larry $
2
- require 'core_ext/regexp'
3
-
4
- class WikiRule < Hash
5
- def initialize(matcher={})
6
- matcher.each { |(a, v)| self[a] = v }
7
- end
8
-
9
- def matcher
10
- self
11
- end
12
-
13
- # define methods to access elements of matcher hash
14
- def method_missing(method_symbol)
15
- self.class.send(:define_method, method_symbol) {self[method_symbol]}
16
- self[method_symbol]
17
- end
18
-
19
- def match
20
- self[:match] ? self[:match].to_regexp : nil
21
- end
22
-
23
- def strip_match
24
- strip = self[:strip]
25
- (strip and strip[:match]) ? strip[:match].to_regexp : nil
26
- end
27
-
28
- def unstrip_match
29
- unstrip = self[:unstrip]
30
- (unstrip and unstrip[:match]) ? unstrip[:match].to_regexp : nil
31
- end
32
-
33
- def strip_replace
34
- self[:strip][:replace]
35
- end
36
-
37
- def unstrip_replace
38
- self[:unstrip][:replace]
39
- end
40
-
41
- def placed(position)
42
- self.delete(position)
43
- end
44
-
45
- def default_rule
46
- self[:default]
47
- end
48
-
49
- def start_mark(type)
50
- return false if self[type].nil? or self[type].class == TrueClass
51
-
52
- self[type][:start_mark]
53
- end
54
-
55
- def end_mark(type)
56
- return false if self[type].nil? or self[type].class == TrueClass
57
-
58
- self[type][:end_mark]
59
- end
60
-
61
- def replace_regex(type)
62
- return false if self[type].nil? or self[type].class == TrueClass
63
-
64
- self[type][:replace]
65
- end
66
-
67
- def target_position
68
- self[:position]
69
- end
70
-
71
- def vars_to_set
72
- self[:set]
73
- end
74
-
75
- def subparse_context
76
- return nil if ! self.has_key?(:subparse)
77
-
78
- if self[:subparse].is_a?(Symbol) or self[:subparse].is_a?(String)
79
- return self[:subparse]
80
- elsif self[:subparse].has_key?(:context)
81
- return self[:subparse][:context]
82
- end
83
-
84
- return nil
85
- end
86
-
87
- def subparse_match_group
88
- if has_key?(:subparse) and
89
- self[:subparse].is_a?(Hash) and
90
- self[:subparse].has_key?(:match_group)
91
- self[:subparse][:match_group]
92
- else
93
- nil
94
- end
95
- end
96
-
97
- def position_matches?(parsed, to_be_parsed, match_result)
98
- return true if !target_position
99
-
100
- pos = parsed.length
101
-
102
- return true if target_position == pos
103
- return true if :first == target_position && 0 == pos
104
-
105
- if 0 == to_be_parsed.length && match_result.post_match.empty?
106
- return true if :last == target_position
107
- return true if :all == target_position && 0 == parsed.length
108
- else
109
- return true if :not_last == target_position
110
- end
111
-
112
- return false
113
- end
114
-
115
- def has_type?(type)
116
- if String == type.class
117
- type = type.to_sym
118
- end
119
-
120
- return self[type]
121
- end
122
-
123
- def replace(parse_type, match_result, wikiparser)
124
- return unless match_result
125
-
126
- wikiparser.substitute(replace_regex(parse_type), match_result)
127
- end
128
-
129
- def block(parse_type, text, match_result, wikiparser)
130
- return unless match_result
131
-
132
- mid = text
133
-
134
- start_strip = ""
135
- end_strip = ""
136
-
137
- if subparse_match_group
138
- subparse_index = match_result.sym2index(subparse_match_group)
139
-
140
- last_match = match_result.last_match_index
141
- start_strip = match_result.pre_sub_match(subparse_index)
142
- end_strip = match_result.post_sub_match(subparse_index)
143
- mid = match_result[subparse_index]
144
- end
145
-
146
- if strip.is_a?(Hash) and strip[:match] and strip[:replace]
147
- mid = mid.gsub(strip_match, strip_replace)
148
- end
149
-
150
- # need to evaluate the start_text before the execution of the
151
- # sub-parse in case any of the wiki helper functions depend on
152
- # ordering of the text
153
- start_text = start_mark(parse_type)?
154
- wikiparser.substitute(start_mark(parse_type),
155
- match_result):
156
- ""
157
- if subparse_context
158
- mid = wikiparser.parse_by_context(parse_type, subparse_context, mid)
159
- end
160
-
161
- mid = start_text + mid
162
-
163
- if end_mark(parse_type)
164
- mid += wikiparser.substitute(end_mark(parse_type), match_result)
165
- end
166
-
167
- if ! has_key?(parse_type)
168
- mid = start_strip + mid + end_strip
169
-
170
- if unstrip
171
- mid.gsub!(unstrip_match, unstrip_replace)
172
- end
173
- end
174
-
175
- mid
176
- end
177
-
178
- def handle_match(parse_type, parsed, to_be_parsed, match_result, wikiparser)
179
- debug_opt = wikiparser.get_var('debug')
180
- if $DEBUG || debug || true == debug_opt || debug_opt == title
181
- puts "\n%s matches [[%s<<\n%s\n>>%s]]" %
182
- [title, match_result.pre_match, match_result,
183
- match_result.post_match]
184
- end
185
-
186
- wikiparser.set_vars(vars_to_set, match_result)
187
-
188
- mid = match_result[0]
189
-
190
- if replace_regex(parse_type)
191
- mid = replace(parse_type, match_result, wikiparser)
192
- elsif true == self[parse_type] or
193
- start_mark(parse_type) or
194
- end_mark(parse_type) or
195
- subparse
196
-
197
- mid = block(parse_type, mid, match_result, wikiparser)
198
- end
199
-
200
- if shelve && mid
201
- mid = wikiparser.shelve(mid)
202
- end
203
-
204
- if "" != match_result.pre_match
205
- parsed.add_text(false, match_result.pre_match)
206
- end
207
-
208
- parsed.add_text(true, mid) if "" != mid
209
-
210
- if "" != match_result.post_match
211
- to_be_parsed.add_back_text(false, match_result.post_match)
212
- end
213
-
214
- return parsed, to_be_parsed
215
- end
216
-
217
- def parse_element(parse_type, to_be_parsed, wikiparser)
218
- parsed = ParsedTextList.new
219
-
220
- position = 0
221
- while element = to_be_parsed.shift
222
- if element.claimed? then parsed.add(element); next ; end
223
-
224
- match_result = match.match(element)
225
-
226
- unless match_result then parsed.add(element); next; end
227
-
228
- if !position_matches?(parsed, to_be_parsed, match_result)
229
- parsed.add(element)
230
- next
231
- end
232
-
233
- parsed, to_be_parsed = handle_match(parse_type, parsed,
234
- to_be_parsed,
235
- match_result, wikiparser)
236
- end
237
-
238
- parsed
239
- end
240
- end
@@ -1,17 +0,0 @@
1
- <p>AT&amp;T has an ampersand in their name.</p>
2
-
3
- <p>AT&amp;T is another way to write it.</p>
4
-
5
- <p>This &amp; that.</p>
6
-
7
- <p>4 &lt; 5.</p>
8
-
9
- <p>6 > 5.</p>
10
-
11
- <p>Here's a <a href="http://example.com/?foo=1&amp;bar=2">link</a> with an ampersand in the URL.</p>
12
-
13
- <p>Here's a link with an amersand in the link text: <a href="http://att.com/" title="AT&amp;T">AT&amp;T</a>.</p>
14
-
15
- <p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
16
-
17
- <p>Here's an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
@@ -1,21 +0,0 @@
1
- AT&T has an ampersand in their name.
2
-
3
- AT&amp;T is another way to write it.
4
-
5
- This & that.
6
-
7
- 4 < 5.
8
-
9
- 6 > 5.
10
-
11
- Here's a [link] [1] with an ampersand in the URL.
12
-
13
- Here's a link with an amersand in the link text: [AT&T] [2].
14
-
15
- Here's an inline [link](/script?foo=1&bar=2).
16
-
17
- Here's an inline [link](</script?foo=1&bar=2>).
18
-
19
-
20
- [1]: http://example.com/?foo=1&bar=2
21
- [2]: http://att.com/ "AT&T"
@@ -1,18 +0,0 @@
1
- <p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
2
-
3
- <p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a></p>
4
-
5
- <ul>
6
- <li>In a list?</li>
7
- <li><a href="http://example.com/">http://example.com/</a></li>
8
- <li>It should.</li>
9
- </ul>
10
-
11
- <blockquote>
12
- <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
13
- </blockquote>
14
-
15
- <p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
16
-
17
- <pre><code>or here: &lt;http://example.com/&gt;
18
- </code></pre>
@@ -1,13 +0,0 @@
1
- Link: <http://example.com/>.
2
-
3
- With an ampersand: <http://example.com/?foo=1&bar=2>
4
-
5
- * In a list?
6
- * <http://example.com/>
7
- * It should.
8
-
9
- > Blockquoted: <http://example.com/>
10
-
11
- Auto-links should not occur here: `<http://example.com/>`
12
-
13
- or here: <http://example.com/>
@@ -1,68 +0,0 @@
1
- <p>These should not, because they occur within a code block:</p>
2
-
3
- <pre><code>Backslash: \\
4
-
5
- Backtick: \`
6
-
7
- Asterisk: \*
8
-
9
- Underscore: \_
10
-
11
- Left brace: \{
12
-
13
- Right brace: \}
14
-
15
- Left bracket: \[
16
-
17
- Right bracket: \]
18
-
19
- Left paren: \(
20
-
21
- Right paren: \)
22
-
23
- Greater-than: \&gt;
24
-
25
- Hash: \#
26
-
27
- Period: \.
28
-
29
- Bang: \!
30
-
31
- Plus: \+
32
-
33
- Minus: \-
34
- </code></pre>
35
-
36
- <p>Nor should these, which occur in code spans:</p>
37
-
38
- <p>Backslash: <code>\\</code></p>
39
-
40
- <p>Backtick: <code>\`</code></p>
41
-
42
- <p>Asterisk: <code>\*</code></p>
43
-
44
- <p>Underscore: <code>\_</code></p>
45
-
46
- <p>Left brace: <code>\{</code></p>
47
-
48
- <p>Right brace: <code>\}</code></p>
49
-
50
- <p>Left bracket: <code>\[</code></p>
51
-
52
- <p>Right bracket: <code>\]</code></p>
53
-
54
- <p>Left paren: <code>\(</code></p>
55
-
56
- <p>Right paren: <code>\)</code></p>
57
-
58
- <p>Greater-than: <code>\&gt;</code></p>
59
-
60
- <p>Hash: <code>\#</code></p>
61
-
62
- <p>Period: <code>\.</code></p>
63
-
64
- <p>Bang: <code>\!</code></p>
65
-
66
- <p>Plus: <code>\+</code></p>
67
-
68
- <p>Minus: <code>\-</code></p>
@@ -1,68 +0,0 @@
1
- These should not, because they occur within a code block:
2
-
3
- Backslash: \\
4
-
5
- Backtick: \`
6
-
7
- Asterisk: \*
8
-
9
- Underscore: \_
10
-
11
- Left brace: \{
12
-
13
- Right brace: \}
14
-
15
- Left bracket: \[
16
-
17
- Right bracket: \]
18
-
19
- Left paren: \(
20
-
21
- Right paren: \)
22
-
23
- Greater-than: \>
24
-
25
- Hash: \#
26
-
27
- Period: \.
28
-
29
- Bang: \!
30
-
31
- Plus: \+
32
-
33
- Minus: \-
34
-
35
-
36
- Nor should these, which occur in code spans:
37
-
38
- Backslash: `\\`
39
-
40
- Backtick: `` \` ``
41
-
42
- Asterisk: `\*`
43
-
44
- Underscore: `\_`
45
-
46
- Left brace: `\{`
47
-
48
- Right brace: `\}`
49
-
50
- Left bracket: `\[`
51
-
52
- Right bracket: `\]`
53
-
54
- Left paren: `\(`
55
-
56
- Right paren: `\)`
57
-
58
- Greater-than: `\>`
59
-
60
- Hash: `\#`
61
-
62
- Period: `\.`
63
-
64
- Bang: `\!`
65
-
66
- Plus: `\+`
67
-
68
- Minus: `\-`
@@ -1,33 +0,0 @@
1
- <p>These should all get escaped:</p>
2
-
3
- <p>Backslash: \</p>
4
-
5
- <p>Backtick: `</p>
6
-
7
- <p>Asterisk: *</p>
8
-
9
- <p>Underscore: _</p>
10
-
11
- <p>Left brace: {</p>
12
-
13
- <p>Right brace: }</p>
14
-
15
- <p>Left bracket: [</p>
16
-
17
- <p>Right bracket: ]</p>
18
-
19
- <p>Left paren: (</p>
20
-
21
- <p>Right paren: )</p>
22
-
23
- <p>Greater-than: ></p>
24
-
25
- <p>Hash: #</p>
26
-
27
- <p>Period: .</p>
28
-
29
- <p>Bang: !</p>
30
-
31
- <p>Plus: +</p>
32
-
33
- <p>Minus: -</p>
@@ -1,33 +0,0 @@
1
- These should all get escaped:
2
-
3
- Backslash: \\
4
-
5
- Backtick: \`
6
-
7
- Asterisk: \*
8
-
9
- Underscore: \_
10
-
11
- Left brace: \{
12
-
13
- Right brace: \}
14
-
15
- Left bracket: \[
16
-
17
- Right bracket: \]
18
-
19
- Left paren: \(
20
-
21
- Right paren: \)
22
-
23
- Greater-than: \>
24
-
25
- Hash: \#
26
-
27
- Period: \.
28
-
29
- Bang: \!
30
-
31
- Plus: \+
32
-
33
- Minus: \-
@@ -1,15 +0,0 @@
1
- <blockquote>
2
- <p>Example:</p>
3
-
4
- <pre><code>sub status {
5
- print "working";
6
- }
7
- </code></pre>
8
-
9
- <p>Or:</p>
10
-
11
- <pre><code>sub status {
12
- return "working";
13
- }
14
- </code></pre>
15
- </blockquote>
@@ -1,11 +0,0 @@
1
- > Example:
2
- >
3
- > sub status {
4
- > print "working";
5
- > }
6
- >
7
- > Or:
8
- >
9
- > sub status {
10
- > return "working";
11
- > }
@@ -1,8 +0,0 @@
1
- <p>In Markdown 1.0.0 and earlier. Version
2
- 8. This line turns into a list item.
3
- Because a hard-wrapped line in the
4
- middle of a paragraph looked like a
5
- list item.</p>
6
-
7
- <p>Here's one with a bullet.
8
- * criminey.</p>
@@ -1,8 +0,0 @@
1
- In Markdown 1.0.0 and earlier. Version
2
- 8. This line turns into a list item.
3
- Because a hard-wrapped line in the
4
- middle of a paragraph looked like a
5
- list item.
6
-
7
- Here's one with a bullet.
8
- * criminey.
@@ -1,71 +0,0 @@
1
- <p>Dashes:</p>
2
-
3
- <hr />
4
-
5
- <hr />
6
-
7
- <hr />
8
-
9
- <hr />
10
-
11
- <pre><code>---
12
- </code></pre>
13
-
14
- <hr />
15
-
16
- <hr />
17
-
18
- <hr />
19
-
20
- <hr />
21
-
22
- <pre><code>- - -
23
- </code></pre>
24
-
25
- <p>Asterisks:</p>
26
-
27
- <hr />
28
-
29
- <hr />
30
-
31
- <hr />
32
-
33
- <hr />
34
-
35
- <pre><code>***
36
- </code></pre>
37
-
38
- <hr />
39
-
40
- <hr />
41
-
42
- <hr />
43
-
44
- <hr />
45
-
46
- <pre><code>* * *
47
- </code></pre>
48
-
49
- <p>Underscores:</p>
50
-
51
- <hr />
52
-
53
- <hr />
54
-
55
- <hr />
56
-
57
- <hr />
58
-
59
- <pre><code>___
60
- </code></pre>
61
-
62
- <hr />
63
-
64
- <hr />
65
-
66
- <hr />
67
-
68
- <hr />
69
-
70
- <pre><code>_ _ _
71
- </code></pre>
@@ -1,67 +0,0 @@
1
- Dashes:
2
-
3
- ---
4
-
5
- ---
6
-
7
- ---
8
-
9
- ---
10
-
11
- ---
12
-
13
- - - -
14
-
15
- - - -
16
-
17
- - - -
18
-
19
- - - -
20
-
21
- - - -
22
-
23
-
24
- Asterisks:
25
-
26
- ***
27
-
28
- ***
29
-
30
- ***
31
-
32
- ***
33
-
34
- ***
35
-
36
- * * *
37
-
38
- * * *
39
-
40
- * * *
41
-
42
- * * *
43
-
44
- * * *
45
-
46
-
47
- Underscores:
48
-
49
- ___
50
-
51
- ___
52
-
53
- ___
54
-
55
- ___
56
-
57
- ___
58
-
59
- _ _ _
60
-
61
- _ _ _
62
-
63
- _ _ _
64
-
65
- _ _ _
66
-
67
- _ _ _