maruku 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/bin/maruku +9 -3
  2. data/docs/changelog.html +52 -4
  3. data/docs/changelog.md +35 -5
  4. data/docs/index.html +13 -5
  5. data/docs/maruku.html +13 -5
  6. data/docs/maruku.md +14 -3
  7. data/lib/maruku/defaults.rb +4 -1
  8. data/lib/maruku/input/parse_block.rb +1 -1
  9. data/lib/maruku/input/parse_span_better.rb +14 -9
  10. data/lib/maruku/input/type_detection.rb +1 -1
  11. data/lib/maruku/input_textile2/t2_parser.rb +1 -1
  12. data/lib/maruku/output/to_html.rb +10 -0
  13. data/lib/maruku/output/to_latex.rb +1 -1
  14. data/lib/maruku/string_utils.rb +4 -0
  15. data/lib/maruku/tests/new_parser.rb +1 -1
  16. data/lib/maruku/version.rb +1 -1
  17. data/maruku_gem.rb +1 -1
  18. data/tests/unittest/email.md +2 -2
  19. data/tests/unittest/inline_html.md +134 -8
  20. data/tests/unittest/links.md +1 -1
  21. data/tests/unittest/links2.md +42 -0
  22. data/tests/unittest/lists10.md +62 -0
  23. data/tests/unittest/lists11.md +57 -0
  24. data/tests/unittest/lists8.md +2 -7
  25. data/tests/unittest/lists_after_paragraph.md +2 -2
  26. data/tests/unittest/misc_sw.md +2 -2
  27. data/tests/unittest/notyet/triggering.md +2 -2
  28. data/tests/unittest/paragraphs.md +1 -1
  29. data/tests/unittest/wrapping.md +2 -2
  30. data/unit_test_block.sh +5 -0
  31. data/unit_test_span.sh +2 -0
  32. metadata +215 -213
  33. data/lib/maruku/ext/diagrams/diagrams.rb +0 -8
  34. data/lib/maruku/ext/diagrams/grid.rb +0 -78
  35. data/lib/maruku/ext/diagrams/inspect.rb +0 -11
  36. data/lib/maruku/ext/diagrams/layout.rb +0 -508
  37. data/lib/maruku/ext/diagrams/parser.rb +0 -219
  38. data/lib/maruku/ext/diagrams/structures.rb +0 -168
  39. data/lib/maruku/ext/diagrams/to_html.rb +0 -37
  40. data/lib/maruku/ext/diagrams/to_latex.rb +0 -103
  41. data/lib/maruku/ext/diagrams/unittest.rb +0 -123
