tartan 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,242 @@
1
+ # $Id: wiki_rule.rb 181 2007-01-05 20:59:06Z bitherder $
2
+ require 'core_ext/regexp'
3
+
4
+ module Tartan
5
+ class WikiRule < Hash
6
+ def initialize(matcher={})
7
+ matcher.each { |(a, v)| self[a] = v }
8
+ end
9
+
10
+ def matcher
11
+ self
12
+ end
13
+
14
+ # define methods to access elements of matcher hash
15
+ def method_missing(method_symbol)
16
+ self.class.send(:define_method, method_symbol) {self[method_symbol]}
17
+ self[method_symbol]
18
+ end
19
+
20
+ def match
21
+ self[:match] ? self[:match].to_regexp : nil
22
+ end
23
+
24
+ def strip_match
25
+ strip = self[:strip]
26
+ (strip and strip[:match]) ? strip[:match].to_regexp : nil
27
+ end
28
+
29
+ def unstrip_match
30
+ unstrip = self[:unstrip]
31
+ (unstrip and unstrip[:match]) ? unstrip[:match].to_regexp : nil
32
+ end
33
+
34
+ def strip_replace
35
+ self[:strip][:replace]
36
+ end
37
+
38
+ def unstrip_replace
39
+ self[:unstrip][:replace]
40
+ end
41
+
42
+ def placed(position)
43
+ self.delete(position)
44
+ end
45
+
46
+ def default_rule
47
+ self[:default]
48
+ end
49
+
50
+ def start_mark(type)
51
+ return false if self[type].nil? or self[type].class == TrueClass
52
+
53
+ self[type][:start_mark]
54
+ end
55
+
56
+ def end_mark(type)
57
+ return false if self[type].nil? or self[type].class == TrueClass
58
+
59
+ self[type][:end_mark]
60
+ end
61
+
62
+ def replace_regex(type)
63
+ return false if self[type].nil? or self[type].class == TrueClass
64
+
65
+ self[type][:replace]
66
+ end
67
+
68
+ def target_position
69
+ self[:position]
70
+ end
71
+
72
+ def vars_to_set
73
+ self[:set]
74
+ end
75
+
76
+ def subparse_context
77
+ return nil if ! self.has_key?(:subparse)
78
+
79
+ if self[:subparse].is_a?(Symbol) or self[:subparse].is_a?(String)
80
+ return self[:subparse]
81
+ elsif self[:subparse].has_key?(:context)
82
+ return self[:subparse][:context]
83
+ end
84
+
85
+ return nil
86
+ end
87
+
88
+ def subparse_match_group
89
+ if has_key?(:subparse) and
90
+ self[:subparse].is_a?(Hash) and
91
+ self[:subparse].has_key?(:match_group)
92
+ self[:subparse][:match_group]
93
+ else
94
+ nil
95
+ end
96
+ end
97
+
98
+ def position_matches?(parsed, to_be_parsed, match_result)
99
+ return true if !target_position
100
+
101
+ pos = parsed.length
102
+
103
+ return true if target_position == pos
104
+ return true if :first == target_position && 0 == pos
105
+
106
+ if 0 == to_be_parsed.length && match_result.post_match.empty?
107
+ return true if :last == target_position
108
+ return true if :all == target_position && 0 == parsed.length
109
+ else
110
+ return true if :not_last == target_position
111
+ end
112
+
113
+ return false
114
+ end
115
+
116
+ def has_type?(type)
117
+ if String == type.class
118
+ type = type.to_sym
119
+ end
120
+
121
+ return self[type]
122
+ end
123
+
124
+ def replace(parse_type, match_result, wikiparser)
125
+ return unless match_result
126
+
127
+ wikiparser.substitute(replace_regex(parse_type), match_result)
128
+ end
129
+
130
+ def block(parse_type, text, match_result, wikiparser)
131
+ return unless match_result
132
+
133
+ mid = text
134
+
135
+ start_strip = ""
136
+ end_strip = ""
137
+
138
+ if subparse_match_group
139
+ subparse_index = match_result.sym2index(subparse_match_group)
140
+
141
+ last_match = match_result.last_match_index
142
+ start_strip = match_result.pre_sub_match(subparse_index)
143
+ end_strip = match_result.post_sub_match(subparse_index)
144
+ mid = match_result[subparse_index]
145
+ end
146
+
147
+ if strip.is_a?(Hash) and strip[:match] and strip[:replace]
148
+ mid = mid.gsub(strip_match, strip_replace)
149
+ end
150
+
151
+ # need to evaluate the start_text before the execution of the
152
+ # sub-parse in case any of the wiki helper functions depend on
153
+ # ordering of the text
154
+ start_text = start_mark(parse_type)?
155
+ wikiparser.substitute(start_mark(parse_type),
156
+ match_result):
157
+ ""
158
+ if subparse_context
159
+ mid = wikiparser.parse_by_context(parse_type, subparse_context, mid)
160
+ end
161
+
162
+ mid = start_text + mid
163
+
164
+ if end_mark(parse_type)
165
+ mid += wikiparser.substitute(end_mark(parse_type), match_result)
166
+ end
167
+
168
+ if ! has_key?(parse_type)
169
+ mid = start_strip + mid + end_strip
170
+
171
+ if unstrip
172
+ mid.gsub!(unstrip_match, unstrip_replace)
173
+ end
174
+ end
175
+
176
+ mid
177
+ end
178
+
179
+ def handle_match(parse_type, parsed, to_be_parsed, match_result, wikiparser)
180
+ debug_opt = wikiparser.get_var('debug')
181
+ if $DEBUG || debug || true == debug_opt || debug_opt == title
182
+ puts "\n%s matches [[%s<<\n%s\n>>%s]]" %
183
+ [title, match_result.pre_match, match_result,
184
+ match_result.post_match]
185
+ end
186
+
187
+ wikiparser.set_vars(vars_to_set, match_result)
188
+
189
+ mid = match_result[0]
190
+
191
+ if replace_regex(parse_type)
192
+ mid = replace(parse_type, match_result, wikiparser)
193
+ elsif true == self[parse_type] or
194
+ start_mark(parse_type) or
195
+ end_mark(parse_type) or
196
+ subparse
197
+
198
+ mid = block(parse_type, mid, match_result, wikiparser)
199
+ end
200
+
201
+ if shelve && mid
202
+ mid = wikiparser.shelve(mid)
203
+ end
204
+
205
+ if "" != match_result.pre_match
206
+ parsed.add_text(false, match_result.pre_match)
207
+ end
208
+
209
+ parsed.add_text(true, mid) if "" != mid
210
+
211
+ if "" != match_result.post_match
212
+ to_be_parsed.add_back_text(false, match_result.post_match)
213
+ end
214
+
215
+ return parsed, to_be_parsed
216
+ end
217
+
218
+ def parse_element(parse_type, to_be_parsed, wikiparser)
219
+ parsed = ParsedTextList.new
220
+
221
+ position = 0
222
+ while element = to_be_parsed.shift
223
+ if element.claimed? then parsed.add(element); next ; end
224
+
225
+ match_result = match.match(element)
226
+
227
+ unless match_result then parsed.add(element); next; end
228
+
229
+ if !position_matches?(parsed, to_be_parsed, match_result)
230
+ parsed.add(element)
231
+ next
232
+ end
233
+
234
+ parsed, to_be_parsed = handle_match(parse_type, parsed,
235
+ to_be_parsed,
236
+ match_result, wikiparser)
237
+ end
238
+
239
+ parsed
240
+ end
241
+ end
242
+ end # Tartan
@@ -0,0 +1,18 @@
1
+ require 'core_ext'
2
+
3
+ module Tartan
4
+ module Wikilink
5
+ module Rules
6
+ def wiki_link_body(page_name, link_body)
7
+ link_body = page_name if "" == link_body
8
+ link_body
9
+ end
10
+
11
+ def wiki_link_tag(page_name)
12
+ raise "wiki_link_tag not properly defined in WikiHelper class"
13
+ end
14
+
15
+ yaml "tartan/wikilink/wikilink.yml"
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,9 @@
1
1
  span:
2
2
  - title: wikilinkWithText
3
- beginning: true
4
- match: "/\[\[([^|]+)[|]([^\]]*)\]\]/"
3
+ after: code_done
4
+ match: '/ \[\[ \s* (.+?) (?= \s* (?:\]\] | \| ) ) \s* \| \s* (.*?) \s* \]\] /x'
5
+ # match: '/\[\[ ((?: . (?! \]\] | \| ) )+.) \| (.*?)\]\] /x'
6
+ # match: "/\[\[([^\]|]+?)[|]([^\]]*)\]\]/"
5
7
  shelve: true
6
8
  subparse:
7
9
  context: span