maruku 0.4.2.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/maruku +66 -20
- data/bin/marutest +12 -2
- data/docs/changelog.html +188 -23
- data/docs/changelog.md +128 -5
- data/docs/entity_test.html +245 -240
- data/docs/entity_test.md +2 -0
- data/docs/exd.html +181 -23
- data/docs/index.html +130 -349
- data/docs/markdown_syntax.html +55 -51
- data/docs/maruku.html +130 -349
- data/docs/maruku.md +154 -339
- data/docs/math.md +143 -0
- data/docs/proposal.html +16 -12
- data/lib/maruku.rb +6 -3
- data/lib/maruku/attributes.rb +7 -2
- data/lib/maruku/defaults.rb +27 -27
- data/lib/maruku/errors_management.rb +10 -9
- data/lib/maruku/ext/diagrams/diagrams.rb +8 -0
- data/lib/maruku/ext/diagrams/grid.rb +78 -0
- data/lib/maruku/ext/diagrams/inspect.rb +11 -0
- data/lib/maruku/ext/diagrams/layout.rb +105 -0
- data/lib/maruku/ext/diagrams/parser.rb +219 -0
- data/lib/maruku/ext/diagrams/structures.rb +168 -0
- data/lib/maruku/ext/diagrams/to_html.rb +37 -0
- data/lib/maruku/ext/diagrams/to_latex.rb +308 -0
- data/lib/maruku/ext/diagrams/unittest.rb +123 -0
- data/lib/maruku/ext/math.rb +11 -0
- data/lib/maruku/ext/math/elements.rb +26 -0
- data/lib/maruku/ext/math/mathml_engines/blahtex.rb +108 -0
- data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +29 -0
- data/lib/maruku/ext/math/mathml_engines/none.rb +20 -0
- data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
- data/lib/maruku/ext/math/parsing.rb +82 -0
- data/lib/maruku/ext/math/to_html.rb +178 -0
- data/lib/maruku/ext/math/to_latex.rb +21 -0
- data/lib/maruku/helpers.rb +11 -0
- data/lib/maruku/input/charsource.rb +1 -1
- data/lib/maruku/input/extensions.rb +68 -0
- data/lib/maruku/input/html_helper.rb +91 -60
- data/lib/maruku/input/parse_block.rb +10 -9
- data/lib/maruku/input/parse_doc.rb +21 -13
- data/lib/maruku/input/parse_span_better.rb +19 -8
- data/lib/maruku/input/type_detection.rb +5 -3
- data/lib/maruku/output/to_html.rb +236 -67
- data/lib/maruku/output/to_latex.rb +69 -26
- data/lib/maruku/output/to_latex_entities.rb +14 -2
- data/lib/maruku/output/to_s.rb +8 -0
- data/lib/maruku/structures.rb +1 -1
- data/lib/maruku/tests/benchmark.rb +2 -2
- data/lib/maruku/tests/new_parser.rb +13 -5
- data/lib/maruku/version.rb +1 -1
- data/lib/sort_prof.rb +22 -0
- data/tests/diagrams/diagrams.md +54 -0
- data/tests/math/syntax.md +46 -0
- data/tests/math_usage/document.md +13 -0
- data/tests/unittest/attributes/attributes.md +50 -6
- data/tests/unittest/easy.md +1 -1
- data/tests/unittest/email.md +3 -3
- data/tests/unittest/entities.md +12 -7
- data/tests/unittest/escaping.md +4 -4
- data/tests/unittest/extra_table1.md +3 -1
- data/tests/unittest/footnotes.md +5 -5
- data/tests/unittest/headers.md +3 -3
- data/tests/unittest/images.md +7 -7
- data/tests/unittest/inline_html.md +51 -5
- data/tests/unittest/links.md +7 -7
- data/tests/unittest/list2.md +1 -1
- data/tests/unittest/lists.md +1 -1
- data/tests/unittest/lists_after_paragraph.md +1 -1
- data/tests/unittest/lists_ol.md +1 -1
- data/tests/unittest/math/equations.md +82 -0
- data/tests/unittest/math/inline.md +80 -0
- data/tests/unittest/math/table.md +51 -0
- data/tests/unittest/math/table2.md +67 -0
- data/tests/unittest/misc_sw.md +24 -24
- data/tests/unittest/notyet/ticks.md +1 -1
- data/tests/unittest/references/long_example.md +2 -2
- data/tests/unittest/smartypants.md +4 -4
- data/tests/unittest/xml.md +68 -0
- data/tests/unittest/xml2.md +36 -0
- data/tests/unittest/xml3.md +52 -0
- data/tests/unittest/xml_instruction.md +5 -5
- metadata +33 -4
- data/docs/a.html +0 -6
- data/docs/char.html +0 -1924
data/docs/math.md
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
LaTeX preamble: math_preamble.tex
|
2
|
+
LaTeX use listings: true
|
3
|
+
CSS: math.css style.css
|
4
|
+
|
5
|
+
Math support in Maruku
|
6
|
+
======================
|
7
|
+
|
8
|
+
|
9
|
+
Introduction...
|
10
|
+
|
11
|
+
* toc
|
12
|
+
{:toc}
|
13
|
+
|
14
|
+
Syntax
|
15
|
+
---------------------------------------
|
16
|
+
|
17
|
+
### Inline math
|
18
|
+
|
19
|
+
Inline math are comprised inside couples of `$`.
|
20
|
+
|
21
|
+
Everything inside `$` will be passed as-is to LaTeX: no Markdown
|
22
|
+
interpretation will take place.
|
23
|
+
|
24
|
+
Example: $x^{n}+y^{n} \neq z^{n}$ for $n \geq 3$
|
25
|
+
|
26
|
+
> Example: $x^{n}+y^{n} \neq z^{n}$ for $n \geq 3$
|
27
|
+
|
28
|
+
### Equations
|
29
|
+
|
30
|
+
Equations are specified using either the `$$ ... $$` or `\[ ... \]`
|
31
|
+
LaTeX notation. Equations can span multiple lines.
|
32
|
+
|
33
|
+
\[
|
34
|
+
\sum_{n=1}^\infty \frac{1}{n}
|
35
|
+
\text{ is divergent, but }
|
36
|
+
\lim_{n \to \infty} \sum_{i=1}^n \frac{1}{i} - \ln n \text{exists.}
|
37
|
+
\]
|
38
|
+
|
39
|
+
> \[
|
40
|
+
> \sum_{n=1}^\infty \frac{1}{n}
|
41
|
+
> \text{ is divergent, but }
|
42
|
+
> \lim_{n \to \infty} \sum_{i=1}^n \frac{1}{i} - \ln n \quad \text{exists.}
|
43
|
+
> \]
|
44
|
+
|
45
|
+
Some random AMSTeX symbols:
|
46
|
+
|
47
|
+
$$ \beth \Subset \bigtriangleup \bumpeq \ggg \pitchfork $$
|
48
|
+
|
49
|
+
$$ \beth \Subset \bigtriangleup \bumpeq \ggg \pitchfork $$
|
50
|
+
|
51
|
+
|
52
|
+
## Cross references ## {#cross}
|
53
|
+
|
54
|
+
Create a label for an equation in two ways:
|
55
|
+
|
56
|
+
* LaTeX style
|
57
|
+
|
58
|
+
Consider \eqref{a}:
|
59
|
+
|
60
|
+
$$ \alpha = \beta \label{a} $$
|
61
|
+
|
62
|
+
* More readable style:
|
63
|
+
|
64
|
+
Consider (eq:a):
|
65
|
+
|
66
|
+
$$ \alpha = \beta $$ (a)
|
67
|
+
|
68
|
+
You can mix the two.
|
69
|
+
|
70
|
+
Labels will work as expected also in the PDF output, whatever
|
71
|
+
style you use: Maruku will insert the necessary `\label` commands.
|
72
|
+
|
73
|
+
The following are 4 equations, labeled A,B,C,D:
|
74
|
+
|
75
|
+
$$ \alpha $$ (A)
|
76
|
+
|
77
|
+
\[
|
78
|
+
\beta
|
79
|
+
\] (B)
|
80
|
+
|
81
|
+
$$ \gamma \label{C} $$
|
82
|
+
|
83
|
+
\[
|
84
|
+
\delta \label{D}
|
85
|
+
\]
|
86
|
+
|
87
|
+
You can now refer to (eq:A), (eq:B), \eqref{C}, \eqref{D}.
|
88
|
+
|
89
|
+
|
90
|
+
Enabling the extension
|
91
|
+
---------------------------------------
|
92
|
+
|
93
|
+
### On the command line
|
94
|
+
|
95
|
+
Use the `-m` option to choose the kind of output. Possible choices are:
|
96
|
+
|
97
|
+
* `-m itex2mml`
|
98
|
+
|
99
|
+
[Instructions for itex2mml][itex2mml].
|
100
|
+
|
101
|
+
* `-m ritex`
|
102
|
+
* `-m blahtex`
|
103
|
+
|
104
|
+
* `-mi blahtex`
|
105
|
+
|
106
|
+
|
107
|
+
[itex2mml]: http://golem.ph.utexas.edu/~distler/code/itexToMML/
|
108
|
+
|
109
|
+
### With embedded Maruku
|
110
|
+
|
111
|
+
First, you have to enable the math extension.
|
112
|
+
|
113
|
+
require 'maruku' # loads maruku
|
114
|
+
require 'maruku/ext/math' # loads the math extension
|
115
|
+
|
116
|
+
|
117
|
+
### MathML output
|
118
|
+
|
119
|
+
...
|
120
|
+
|
121
|
+
### PNG output ###
|
122
|
+
|
123
|
+
Other parameters of interests are:
|
124
|
+
|
125
|
+
* `Globals[:math_png_dir]`
|
126
|
+
* `Globals[:math_png_dir_url]`
|
127
|
+
|
128
|
+
|
129
|
+
Advanced topics
|
130
|
+
---------------
|
131
|
+
|
132
|
+
### Styling equations ####
|
133
|
+
|
134
|
+
...
|
135
|
+
|
136
|
+
### Aligning PNGs ####
|
137
|
+
|
138
|
+
...
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
data/docs/proposal.html
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
-
<?xml version=
|
2
|
-
<!DOCTYPE html PUBLIC
|
3
|
-
|
4
|
-
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC
|
3
|
+
"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
|
4
|
+
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
|
5
|
+
<html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
|
6
|
+
<head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title>Proposal for adding a meta-data syntax to Markdown</title><link href='style.css' rel='stylesheet' type='text/css' />
|
7
|
+
</head>
|
8
|
+
<body>
|
5
9
|
<h1 id='proposal_for_adding_a_metadata_syntax_to_markdown'>Proposal for adding a meta-data syntax to Markdown</h1>
|
6
10
|
|
7
|
-
<p>This document describes a syntax for attaching meta-data to block-level elements (headers, paragraphs, code blocks
|
11
|
+
<p>This document describes a syntax for attaching meta-data to block-level elements (headers, paragraphs, code blocks,…), and to span-level elements (links, images,…).</p>
|
8
12
|
|
9
13
|
<p><strong><em>Note: this is an evolving proposal</em></strong></p>
|
10
14
|
|
@@ -25,7 +29,7 @@
|
|
25
29
|
<p>instead of:</p>
|
26
30
|
<pre><code>{ref_id}: key=val .class #id
|
27
31
|
</code></pre>
|
28
|
-
<p>Converters that don
|
32
|
+
<p>Converters that don’t use this syntax may just ignore everything which is in curly braces and starts with ”:”.</p>
|
29
33
|
</li>
|
30
34
|
|
31
35
|
<li>
|
@@ -109,7 +113,7 @@ second line of paragraph
|
|
109
113
|
</li>
|
110
114
|
|
111
115
|
<li>
|
112
|
-
<p><code>.myclass</code> means
|
116
|
+
<p><code>.myclass</code> means “add <code>myclass</code> to the current <code>class</code> attribute”.</p>
|
113
117
|
|
114
118
|
<p>So these are equivalent:</p>
|
115
119
|
<pre><code>{: .class1 .class2}
|
@@ -143,13 +147,13 @@ Line 2 of the paragraph.
|
|
143
147
|
</code></pre>
|
144
148
|
<p>Attribute lists may be indented up to 3 spaces:</p>
|
145
149
|
<pre><code>Paragraph1
|
146
|
-
|
150
|
+
¬{:ok}
|
147
151
|
|
148
152
|
Paragraph2
|
149
|
-
|
153
|
+
¬¬{:ok}
|
150
154
|
|
151
155
|
Paragraph2
|
152
|
-
|
156
|
+
¬¬¬{:ok}</code></pre>
|
153
157
|
<h3 id='for_headers'><span class='maruku_section_number'>3.2. </span>For headers</h3>
|
154
158
|
|
155
159
|
<p>For headers, you can put attribute lists on the same line:</p>
|
@@ -266,7 +270,7 @@ Blah blah blah.
|
|
266
270
|
|
267
271
|
<p>Also, you <strong>must</strong> escape a closing curly brace <code>}</code> inside quoted values. This rule is for making life easier for interpreter that just want to skip the meta-data.</p>
|
268
272
|
|
269
|
-
<p>If you don
|
273
|
+
<p>If you don’t implement this syntax, you can get rid of the IAL by using this regular expression (this is written in Ruby):</p>
|
270
274
|
<pre><code>r = /\{:(\\\}|[^\}])*\}/
|
271
275
|
|
272
276
|
s.gsub(r, '') # ignore metadata</code></pre>
|
@@ -283,4 +287,4 @@ for me
|
|
283
287
|
<pre><code>this is
|
284
288
|
|
285
289
|
|
286
|
-
for me </code></pre><div class='maruku_signature'><hr /><span style='font-size: small; font-style: italic'>Created by <a href='http://maruku.rubyforge.org' title='Maruku: a Markdown interpreter for Ruby'>Maruku</a> at
|
290
|
+
for me </code></pre><div class='maruku_signature'><hr /><span style='font-size: small; font-style: italic'>Created by <a href='http://maruku.rubyforge.org' title='Maruku: a Markdown-superset interpreter for Ruby'>Maruku</a> at 14:11 on Tuesday, January 23rd, 2007.</span></div></body></html>
|
data/lib/maruku.rb
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
19
|
#++
|
20
20
|
|
21
|
+
require 'rexml/document'
|
22
|
+
|
21
23
|
# :include:MaRuKu.txt
|
22
24
|
module MaRuKu
|
23
25
|
|
@@ -44,11 +46,9 @@ module MaRuKu
|
|
44
46
|
module Helpers; end
|
45
47
|
|
46
48
|
module Errors; end
|
47
|
-
|
48
|
-
module Defaults; end
|
49
49
|
|
50
50
|
class MDElement
|
51
|
-
include
|
51
|
+
include REXML
|
52
52
|
include MaRuKu
|
53
53
|
include Out::Markdown
|
54
54
|
include Out::HTML
|
@@ -60,6 +60,7 @@ module MaRuKu
|
|
60
60
|
|
61
61
|
|
62
62
|
class MDDocument < MDElement
|
63
|
+
include In::Markdown
|
63
64
|
include In::Markdown::SpanLevelParser
|
64
65
|
include In::Markdown::BlockLevelParser
|
65
66
|
end
|
@@ -99,6 +100,8 @@ require 'maruku/input/charsource'
|
|
99
100
|
require 'maruku/input/parse_span_better'
|
100
101
|
require 'maruku/input/rubypants'
|
101
102
|
|
103
|
+
require 'maruku/input/extensions'
|
104
|
+
|
102
105
|
require 'maruku/attributes'
|
103
106
|
|
104
107
|
require 'maruku/structures_iterators'
|
data/lib/maruku/attributes.rb
CHANGED
@@ -45,8 +45,11 @@ module MaRuKu;
|
|
45
45
|
push [key, val]
|
46
46
|
end
|
47
47
|
def push_ref(ref_id);
|
48
|
+
|
48
49
|
raise "Bad :ref #{ref_id.inspect}" if not ref_id
|
49
|
-
push [:ref, ref_id]
|
50
|
+
push [:ref, ref_id+""]
|
51
|
+
|
52
|
+
# p "Now ", self ########################################
|
50
53
|
end
|
51
54
|
def push_class(val);
|
52
55
|
raise "Bad :id #{val.inspect}" if not val
|
@@ -81,6 +84,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
|
81
84
|
[ "a =b", :throw, "No whitespace before `=`." ],
|
82
85
|
[ "a= b", :throw, "No whitespace after `=`." ],
|
83
86
|
|
87
|
+
[ "a b", [[:ref, 'a'],[:ref, 'b']], "More than one ref" ],
|
84
88
|
[ "a b c", [[:ref, 'a'],[:ref, 'b'],[:ref, 'c']], "More than one ref" ],
|
85
89
|
[ "hello notfound", [[:ref, 'hello'],[:ref, 'notfound']]],
|
86
90
|
|
@@ -129,6 +133,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
|
129
133
|
|
130
134
|
# returns nil or an AttributeList
|
131
135
|
def read_attribute_list(src, con, break_on_chars)
|
136
|
+
|
132
137
|
separators = break_on_chars + [?=,?\ ,?\t]
|
133
138
|
escaped = Maruku::EscapedCharInQuotes
|
134
139
|
|
@@ -210,7 +215,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
|
|
210
215
|
end
|
211
216
|
|
212
217
|
if not Globals[:debug_keep_ials]
|
213
|
-
elements.delete_if {|x| is_ial(x)}
|
218
|
+
elements.delete_if {|x| is_ial(x) unless x == elements.first}
|
214
219
|
end
|
215
220
|
end
|
216
221
|
|
data/lib/maruku/defaults.rb
CHANGED
@@ -23,40 +23,40 @@ module MaRuKu
|
|
23
23
|
|
24
24
|
Globals = {
|
25
25
|
:unsafe_features => false,
|
26
|
+
:on_error => :warning,
|
26
27
|
|
27
|
-
:debug_keep_ials => false,
|
28
28
|
|
29
|
-
:
|
30
|
-
}
|
29
|
+
:use_numbered_headers => false,
|
31
30
|
|
32
|
-
|
33
|
-
|
31
|
+
:maruku_signature => true,
|
32
|
+
:code_background_color => '#fef',
|
33
|
+
:code_show_spaces => false,
|
34
|
+
:html_math_engine => 'none', #ritex, itex2mml
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
50
|
-
|
36
|
+
:html_png_engine => 'none',
|
37
|
+
:html_png_dir => 'pngs',
|
38
|
+
:html_png_url => 'pngs/',
|
39
|
+
:html_png_resolution => 200,
|
40
|
+
|
41
|
+
:html_use_syntax => false,
|
42
|
+
|
43
|
+
:latex_use_listings => false,
|
44
|
+
:latex_cjk => false,
|
45
|
+
|
46
|
+
:debug_keep_ials => false,
|
47
|
+
|
48
|
+
}
|
51
49
|
|
52
50
|
class MDElement
|
53
|
-
def
|
54
|
-
if self.
|
55
|
-
return
|
56
|
-
elsif
|
57
|
-
return
|
51
|
+
def get_setting(sym)
|
52
|
+
if self.attributes.has_key?(sym) then
|
53
|
+
return self.attributes[sym]
|
54
|
+
elsif self.doc && self.doc.attributes.has_key?(sym) then
|
55
|
+
return self.doc.attributes[sym]
|
56
|
+
elsif MaRuKu::Globals.has_key?(sym)
|
57
|
+
return MaRuKu::Globals[sym]
|
58
58
|
else
|
59
|
-
puts "Bug: no default for #{sym.inspect}"
|
59
|
+
$stderr.puts "Bug: no default for #{sym.inspect}"
|
60
60
|
nil
|
61
61
|
end
|
62
62
|
end
|
@@ -37,10 +37,9 @@ module MaRuKu
|
|
37
37
|
end
|
38
38
|
|
39
39
|
module Errors
|
40
|
-
Default_on_error = :warning
|
41
40
|
|
42
41
|
def maruku_error(s,src=nil,con=nil)
|
43
|
-
policy =
|
42
|
+
policy = get_setting(:on_error)
|
44
43
|
|
45
44
|
case policy
|
46
45
|
when :ignore
|
@@ -48,6 +47,8 @@ module Errors
|
|
48
47
|
raise_error create_frame(describe_error(s,src,con))
|
49
48
|
when :warning
|
50
49
|
tell_user create_frame(describe_error(s,src,con))
|
50
|
+
else
|
51
|
+
raise "BugBug: policy = #{policy.inspect}"
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
@@ -69,13 +70,13 @@ module Errors
|
|
69
70
|
def create_frame(s)
|
70
71
|
n = 75
|
71
72
|
"\n" +
|
72
|
-
" "+"_"*n
|
73
|
-
"| Maruku tells you:\n"
|
74
|
-
"+"+"-"*n +"\n"+
|
75
|
-
add_tabs(s,1,'| ')
|
76
|
-
"+"
|
77
|
-
add_tabs(caller[0, 5].join("\n"),1,'!')
|
78
|
-
"\\"
|
73
|
+
" "+"_"*n + "\n"+
|
74
|
+
"| Maruku tells you:\n" +
|
75
|
+
"+" + ("-"*n) +"\n"+
|
76
|
+
add_tabs(s,1,'| ') + "\n" +
|
77
|
+
"+" + ("-"*n) + "\n" +
|
78
|
+
add_tabs(caller[0, 5].join("\n"),1,'!') + "\n" +
|
79
|
+
"\\" + ("_"*n) + "\n"
|
79
80
|
end
|
80
81
|
|
81
82
|
def describe_error(s,src,con)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Diagrams
|
2
|
+
|
3
|
+
class Grid
|
4
|
+
attr_accessor :width, :height
|
5
|
+
|
6
|
+
def initialize(width, height, init)
|
7
|
+
@width, @height = width, height
|
8
|
+
@data = Array.new
|
9
|
+
height.times do @data.push [init]*@width end
|
10
|
+
@init = init
|
11
|
+
end
|
12
|
+
|
13
|
+
def get(x, y)
|
14
|
+
@data[y][x]
|
15
|
+
end
|
16
|
+
|
17
|
+
def set(x, y, v)
|
18
|
+
@data[y][x] = v || @init
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
@data.map{|x|
|
23
|
+
x.map{|y|
|
24
|
+
case y
|
25
|
+
when true; '#'
|
26
|
+
when false, nil; ' '
|
27
|
+
when Fixnum; y.chr
|
28
|
+
end
|
29
|
+
}.join
|
30
|
+
}.join("\n")
|
31
|
+
end
|
32
|
+
|
33
|
+
def inspect2(valid)
|
34
|
+
s = ""
|
35
|
+
|
36
|
+
s += "+" + "-"*@width + "+\n"
|
37
|
+
for y in 0..(@height-1)
|
38
|
+
s += "|"
|
39
|
+
for x in 0..(@width-1)
|
40
|
+
s += valid.get(x,y) ? get(x,y).chr : " "
|
41
|
+
end
|
42
|
+
s += "|"
|
43
|
+
s += "\n"
|
44
|
+
end
|
45
|
+
s += "+" + "-"*@width + "+\n"
|
46
|
+
s
|
47
|
+
end
|
48
|
+
|
49
|
+
def each
|
50
|
+
for y in 0..(height-1)
|
51
|
+
for x in 0..(width-1)
|
52
|
+
e = get(x,y)
|
53
|
+
yield x,y,e
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_area(x,y,w,h,e)
|
59
|
+
for i in (x..x+w-1)
|
60
|
+
for j in (y..y+h-1)
|
61
|
+
set(i,j,e)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def read_area(x,y,w,h)
|
67
|
+
s = ""
|
68
|
+
for j in (y..y+h-1)
|
69
|
+
for i in (x..x+w-1)
|
70
|
+
s << get(i,j)
|
71
|
+
end
|
72
|
+
s << "\n"
|
73
|
+
end
|
74
|
+
s
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|