AoBane 0.0.1
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/.gitignore +17 -0
- data/AoBane.gemspec +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +1 -0
- data/bin/AoBane +6 -0
- data/lib/AoBane/cui.rb +242 -0
- data/lib/AoBane/version.rb +3 -0
- data/lib/AoBane.rb +2191 -0
- data/test/Test.html +12 -0
- data/test/Test.md +2 -0
- metadata +94 -0
data/.gitignore
ADDED
data/AoBane.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'AoBane/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "AoBane"
|
8
|
+
spec.version = AoBane::VERSION
|
9
|
+
spec.authors = ["set"]
|
10
|
+
spec.email = ["set.minami@gmail.com"]
|
11
|
+
spec.description = %q{AoBane The Markdown engine powered by BlueFeather}
|
12
|
+
spec.summary = %q{You can write colored font without css and special characters with simple way.}
|
13
|
+
spec.homepage = "https://github.com/setminami/AoBane"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Set
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
AoBane The MarkDown Core Engine
|
2
|
+
======
|
3
|
+
|
4
|
+
Powered By BlueFeather
|
5
|
+
|
6
|
+
##What's This and What You Can...
|
7
|
+
This codes are extended from BlueFeather.<br>
|
8
|
+
The points of difference are
|
9
|
+
* You can use font TAG like this-> `*[blablabla](color|font faces#font size)`
|
10
|
+
* *e.g.,* `*[blablabla](red|Times,Arial#5) -expand-> <font color="red" face="Times,Arial" size="5">blablabla</font>`
|
11
|
+
- And I know that font TAG was duplicated in HTML5...
|
12
|
+
* You can use HTML special character by simple way.
|
13
|
+
|
14
|
+
like this
|
15
|
+
> -- —
|
16
|
+
|
17
|
+
> <=> ⇔
|
18
|
+
|
19
|
+
> => ⇒
|
20
|
+
|
21
|
+
> <= ⇐
|
22
|
+
|
23
|
+
> ||^ ⇑
|
24
|
+
|
25
|
+
> ||/ ⇓
|
26
|
+
|
27
|
+
> <-> ↔
|
28
|
+
|
29
|
+
> -> →
|
30
|
+
|
31
|
+
> <- ←
|
32
|
+
|
33
|
+
> |^ ↑
|
34
|
+
|
35
|
+
> |/ ↓
|
36
|
+
|
37
|
+
> `>> »`
|
38
|
+
|
39
|
+
> `<< «`
|
40
|
+
|
41
|
+
> +_ ±
|
42
|
+
|
43
|
+
> != ≠
|
44
|
+
|
45
|
+
> ~~ ≈
|
46
|
+
|
47
|
+
> ~= ≅
|
48
|
+
|
49
|
+
> <_ ≤
|
50
|
+
|
51
|
+
> `>_` ≥
|
52
|
+
|
53
|
+
> |FA ∀
|
54
|
+
|
55
|
+
> |EX ∃
|
56
|
+
|
57
|
+
> (+) ⊕
|
58
|
+
|
59
|
+
> (x) ⊗
|
60
|
+
|
61
|
+
> `\&` &
|
62
|
+
|
63
|
+
> (c) ©
|
64
|
+
|
65
|
+
> (R) ®
|
66
|
+
|
67
|
+
> (SS) §
|
68
|
+
|
69
|
+
> (TM) ™
|
70
|
+
|
71
|
+
##How to Install
|
72
|
+
Under costructing...wait a minutes
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/AoBane
ADDED
data/lib/AoBane/cui.rb
ADDED
@@ -0,0 +1,242 @@
|
|
1
|
+
#! ruby
|
2
|
+
# AoBane Command-line Interface
|
3
|
+
#
|
4
|
+
require 'optparse'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'stringio'
|
7
|
+
require 'pathname'
|
8
|
+
|
9
|
+
require 'AoBane'
|
10
|
+
|
11
|
+
module AoBane
|
12
|
+
class CUI
|
13
|
+
module FormatType
|
14
|
+
TEXT = 'text'
|
15
|
+
DOCUMENT = 'document'
|
16
|
+
end
|
17
|
+
|
18
|
+
include FormatType
|
19
|
+
|
20
|
+
FORMAT_TYPE_TABLE = {
|
21
|
+
'document' => DOCUMENT,
|
22
|
+
'bfdoc' => DOCUMENT,
|
23
|
+
'text' => TEXT,
|
24
|
+
'bftext' => TEXT,
|
25
|
+
}
|
26
|
+
|
27
|
+
HELP = <<-EOS
|
28
|
+
AoBane - Extended Markdown Converter
|
29
|
+
|
30
|
+
Usage: AoBane [options] file1 [file2 file3 ..]
|
31
|
+
|
32
|
+
Options:
|
33
|
+
-e, --encoding NAME parse input files as encoding of NAME.
|
34
|
+
(s[hift(_-)jis] / e[uc-jp] / u[tf-8] / a[scii]
|
35
|
+
default: 'utf-8')
|
36
|
+
-f, --format TYPE specify format.
|
37
|
+
(t[ext] => text mode
|
38
|
+
d[ocument] => document mode)
|
39
|
+
--force write even if target files have not changed.
|
40
|
+
(default: only if target files have changed)
|
41
|
+
-h, --help show this help.
|
42
|
+
-o, --output DIR output files to DIR. (default: same as input file)
|
43
|
+
-q, --quiet no output to stderr.
|
44
|
+
--suffix .SUF specify suffix of output files. (default: '.html')
|
45
|
+
-v, --verbose verbose mode - output detail of operation.
|
46
|
+
--version show AoBane version.
|
47
|
+
|
48
|
+
Advanced Usage:
|
49
|
+
* If specify files only '-', AoBane read from stdin and write to stdout.
|
50
|
+
|
51
|
+
|
52
|
+
Example:
|
53
|
+
AoBane *.bftext *.bfdoc
|
54
|
+
AoBane -v --sufix .xhtml -o ../ sample.markdown
|
55
|
+
AoBane -
|
56
|
+
|
57
|
+
More info:
|
58
|
+
see <https://github.com/setminami/AoBane/>
|
59
|
+
EOS
|
60
|
+
|
61
|
+
def self.run(*args)
|
62
|
+
self.new.run(*args)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
attr_reader :stdout, :stderr, :stdin
|
68
|
+
|
69
|
+
def initialize(stdout = $stdout, stderr = $stderr, stdin = $stdin)
|
70
|
+
@stdout, @stderr, @stdin = stdout, stderr, stdin
|
71
|
+
end
|
72
|
+
|
73
|
+
def run(argv)
|
74
|
+
op = OptionParser.new
|
75
|
+
|
76
|
+
verbose = false
|
77
|
+
quiet = false
|
78
|
+
force = false
|
79
|
+
suffix = '.html'
|
80
|
+
format = nil
|
81
|
+
output_dir_path = nil
|
82
|
+
encoding = EncodingType::UTF_8
|
83
|
+
|
84
|
+
|
85
|
+
message_out = @stderr
|
86
|
+
|
87
|
+
|
88
|
+
op.on('-e', '--encoding NAME') do |v|
|
89
|
+
case v.downcase
|
90
|
+
when /^sh?i?f?t?[-_]?j?i?s?$/
|
91
|
+
encoding = EncodingType::SHIFT_JIS
|
92
|
+
when /^eu?c?-?j?p?$/
|
93
|
+
encoding = EncodingType::EUC_JP
|
94
|
+
when /^ut?f?-?8?$/
|
95
|
+
encoding = EncodingType::UTF_8
|
96
|
+
when /^as?c?i?i?$/
|
97
|
+
encoding = EncodingType::ASCII
|
98
|
+
else
|
99
|
+
message_out.puts "ERROR: invalid encoding - #{v}"
|
100
|
+
message_out.puts "Expected: s[hift(-_)jis] / e[uc-jp] / u[tf-8] / a[scii]"
|
101
|
+
return false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
op.on('-f', '--format TYPE', FORMAT_TYPE_TABLE){|x| format = x}
|
105
|
+
op.on('--force'){|x| force = true}
|
106
|
+
op.on('-v', '--verbose'){ verbose = true }
|
107
|
+
op.on('-o', '--output DIR', String){|x| output_dir_path = Pathname.new(x)}
|
108
|
+
op.on('-q', '--quiet'){ message_out = StringIO.new }
|
109
|
+
op.on('--suffix .SUF', String){|x| suffix = x}
|
110
|
+
op.on('--version'){
|
111
|
+
@stdout.puts "AoBane #{VERSION_LABEL}"
|
112
|
+
return false
|
113
|
+
}
|
114
|
+
op.on('-h', '--help'){
|
115
|
+
@stdout.puts HELP
|
116
|
+
return false
|
117
|
+
}
|
118
|
+
|
119
|
+
args = op.parse(argv)
|
120
|
+
|
121
|
+
if args.empty? then
|
122
|
+
message_out.puts "ERROR: please text file paths, patterns, or '-' (stdin-mode).\nEx) AoBane *.bfdoc"
|
123
|
+
return false
|
124
|
+
end
|
125
|
+
|
126
|
+
message_out.puts "default encoding: #{encoding}" if verbose
|
127
|
+
|
128
|
+
unless defined?(Encoding) then
|
129
|
+
# ruby 1.8 or earlier
|
130
|
+
original_kcode = $KCODE
|
131
|
+
$KCODE = EncodingType.convert_to_kcode(encoding)
|
132
|
+
end
|
133
|
+
|
134
|
+
begin
|
135
|
+
if args == ['-'] then
|
136
|
+
if verbose then
|
137
|
+
message_out.puts "AoBane: stdin -> stdout mode."
|
138
|
+
message_out.puts "----"
|
139
|
+
end
|
140
|
+
src = @stdin.read
|
141
|
+
if defined?(Encoding) then
|
142
|
+
# ruby 1.9 or later
|
143
|
+
src.force_encoding(EncodingType.regulate(encoding))
|
144
|
+
end
|
145
|
+
|
146
|
+
# default: text
|
147
|
+
if format == DOCUMENT then
|
148
|
+
@stdout.write(AoBane.parse_document(src, encoding))
|
149
|
+
else
|
150
|
+
@stdout.write(AoBane.parse_text(src))
|
151
|
+
end
|
152
|
+
else
|
153
|
+
targets = []
|
154
|
+
|
155
|
+
args.each do |pattern|
|
156
|
+
targets.concat(Pathname.glob(pattern.gsub('\\', '/')))
|
157
|
+
end
|
158
|
+
|
159
|
+
if targets.empty? then
|
160
|
+
message_out.puts "ERROR: targets not found.\n(patterns: #{args.join(' ')})"
|
161
|
+
return false
|
162
|
+
end
|
163
|
+
|
164
|
+
targets.each do |src|
|
165
|
+
ext = src.extname
|
166
|
+
|
167
|
+
if output_dir_path then
|
168
|
+
filename = src.basename.to_s.sub(/#{Regexp.escape(ext)}$/, suffix)
|
169
|
+
dest = (output_dir_path + filename).cleanpath
|
170
|
+
else
|
171
|
+
dest = Pathname.new(src.to_s.sub(/#{Regexp.escape(ext)}$/, suffix)).cleanpath
|
172
|
+
end
|
173
|
+
|
174
|
+
html = nil
|
175
|
+
current_format = format
|
176
|
+
|
177
|
+
if ext == suffix then
|
178
|
+
message_out.puts "#{src} skipped. (suffix = #{suffix})" if verbose
|
179
|
+
elsif not force and dest.exist? and (dest.mtime > src.mtime) then
|
180
|
+
message_out.puts "#{src} skipped. (not changed)" if verbose
|
181
|
+
else
|
182
|
+
# judge by extname if format is not specified
|
183
|
+
unless current_format then
|
184
|
+
case ext
|
185
|
+
when '.bfdoc', '.md'
|
186
|
+
current_format = DOCUMENT
|
187
|
+
else
|
188
|
+
current_format = TEXT
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
# parse
|
193
|
+
parser = AoBane::Parser.new
|
194
|
+
this_encoding = nil
|
195
|
+
parsing_sec = Benchmark.realtime{
|
196
|
+
case current_format
|
197
|
+
when DOCUMENT
|
198
|
+
doc = nil
|
199
|
+
open(src, 'r'){|f|
|
200
|
+
doc = AoBane::Document.parse_io(f, encoding)
|
201
|
+
}
|
202
|
+
html = parser.document_to_html(doc)
|
203
|
+
this_encoding = doc.encoding_type
|
204
|
+
when TEXT
|
205
|
+
open_mode = (defined?(Encoding) ? "r:#{encoding}" : 'r')
|
206
|
+
text = src.open(open_mode){|x| x.read}
|
207
|
+
html = parser.parse_text(text)
|
208
|
+
this_encoding = encoding
|
209
|
+
end
|
210
|
+
}
|
211
|
+
|
212
|
+
if html then
|
213
|
+
open(dest, 'w'){|f|
|
214
|
+
f.write(html)
|
215
|
+
}
|
216
|
+
message_out.puts "#{src} => #{dest} (#{File.size(dest)} byte)"
|
217
|
+
|
218
|
+
if verbose then
|
219
|
+
message_out.puts " Format: #{current_format}"
|
220
|
+
message_out.puts " Encoding: #{this_encoding}"
|
221
|
+
message_out.puts sprintf(' Parsing Time: %g sec', parsing_sec)
|
222
|
+
message_out.puts
|
223
|
+
end
|
224
|
+
end # if html
|
225
|
+
end # if ext == suffix
|
226
|
+
|
227
|
+
end # targets.each
|
228
|
+
end # if stdin-mode
|
229
|
+
|
230
|
+
ensure
|
231
|
+
unless defined?(Encoding) then
|
232
|
+
# recover original $KCODE
|
233
|
+
$KCODE = original_kcode
|
234
|
+
end
|
235
|
+
|
236
|
+
end # begin
|
237
|
+
|
238
|
+
|
239
|
+
return true
|
240
|
+
end # def run
|
241
|
+
end # class CUI
|
242
|
+
end # module AoBane
|