@@ -1,219 +0,0 @@
1
- module Diagrams
2
-
3
- class Diagram
4
- def create_grid_from_string(string)
5
- lines = string.split("\n").map{|x| x.gsub(/\s*$/,'') }
6
-
7
- while lines.first && lines.first.strip.size == 0; lines.shift end
8
- while lines.last && lines.last.strip.size == 0; lines.pop end
9
- width = lines.map{|x| x.size}.max
10
- height = lines.size
11
-
12
- grid = Grid.new(width, height, 32)
13
- for y in 0..height-1
14
- for x in 0..width-1
15
- grid.set(x, y, lines[y][x])
16
- end
17
- end
18
- grid
19
- end
20
-
21
-
22
- def detect_points
23
- [?+, ?*].each do |p|
24
- for_each_to_process(p) do |x,y|
25
- point = Point.new
26
- point.pos = [x, y]
27
- point.char = p
28
- @to_process.set(x,y,false)
29
- @points.push point
30
- @occup.set(x,y, point)
31
- end
32
- end
33
-
34
- @points.each do |p1|
35
- @points.each do |p2|
36
- if p1 != p2
37
- if p2.pos.x < p1.pos.x
38
- p1.aligned[:t].push(p2) if p2.pos.y == p1.pos.y
39
- end
40
- if p2.pos.y < p1.pos.y
41
- p1.aligned[:l].push(p2) if p2.pos.x == p1.pos.x
42
- end
43
- end
44
- end
45
- end
46
- end
47
-
48
- def detect_arrows
49
- [ [?|, /^\|*$/, [?^, ?A], [?v, ?V], 0, 1, :S],
50
- [?-, /^\-*$/, [?<], [?>], 1, 0, :E],
51
- [?\\,/^\\*$/, [], [], 1, 1, :SE],
52
- [?/, /^\/*$/, [], [], -1, 1, :SW]
53
- ].each do |char, reg, cap1, cap2, inc_x, inc_y, ty|
54
- for_each_to_process(char) do |x,y,e|
55
- find_arrow(x, y, reg, cap1, cap2, inc_x, inc_y)
56
- end
57
- end
58
- end
59
-
60
-
61
- def find_arrow(x, y, reg, cap1, cap2, inc_x, inc_y)
62
- inc = [inc_x, inc_y]
63
- rinc = [-inc_x, -inc_y]
64
-
65
- a = Arrow.new
66
-
67
- if cap1.include?(c = @text.get(x-inc_x, y-inc_y))
68
- a.cap1 = c
69
- a.start_pos = [x-inc_x, y-inc_y]
70
- else
71
- a.cap1 = nil
72
- a.start_pos = [x,y]
73
- end
74
-
75
- s = match(x,y,reg,inc_x,inc_y)
76
- len = s.size
77
-
78
- a.end_pos = [x+(len-1)*inc_x, y+(len-1)*inc_y]
79
- maybe_cap = [x+(len)*inc_x, y+(len)*inc_y]
80
- if cap2.include?(c=@text.get(*maybe_cap))
81
- len +=1
82
- a.end_pos = maybe_cap
83
- a.cap2 = c
84
- else
85
- a.cap2 = nil
86
- end
87
-
88
- a.length = len
89
-
90
- before = [a.start_pos[0]-inc_x,a.start_pos[1]-inc_y]
91
- if ob = @occup.get(*before)
92
- impact = ob.link_direction(before, rinc)
93
- ob.links[impact] << a
94
- a.links[Reverse[impact]]<< ob
95
- a.start_link = ob
96
- else
97
- puts "Nothing found at #{before.inspect} : #{
98
- @text.get(*before)
99
- } while #{@text.get(*a.start_pos).chr}"
100
- end
101
- after = [a.end_pos[0]+inc_x,a.end_pos[1]+inc_y]
102
- if ob = @occup.get(*after)
103
- impact = ob.link_direction(after, inc)
104
- ob.links[impact] << a
105
- a.links[Reverse[impact]] << ob
106
- a.end_link = ob
107
- else
108
- puts "Nothing found at #{after.inspect} : #{
109
- @text.get(*after)
110
- } while #{@text.get(*a.end_pos).chr}"
111
- end
112
-
113
- iterate(a.start_pos,a.end_pos) do |x,y|
114
- @to_process.set(x,y,false)
115
- @occup.set(x,y,a)
116
- end
117
-
118
- @arrows.push a
119
- p a
120
- end
121
-
122
- def iterate(pos1,pos2)
123
- inc_x = pos2[0]-pos1[0]
124
- inc_y = pos2[1]-pos1[1]
125
- len = [inc_x.abs,inc_y.abs].max + 1
126
- if inc_x.abs > inc_y.abs
127
- len = inc_x.abs + 1
128
- else
129
- len = inc_y.abs + 1
130
- end
131
-
132
- inc_x /= inc_x.abs if inc_x != 0
133
- inc_y /= inc_y.abs if inc_y != 0
134
-
135
- # raise "" if inc_x
136
- for i in 0..(len-1)
137
- x, y = pos1[0]+i*inc_x,pos1[1]+i*inc_y
138
- yield x,y
139
- end
140
- end
141
-
142
- def detect_boxes
143
- for_each_to_process(?+) do |x,y,e|
144
- find_box(x,y,/^\+[\-\+]+\+$/, /^\+[\|\+]+\+$/)
145
- end
146
- for_each_to_process(?/) do |x,y,e|
147
- find_box(x,y,/^\/[\-\+]+\\$/, /^\/[\|\+]+\\$/)
148
- end
149
-
150
- # find alignments
151
- @boxes.each do |b1|
152
- @boxes.each do |b2|
153
- if b1 != b2
154
- if (b2.y < b1.y)
155
- b1.aligned[:l].push(b2) if (b1.x == b2.x)
156
- b1.aligned[:r].push(b2) if (b1.x+b1.width == b2.x+b2.width)
157
- end
158
- if (b2.x < b1.x)
159
- b1.aligned[:t].push(b2) if (b1.y == b2.y)
160
- b1.aligned[:b].push(b2) if (b1.y+b1.height == b2.y+b2.height)
161
- end
162
- end
163
- end
164
- end
165
- end
166
-
167
- def for_each_to_process(char)
168
- @text.each do |x,y,e|
169
- if e === char && @to_process.get(x,y)
170
- yield x, y, e
171
- end
172
- end
173
- end
174
-
175
- def find_box(x,y,hmatch,vmatch)
176
- horiz = match_horiz(x,y,hmatch)
177
- vert = match_vert(x,y,vmatch)
178
-
179
- return if not horiz or not vert
180
- width, height = horiz.size, vert.size
181
- if (width > 2) && (height > 2)
182
- # mark the cell as processed
183
- @to_process.set_area(x, y, horiz.size, vert.size, false)
184
- box = Box.new(x,y,width,height)
185
- box.content = @text.read_area(x+1,y+1,width-2,height-2)
186
- box.content.gsub!(/\n/,' ')
187
- # mark the area as occupied by the box
188
- @occup.set_area(x, y, horiz.size, vert.size, box)
189
- @boxes.push box
190
- end
191
- end
192
-
193
- def match(x,y,reg,inc_x,inc_y)
194
- s = ""
195
- best = nil
196
- while x<@text.width && y < @text.height
197
- s << @text.get(x,y).chr
198
- break if not @to_process.get(x,y)
199
- if s =~ reg
200
- best = s.dup
201
- end
202
- x += inc_x; y += inc_y
203
- end
204
- best
205
- end
206
-
207
- def match_horiz(x,y,reg)
208
- match(x,y,reg,1,0)
209
- end
210
-
211
- def match_vert(x,y,reg)
212
- match(x,y,reg,0,1)
213
- end
214
-
215
-
216
- end
217
-
218
-
219
- end # moudle Diagram
@@ -1,168 +0,0 @@
1
- class Array
2
- def x() self[0] end
3
- def y() self[1] end
4
- end
5
-
6
- module Diagrams
7
-
8
- class Spring
9
- attr_accessor :min,:shrink,:pref,:stretch,:max
10
- attr_accessor :weight #not used yet
11
- attr_accessor :imposed
12
-
13
- def initialize(min,shrink,pref,stretch,max)
14
- @min,@shrink,@pref,@stretch,@max =
15
- min, shrink, pref, stretch, max
16
- end
17
-
18
- def Spring.series(s1,s2)
19
- Spring.new(
20
- s1.min+s2.min,
21
- s1.shrink+s2.shrink,
22
- s1.pref+s2.pref,
23
- s1.stretch+s2.stretch,
24
- s1.max+s2.max
25
- )
26
- end
27
-
28
- def Spring.parallel(s1,s2)
29
- pref = (s1.pref+s2.pref)*0.5
30
- pref = [s1.min, pref].max
31
- pref = [s1.max, pref].min
32
- pref = [s2.min, pref].max
33
- pref = [s2.max, pref].min
34
-
35
- Spring.new(
36
- [s1.min,s2.min].max,
37
- [s1.shrink,s2.shrink].min,
38
- pref,
39
- [s1.stretch,s2.stretch].min,
40
- [s1.max,s2.max].min
41
- )
42
- end
43
-
44
-
45
- def inspect
46
- if @min == @max
47
- "Fixed(#{@min})"
48
- else
49
- "S[%.1f(%.1f)%.1f(%.1f)%.1f]=%.1f" %
50
- [ @min, @shrink, @pref, @stretch, @max, @imposed || -1]
51
- end
52
- end
53
- end
54
-
55
- Reverse = {:N=>:S,:S=>:N,:W=>:E,:E=>:W}
56
-
57
- class Sized
58
- attr_accessor :hs, :vs # horizontal, vertical spring
59
- attr_accessor :links #hash :N,:S,:W,:E
60
- def initialize
61
- @hs = Spring.new(1,0,1,0,1)
62
- @vs = Spring.new(1,0,1,0,1)
63
- @links = {:N=>[],:E=>[],:W=>[],:S=>[]}
64
- end
65
- end
66
-
67
- class Arrow < Sized
68
- attr_accessor :type # :S, :NW, :SE, :E
69
- attr_accessor :cap1,:cap2 # either nil or the cap
70
- attr_accessor :start_pos, :end_pos
71
- attr_accessor :start_link, :end_link
72
- attr_accessor :length
73
- attr_accessor :object_start, :object_end
74
-
75
-
76
- # variables for start and end
77
- attr_accessor :v_start,:v_end
78
-
79
- def is_vert?
80
- start_pos.x == end_pos.x
81
- end
82
-
83
- end
84
-
85
-
86
- class Box < Sized
87
- attr_accessor :x,:y,:width,:height
88
- attr_accessor :content
89
-
90
- attr_accessor :aligned
91
-
92
- # variables for top-left and bottom-right
93
- attr_accessor :v_tl,:v_br
94
-
95
-
96
- def initialize(x,y,width,height)
97
- super()
98
- @x,@y,@width,@height = x,y,width,height
99
- @aligned = {:l=>[],:t=>[],:b=>[],:r=>[]}
100
- end
101
-
102
- # pos: position touching this
103
- # from: other
104
- def link_direction(pos, inc)
105
- if pos.x == @x then return :W end
106
- if pos.x == @x+@width-1 then return :E end
107
- if pos.y == @y then return :N end
108
- if pos.y == @y+@height-1 then return :S end
109
- raise "Strange #{pos.inspect}: "+self.inspect
110
- end
111
- end
112
-
113
- class Point < Sized
114
- attr_accessor :pos
115
- attr_accessor :char
116
-
117
- attr_accessor :aligned
118
-
119
- # variables for point position
120
- attr_accessor :v_p
121
-
122
- def initialize
123
- super()
124
- @aligned = {:l=>[],:t=>[]}
125
- end
126
-
127
- def link_direction(pos, inc)
128
- if inc.x > 0 then return :W end
129
- if inc.x < 0 then return :E end
130
- if inc.y > 0 then return :N end
131
- if inc.y < 0 then return :S end
132
- raise "Strange #{inc.inspect}: "+self.inspect
133
- end
134
- end
135
-
136
-
137
- class Diagram
138
- attr_accessor :boxes, :points, :arrows
139
-
140
- attr_accessor :text, :occup, :to_process
141
-
142
- def initialize(s)
143
- @text = create_grid_from_string(s)
144
- @to_process = Grid.new(@text.width, @text.height, false)
145
- @occup = Grid.new(@text.width, @text.height, nil)
146
- @boxes = []
147
- @points = []
148
- @arrows = []
149
- # mark cells to process
150
- @text.each do |x,y,e|
151
- @to_process.set(x,y,true) if e != 32
152
- end
153
- @width, @height = @text.width,@text.height
154
-
155
- # p @to_process
156
-
157
- puts @text.inspect2(@to_process)
158
-
159
- detect_boxes
160
- detect_points
161
- detect_arrows
162
-
163
- puts @text.inspect2(@to_process)
164
- end
165
- end
166
-
167
-
168
- end
@@ -1,37 +0,0 @@
1
- require 'rexml/document'
2
-
3
- module Diagrams
4
-
5
- class Diagram
6
-
7
-
8
- include REXML
9
- def to_html
10
- div = Element.new 'div'
11
- div.add_element 'div', {'style'=>'width: 1em', 'id'=>'emtest'}
12
- div.attributes['style'] =
13
- "position:relative; display: block; width: #{@width}em; height: #{@height}em;"
14
- div.attributes['class'] = 'diagram'
15
- @boxes.each_with_index do |b, i|
16
- box = Element.new 'div'
17
- box.attributes['class'] = 'box'
18
-
19
- w = b.width
20
- box.attributes['id'] = "box#{i}"
21
- box.attributes['style'] =
22
- "position:absolute; left:#{b.x}em; top:#{b.y}em; border:solid 1px black;"
23
- content = Element.new 'div', box
24
- content.attributes['class'] = 'inner'
25
- content << Text.new( b.content )
26
- div << box
27
- div << Text.new("\n")
28
- end
29
- div
30
- end
31
-
32
-
33
- end
34
-
35
-
36
-
37
- end
@@ -1,103 +0,0 @@
1
-
2
- module Diagrams
3
-
4
- class Diagram
5
-
6
- def write_tex_discovery(diag_id, output_file)
7
- fid = 10
8
- s = ("\\immediate\\openout%d=%s\n" % [fid, output_file])
9
- @boxes.each_with_index do |b, i|
10
- s += ("\\setbox0=\\hbox{%s}\n" % b.content)
11
- s += "\\immediate\\write%d{%s,%d,\\the\\wd0,\\the\\ht0,\\the\\dp0 ,%s}\n" %
12
- [fid, diag_id, i, b.content]
13
- end
14
- s += "\\end\n"
15
- s
16
- end
17
-
18
- def write_latex_discovery(diag_id, output_file)
19
- fid = 10
20
- s=""
21
- # s +="\\documentclass{article}\\begin{document}"
22
- s += ("\\immediate\\openout%d=%s\n" % [fid, output_file])
23
- # s+= "\\ifx\\already\\empty"
24
- # s+="\\def\\already{1}"
25
- # s+= "\\newlength{\\mywd}\n"
26
- # s+= "\\newlength{\\myht}\n"
27
- # s+= "\\newlength{\\mydp}\n"
28
- # s+="\\fi"
29
- @boxes.each_with_index do |b, i|
30
- s += ("\\settowidth{\\mywd}{\\hbox{%s}}\n" % b.content)
31
- s += ("\\settoheight{\\myht}{\\hbox{%s}}\n" % b.content)
32
- s += ("\\settodepth{\\mydp}{\\hbox{%s}}\n" % b.content)
33
- s += "\\immediate\\write%d{%s,%d,\\the\\mywd,\\the\\myht,\\the\\mydp}\n" %
34
- [fid, diag_id, i]
35
- end
36
- s+=("\\immediate\\closeout%d\n" % fid)
37
- # s+="\\end{document}"
38
- s
39
- end
40
-
41
- def read_tex_discovery(my_diag_id, s)
42
- s.split("\n").each do |l|
43
- diag_id, box_index, wd, ht, dp, text = l.split(",")
44
- if diag_id == my_diag_id
45
- puts "found box #{box_index}: #{wd} #{ht} #{dp}"
46
- wd,ht,dp = wd.to_f,ht.to_f,dp.to_f
47
- width = wd
48
- height = ht+dp
49
- puts "found box #{box_index}: #{width}x#{height}"
50
- i = box_index.to_i
51
- @boxes[i].hs.min = width
52
- @boxes[i].hs.shrink = 1
53
- @boxes[i].hs.pref = width*1.2
54
- @boxes[i].hs.stretch = 0.1
55
- @boxes[i].hs.max = 1000
56
- @boxes[i].vs.min = height
57
- @boxes[i].vs.shrink = 1
58
- @boxes[i].vs.pref = height*1.2
59
- @boxes[i].vs.stretch = 0.1
60
- @boxes[i].vs.max = 1000
61
- end
62
- end
63
- end
64
-
65
- def to_latex(job="anon_diagram")
66
- do_discovery = true
67
-
68
- tmp_out = "#{job}.dia"
69
-
70
- diag_id = "dia"
71
- s = write_latex_discovery(diag_id, tmp_out)
72
-
73
- if File.exist?(tmp_out)
74
- File.open(tmp_out, 'r') do |f|
75
- read_tex_discovery(diag_id, f.read)
76
- end
77
- end
78
-
79
- do_layout(job)
80
-
81
- @boxes.each_with_index do |b, i|
82
- width = b.hs.min
83
- height = b.vs.min
84
- s << ("\\framebox[%fpt]{\\rule{10pt}{%fpt}%s}"% [width,height, b.content])
85
- end
86
-
87
- s+="\n\nCiao\n\n"
88
- s
89
- end
90
-
91
-
92
- # in points
93
- def to_dev(x)
94
- x * 10
95
- end
96
-
97
-
98
- end
99
-
100
- end
101
-
102
-
103
-