mdextab 0.1.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.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mdextab.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 yasuo kominami
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ mainly extend table tag of HTML5 of Makrdown on Pandoc
2
+
3
+ # Mdextab
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mdextab`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'mdextab'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install mdextab
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ykominami/mdextab.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mdextab"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/makemdtab ADDED
@@ -0,0 +1,304 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'bundler/setup'
5
+ require 'mdextab'
6
+ require 'digest'
7
+
8
+ require 'simpleoptparse'
9
+ require 'byebug'
10
+
11
+ EXIT_CODE_NORMAL_EXIT=0
12
+ EXIT_CODE_CANNOT_FILE_FILE=101
13
+ EXIT_CODE_CANNOT_WRITE_FILE=102
14
+ EXIT_CODE_ARGV_SIZE=103
15
+ EXIT_CODE_MISSING_REQUIRED_ARGUMENT=104
16
+ EXIT_CODE_CANNOTFIND_YAMLFILE_OR_EMPTY=105
17
+ EXIT_CODE_YAMLFILE_IS_EMPTY=106
18
+ EXIT_CODE_CANNOTFIND_ERUBYFILE_OR_EMPTY=107
19
+ EXIT_CODE_ERUBYFILE_IS_EMPTY=108
20
+ EXIT_CODE_CANNOTFIND_MDFILE_OR_EMPTY=109
21
+ EXIT_CODE_MDFILE_IS_EMPTY=110
22
+
23
+ class Makemdtab
24
+ def initialize(opts, erubyfnames)
25
+ @dataop=opts["dataop"]
26
+ @datayamlfname=opts["data"]
27
+ @yamlop=opts["yamlop"]
28
+ @yamlfname=opts["setting"]
29
+ @auxyamlfname=opts["auxsetting"]
30
+ @erubyfnames=erubyfnames
31
+ @outputfname=opts["output"]
32
+
33
+ @exit_cannot_find_file=1
34
+ @exit_cannot_write_file=2
35
+
36
+ @erubies = {}
37
+
38
+ @logger=Logger.new(STDOUT)
39
+ @logger.level = Logger::INFO
40
+ @logger.level = Logger::DEBUG if opts["debug"]
41
+ @logger.formatter = proc do |severity, datetime, progname, msg|
42
+ "#{msg}\n"
43
+ end
44
+
45
+ [@datayamlfname, @yamlfname, @auxyamlfname, @erubyfnames].flatten.each do |fname|
46
+ next if File.exist?(fname)
47
+
48
+ mes="Can't find #{fname}"
49
+ outputError(mes)
50
+ exit(EXIT_CODE_CANNOT_FILE_FILE)
51
+ end
52
+
53
+ begin
54
+ @output = File.open(@outputfname, 'w')
55
+ rescue RuntimeError => ex
56
+ mes2 = "Can't write #{@outputfname}"
57
+ outputError(mes2)
58
+ exit(EXIT_CODE_CANNOT_WRITE_FILE)
59
+ end
60
+ end
61
+
62
+ def outputError(mes)
63
+ if @logger
64
+ @logger.error(mes)
65
+ else
66
+ STDERR.puts(mes)
67
+ end
68
+ end
69
+
70
+ def makeMd()
71
+ load(@dataop, @datayamlfname, @yamlop, @auxyamlfname, @yamlfname, @erubyfnames).map{|x|
72
+ @output.puts(x)
73
+ }
74
+ end
75
+
76
+ def load(dataop, datayamlfname, yamlop, auxyamlfname, yamlfname, erubyfnames)
77
+ eruby0 = nil
78
+ eruby1 = nil
79
+ obj = {}
80
+ obj0 = YAML.load_file(auxyamlfname) if auxyamlfname
81
+ obj = obj0 if obj0
82
+
83
+ case yamlop
84
+ when :MERGE
85
+ obj2 = YAML.load_file(yamlfname)
86
+ if obj2
87
+ if obj
88
+ objx = obj.merge(obj2)
89
+ else
90
+ objx = obj2
91
+ end
92
+ else
93
+ objx = obj
94
+ end
95
+ when :REPLACE
96
+ str = File.read(yamlfname)
97
+ str2 = Erubis::Eruby.new(str).result(obj)
98
+ objx0 = YAML.load(str2)
99
+ if objx0
100
+ objx = objx
101
+ else
102
+ objx = {}
103
+ end
104
+ else
105
+ # do nothing
106
+ end
107
+
108
+ erubystr=erubyfnames.map{|x| checkAndLoadErubyfile(x)}.join("\n")
109
+ if @dataop == :PATTERN_FOUR
110
+ mdfname=datayamlfname
111
+ objx["PARENT_DIR"] = ENV['MDEXTAB_MAKE']
112
+
113
+ mdstr=checkAndLoadMdfile(mdfname)
114
+
115
+ dx = [erubystr, mdstr].join("\n")
116
+ @erubies[mdfname] ||= Erubis::Eruby.new(dx)
117
+ array=[@erubies[mdfname].result(objx)]
118
+ else
119
+ puts "datayamlfname=#{datayamlfname}"
120
+ strdata2=checkAndExpandYamlfile(datayamlfname, objx)
121
+ data = YAML.load(strdata2)
122
+ if data.class != Hash
123
+ puts "strdata2=#{strdata2}"
124
+ p data
125
+ exit(300)
126
+ end
127
+ erubyfname=erubyfnames.last
128
+ case dataop
129
+ when :PATTERN_ONE
130
+ array=loadWithPattern1(data, erubyfname, erubystr)
131
+ when :PATTERN_TWO
132
+ array=loadWithPattern2(data, erubyfname, erubystr)
133
+ when :PATTERN_THREE
134
+ dir=File.dirname(datayamlfname)
135
+ array=loadWithPattern3(data, erubyfname, erubystr, dir)
136
+ else
137
+ array=[]
138
+ # do nothing
139
+ end
140
+ end
141
+ array
142
+ end
143
+
144
+ def checkAndLoadErubyfile(erubyfname)
145
+ size=File.size?(erubyfname)
146
+ if size and size > 0
147
+ erubystr=File.read(erubyfname)
148
+ else
149
+ mes=%Q!Can not find #{erubyfname} or is empty!
150
+ outputError(mes)
151
+ exit(EXIT_CODE_CANNOTFIND_ERUBYFILE_OR_EMPTY)
152
+ end
153
+ if erubystr.strip.empty?
154
+ mes=%Q!#{erubyfname} is empty!
155
+ outputError(mes)
156
+ exit(EXIT_CODE_ERUBYFILE_IS_EMPTY)
157
+ end
158
+ erubystr
159
+ end
160
+
161
+ def checkAndLoadMdfile(mdfname)
162
+ size2=File.size?(mdfname)
163
+ if size2 and size2 > 0
164
+ mdstr=File.read(mdfname)
165
+ else
166
+ mes=%Q!Can not find #{mdfname} or is empty!
167
+ outputError(mes)
168
+ exit(EXIT_CODE_CANNOTFIND_MDFILE_OR_EMPTY)
169
+ end
170
+ if mdstr.strip.empty?
171
+ mes=%Q!#{mdfname} is empty!
172
+ outputError(mes)
173
+ exit(EXIT_CODE_MDFILE_IS_EMPTY)
174
+ end
175
+ mdstr
176
+ end
177
+
178
+ def checkAndExpandYamlfile(yamlfname, objx)
179
+ size=File.size?(yamlfname)
180
+ if size and size > 0
181
+ puts File.mtime(yamlfname)
182
+ strdata = File.read(yamlfname)
183
+ else
184
+ mes=%Q!Can not find #{yamlfname} or is empty!
185
+ outputError(mes)
186
+ exit(EXIT_CODE_CANNOTFIND_YAMLFILE_OR_EMPTY)
187
+ end
188
+
189
+ if strdata.strip.empty?
190
+ mes=%Q!#{yamlfname} is empty!
191
+ outputError(mes)
192
+ exit(EXIT_CODE_YAMLFILE_IS_EMPTY)
193
+ else
194
+ puts Digest::MD5.hexdigest(strdata)
195
+ #
196
+ strdata2 = Erubis::Eruby.new(strdata).result(objx)
197
+ end
198
+
199
+ strdata2
200
+ end
201
+
202
+ def loadWithPattern1(data, erubyfname, erubystr)
203
+ @erubies[erubyfname] ||= Erubis::Eruby.new(erubystr)
204
+ [@erubies[erubyfname].result(data)]
205
+ end
206
+
207
+ def loadWithPattern2(data, erubyfname, erubystr)
208
+ data.map{ |x|
209
+ @erubies[erubyfname] ||= Erubis::Eruby.new(erubystr)
210
+ @erubies[erubyfname].result(x)
211
+ }
212
+ end
213
+
214
+ def loadWithPattern3(data, erubyfname, erubystr, dir)
215
+ hs={}
216
+ data.each do |k,v|
217
+ if /items/.match(k)
218
+ hs[k]=[]
219
+ v.each do |v2|
220
+ if /^path=(.*)/.match(v2)
221
+ hs[k] << File.join(dir, $1)
222
+ else
223
+ hs[k] << v2
224
+ end
225
+ end
226
+ else
227
+ hs[k]=v
228
+ end
229
+ end
230
+ @erubies[erubyfname] ||= Erubis::Eruby.new(erubystr)
231
+ [@erubies[erubyfname].result(hs)]
232
+ end
233
+
234
+ def postProcess
235
+ @output.close if @output
236
+ @output = nil
237
+ end
238
+ end
239
+
240
+ opts = {}
241
+ banner = "Usage: bundle exec ruby bin/makemdtab [--contest] [--debug] -o outfname -d datafname --y merge|replace -p pattern_one|pattern_two|pattern_three -s yamlfname [-a auxyamlfname] erubyfname [erubyfname2 *]"
242
+ if ARGV.size == 0
243
+ puts(banner)
244
+ exit(EXIT_CODE_ARGV_SIZE)
245
+ end
246
+
247
+ Simpleoptparse::Simpleoptparse.parse(ARGV , opts , banner , Mdextab::VERSION , nil){ |parser|
248
+ parser.on('--debug' ) {|x| opts["debug"] = true}
249
+ parser.on('--contest' ) {|x| opts["kind"] = :contest}
250
+ parser.on('-d value', '--data' ,'data file') {|x| opts["data"] = x}
251
+ parser.on('-s value', '--setting') {|x| opts["setting"] = x}
252
+ parser.on('-a [value]', '--auxsetting') {|x| opts["auxsetting"] = x}
253
+ parser.on('-o value', '--output') {|x| opts["output"] = x}
254
+ parser.on('-y value', '--yamlop') {|x|
255
+ case x.upcase
256
+ when /^MERGE/
257
+ opts["yamlop"] = :MERGE
258
+ when /^REPLACE/
259
+ opts["yamlop"] = :REPLACE
260
+ else
261
+ # do nothing
262
+ end
263
+ }
264
+ parser.on('-p value', '--dataop') {|x|
265
+ case x.upcase
266
+ when /^PATTERN_ONE/
267
+ opts["dataop"] = :PATTERN_ONE
268
+ when /^PATTERN_TWO/
269
+ opts["dataop"] = :PATTERN_TWO
270
+ when /^PATTERN_THREE/
271
+ opts["dataop"] = :PATTERN_THREE
272
+ when /^PATTERN_FOUR/
273
+ opts["dataop"] = :PATTERN_FOUR
274
+ else
275
+ # do nothing
276
+ end
277
+ }
278
+ }
279
+
280
+ unless opts["output"] and opts["yamlop"] and opts["dataop"]
281
+ puts(banner)
282
+ puts "don't be specified -d output" unless opts["output"]
283
+ puts "don't be specified -y value" unless opts["yamlop"]
284
+ puts "don't be specified -p value" unless opts["dataop"]
285
+ p ARGV
286
+ p opts
287
+ exit(EXIT_CODE_MISSING_REQUIRED_ARGUMENT)
288
+ end
289
+
290
+ puts "# makemdtab Start #"
291
+ puts "|||||||||||| opts['output']=#{opts['output']}"
292
+ puts "|||||||||||| ARGV=#{ARGV}"
293
+ opts.each do |k,v|
294
+ puts "|||||||||||| opts[#{k}]=#{v}"
295
+ end
296
+
297
+ x=Makemdtab.new(opts, ARGV)
298
+ x.makeMd()
299
+ x.postProcess
300
+ puts "# makemdtab End #"
301
+ exit(EXIT_CODE_NORMAL_EXIT)
302
+
303
+
304
+
data/bin/mdextab ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mdextab'
5
+
6
+ require 'simpleoptparse'
7
+
8
+ opts = { }
9
+ banner = "Usage: bundle exec ruby bin/mdextab in_md_fname out_md_fname settng_yaml auxiliary_setting_yaml"
10
+
11
+ Simpleoptparse::Simpleoptparse.parse(ARGV , opts , banner , Mdextab::VERSION , nil){|parser|
12
+ parser.on('-d', '--debug' ) {|x| opts["debug"] = true }
13
+ }
14
+
15
+ fname = ARGV[0]
16
+ oFname = ARGV[1]
17
+ yamlFname = ARGV[2]
18
+ auxiliaryYamlFname = ARGV[3]
19
+ m = Mdextab::Mdextab.new(opts,fname,oFname,yamlFname,auxiliaryYamlFname)
20
+ m.parse
21
+ m.end
22
+
23
+ puts "##### Mdextab fname=#{fname}"
24
+ puts "##### Mdextab oFname=#{oFname}"
25
+ puts "##### Mdextab yamlFname=#{yamlFname}"
26
+ puts "##### Mdextab auxiliaryYamlFname=#{auxiliaryYamlFname}"
27
+
28
+ exit(0)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/mdextab ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mdextab"
@@ -0,0 +1,58 @@
1
+ require 'logger'
2
+
3
+ module Mdextab
4
+ class Loggerx
5
+ def initialize(fname)
6
+ @loggerSTDOUT = Logger.new(STDOUT)
7
+ @loggerSTDOUT.level = Logger::UNKNOWN
8
+ @loggerSTDOUT.formatter = proc do |severity, datetime, progname, msg|
9
+ "#{severity[0]}: #{msg}\n"
10
+ # "#{msg}\n"
11
+ end
12
+ file = File.open( fname , 'w')
13
+ @loggerFILE = Logger.new(file)
14
+ @loggerFILE.level = Logger::INFO
15
+ @loggerFILE.formatter = proc do |severity, datetime, progname, msg|
16
+ "#{severity}: #{msg}\n"
17
+ # "#{msg}\n"
18
+ end
19
+ end
20
+
21
+ def datetime_format=(format)
22
+ @loggerSTDOUT.datetime_format=format
23
+ @loggerFILE.datetime_format=format
24
+ end
25
+
26
+ def level=(value)
27
+ puts value
28
+ @loggerSTDOUT.level=value
29
+ @loggerFILE.level=value
30
+ end
31
+
32
+ def set_level(value)
33
+ puts value
34
+ @loggerSTDOUT.level=value
35
+ @loggerFILE.level=value
36
+ end
37
+
38
+ def debug(mes)
39
+ @loggerSTDOUT.debug(mes)
40
+ @loggerFILE.debug(mes)
41
+ end
42
+
43
+ def error(mes)
44
+ @loggerSTDOUT.error(mes)
45
+ @loggerFILE.error(mes)
46
+ end
47
+
48
+ def fatal(mes)
49
+ @loggerSTDOUT.fatal(mes)
50
+ @loggerFILE.fatal(mes)
51
+ end
52
+
53
+ def info(mes)
54
+ @loggerSTDOUT.info(mes)
55
+ @loggerFILE.info(mes)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,51 @@
1
+ require 'forwardable'
2
+
3
+ module Mdextab
4
+ class Table
5
+ extend Forwardable
6
+ def_delegators :@tbody, :add_th, :add_td, :tdAppend, :thAppend, :add
7
+ attr_reader :lineno, :tbody
8
+
9
+ def initialize(lineno, logger,attr=nil)
10
+ @lineno = lineno
11
+ @attr = attr
12
+ @tbody = nil
13
+ @logger = logger
14
+ end
15
+
16
+ def add_tbody(lineno)
17
+ @tbody = Tbody.new(lineno, @logger)
18
+ end
19
+
20
+ def tbody_end
21
+ @tbody.end
22
+ end
23
+
24
+ def end
25
+ table_end
26
+ end
27
+
28
+ def table_end
29
+ to_s
30
+ end
31
+
32
+ def to_s(debug=false)
33
+ if @attr
34
+ if debug
35
+ str_1 = %Q!<table #{@attr} lineno:#{@lineno}>!
36
+ else
37
+ str_1 = %Q!<table #{@attr}>!
38
+ end
39
+ else
40
+ if debug
41
+ str_1 = %Q!<table lineno:#{@lineno}>!
42
+ else
43
+ str_1 = %Q!<table>!
44
+ end
45
+ end
46
+
47
+ [str_1, @tbody.to_s, "</table>"].join("\n")
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,55 @@
1
+ module Mdextab
2
+ class Tbody
3
+ attr_reader :lineno
4
+
5
+ def initialize(lineno, logger)
6
+ @array = []
7
+ @tr = nil
8
+ @th = nil
9
+ @td = nil
10
+ @lineno = lineno
11
+ @logger = logger
12
+ end
13
+
14
+ def add_th(lineno, content, nth, attr=nil, condense)
15
+ if nth == 1
16
+ @tr = Tr.new(lineno)
17
+ @array << @tr
18
+ end
19
+ @th = Th.new(lineno, attr)
20
+ @th.add(content, condense)
21
+ @tr.add(@th)
22
+ end
23
+
24
+ def add_td(lineno, content, nth, attr=nil, condense)
25
+ @logger.debug( "content=#{content}|nth=#{nth}|attr=#{attr}" )
26
+ if nth == 1
27
+ @tr = Tr.new(lineno)
28
+ @array << @tr
29
+ end
30
+ @td = Td.new(lineno,attr)
31
+ @td.add(content, condense)
32
+ @tr.add(@td)
33
+ end
34
+
35
+ def tdAppend(content, condense)
36
+ @td.add(content, condense)
37
+ end
38
+
39
+ def thAppend(content, condense)
40
+ @th.add(content, condense)
41
+ end
42
+
43
+ def add(cont)
44
+ @array << cont
45
+ end
46
+
47
+ def end
48
+ @tr = nil
49
+ end
50
+
51
+ def to_s
52
+ ["<tbody>" , @array.map{|x| x.to_s} , "</tbody>"].join("\n")
53
+ end
54
+ end
55
+ end
data/lib/mdextab/td.rb ADDED
@@ -0,0 +1,31 @@
1
+ class Td
2
+ def initialize(lineno, attr=nil)
3
+ @lineno = lineno
4
+ @attr = attr
5
+ @content = ""
6
+ end
7
+
8
+ def add(content, condnese)
9
+ if condnese
10
+ if @content
11
+ if @contnet.match?(/^\s*$/)
12
+ @content=content.to_s
13
+ else
14
+ @content+=content.to_s
15
+ end
16
+ else
17
+ @content=content.to_s
18
+ end
19
+ else
20
+ @content = [@content, content].join("\n") if content
21
+ end
22
+ end
23
+
24
+ def to_s
25
+ if @attr != nil
26
+ %Q!<td #{@attr}>#{@content}</td>!
27
+ else
28
+ %Q!<td>#{@content}</td>!
29
+ end
30
+ end
31
+ end
data/lib/mdextab/th.rb ADDED
@@ -0,0 +1,33 @@
1
+ module Mdextab
2
+ class Th
3
+ def initialize(lineno, attr=nil)
4
+ @lineno = lineno
5
+ @attr = attr
6
+ @content = ""
7
+ end
8
+
9
+ def add(content, condense)
10
+ if condense
11
+ if @content
12
+ if @content.match?(/^\s*$/)
13
+ @content = content.to_s
14
+ else
15
+ @content+=content.to_s
16
+ end
17
+ else
18
+ @content=content.to_s
19
+ end
20
+ else
21
+ @content = [@content , content].join("\n") if content
22
+ end
23
+ end
24
+
25
+ def to_s
26
+ if @attr != nil
27
+ %Q!<th #{@attr}>#{@content}</th>!
28
+ else
29
+ %Q!<th>#{@content}</th>!
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ module Mdextab
2
+ class Token
3
+ attr_reader :kind, :opt
4
+
5
+ def initialize(kind , opt={})
6
+ @kind = kind
7
+ @opt = opt
8
+ end
9
+ end
10
+ end
11
+
data/lib/mdextab/tr.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Mdextab
2
+ class Tr
3
+ def initialize(lineno)
4
+ @lineno = lineno
5
+ @array = []
6
+ end
7
+
8
+ def add(cont)
9
+ @array << cont
10
+ end
11
+
12
+ def to_s
13
+ ["<tr>", @array.map{|x| x.to_s} , "</tr>"].join("\n")
14
+ end
15
+ end
16
+ end