martile 0.1.26 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a886f82c2bff38a89cd3f9359f3d12dd28cddfa
4
- data.tar.gz: 29c17fc6058147279d46b8be5b6fb824724c60b2
3
+ metadata.gz: 1bd0764fcf645b03a35dcb6d27b423c2fbd2ef5c
4
+ data.tar.gz: 47583be9f06a798ea9ba1ff2e224a319efa76648
5
5
  SHA512:
6
- metadata.gz: ab7d032ac774a73891a69224952be3ca1740a59bb7f9aaac77222850b68ef8849df37627c9690d953d085468f2c3551d589351fdda0dfdd10edb3b0c1da2434d
7
- data.tar.gz: 06ff6985bfd449d0693a8d5c4b612c803866a7e52df4a0610756a1df738948f3faffa98300db51f42d1237e25a0cbc85bc9974c2139125066bfbd740761e2fe5
6
+ metadata.gz: 1e7a4c0b49e109ac5357a305f3b40706523984a42b3524dc7126488c1223d2822f9c02efcf12f625fb5011b181abca7052cc606b63192229ed87a76f813b393a
7
+ data.tar.gz: d42f83523621072e67a4a7df8de6efb74822d23f5c6612749383fca7fdc215c68e9b284a41c8ddc9950d9125b09e4f5b069b66f99f06bcb1b5f72b08d2dc515f
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/martile.rb CHANGED
@@ -8,6 +8,8 @@ require 'dynarex'
8
8
  require 'rdiscount'
9
9
 
10
10
 
11
+ # bug fix: 03-Apr-2014: XML or HTML elements should now be filtered out
12
+ # of any transformations.
11
13
  # feature: 31-Mar-2014: Added an _underline_ feature.
12
14
  # bug fix: 01-Mar-2014: A Dynarex_to_table statement between 2 HTML blocks
13
15
  # is now handled properly.
@@ -34,7 +36,9 @@ class Martile
34
36
  attr_reader :to_html
35
37
 
36
38
  def initialize(s)
37
- raw_s2 = filter_out_html(s, :code_block_to_html)
39
+
40
+ raw_s2 = apply_filter(s) {|x| code_block_to_html x }
41
+ #puts 'raw_s2: ' + raw_s2.inspect
38
42
 
39
43
  # ensure all angle brackets within <pre><code> is escaped
40
44
  s2 = raw_s2.split(/(?=<pre><code>)/m).map { |y|
@@ -55,16 +59,22 @@ class Martile
55
59
  end
56
60
 
57
61
  #puts 's2 : ' + s2.inspect
58
- s3 = filter_out_html(s2, :ordered_list_to_html)
62
+
63
+ s3 = apply_filter(s2) {|x| ordered_list_to_html x }
59
64
  #puts 's3 : ' + s3.inspect
60
- s4 = filter_out_html(s3, :unordered_list_to_html)
65
+
66
+ s4 = apply_filter(s3) {|x| unordered_list_to_html x }
61
67
  #puts 's4 : ' + s4.inspect
62
- s5 = filter_out_html(s4, :dynarex_to_table)
68
+
69
+ s5 = apply_filter(s4) {|x| dynarex_to_table x }
63
70
  #puts 's5 :' + s5.inspect
64
- s6 = filter_out_html(s5, :table_to_html)
71
+
72
+ s6 = apply_filter(s5) {|x| table_to_html x }
65
73
  #puts 's6 : ' + s6.inspect
66
- s7 = filter_out_html(s6, :underline)
74
+
75
+ s7 = apply_filter(s6) {|x| underline x }
67
76
  #puts 's7 : ' + s7.inspect
77
+
68
78
  @to_html = s7
69
79
  end
70
80
 
@@ -105,8 +115,8 @@ class Martile
105
115
 
106
116
  dynarex = Dynarex.new($1)
107
117
  dynarex.to_h.map(&:values)
108
- '[' + dynarex.to_h.map{|x| x.values.join('|') + "\n"}
109
- .join('|').chomp + ']'
118
+ '[' + dynarex.to_h.map{|x| x.values.join('|').gsub('<','&lt;')\
119
+ .gsub('>','&gt;') + "\n"}.join('|').chomp + ']'
110
120
  end
111
121
  end
112
122
 
@@ -136,19 +146,11 @@ class Martile
136
146
 
137
147
  end
138
148
 
139
- def filter_out_html(s, name)
140
-
141
- s.gsub(/<(\w+)>[^(?:<\/\1>)]+<\/\1>*|.+/m) do |x|
149
+ def apply_filter(s, &block)
142
150
 
143
- html = x[/<(\w+)>[^(?:<\/\1>)]+<\/\1>/m]
144
- plain_text = html ? ($') : x
145
- text1 = ($`).to_s
146
- s1 = text1.length > 0 ? self.method(name).call(text1) : ''
147
- #puts 'plain_text : ' + plain_text.inspect
148
- s2 = plain_text.length > 0 ? self.method(name).call(plain_text.to_s) : ''
149
- s1 + html.to_s + s2
150
- end
151
- end
151
+ Rexle.new("<root>#{s}</root>").root\
152
+ .map {|x| x.is_a?(String) ? block.call(x) : x}.join
153
+ end
152
154
 
153
155
  def ordered_list_to_html(s)
154
156
  list_to_html s, '#'
@@ -174,9 +176,8 @@ class Martile
174
176
  end
175
177
  end
176
178
  end
177
- puts 'a = ' + a.inspect
179
+
178
180
  r = Rexle.new(a).xml pretty: true, declaration: false
179
- puts 'r : ' + r.inspect
180
181
  r
181
182
  end
182
183
  return s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: martile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  YF3JmVOebtMx3b9sXkLX1YyX0fsg59FXvg9CVfAoaG6qjG2Y/okBwMSqqMLQiiao
32
32
  aRfEuwOkM9Z+zA==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-03-31 00:00:00.000000000 Z
34
+ date: 2014-04-03 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rexle-builder
metadata.gz.sig CHANGED
Binary file