aozora2html 0.7.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +34 -0
- data/.gitignore +8 -3
- data/.rubocop.yml +227 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +33 -0
- data/LICENSE +116 -0
- data/README.md +16 -11
- data/aozora2html.gemspec +6 -6
- data/bin/aozora2html +6 -54
- data/lib/aozora2html/accent_parser.rb +91 -0
- data/lib/aozora2html/error.rb +16 -0
- data/lib/aozora2html/header.rb +139 -0
- data/lib/aozora2html/i18n.rb +28 -0
- data/lib/aozora2html/ruby_buffer.rb +81 -0
- data/lib/aozora2html/style_stack.rb +27 -0
- data/lib/aozora2html/tag/accent.rb +39 -0
- data/lib/aozora2html/tag/block.rb +19 -0
- data/lib/aozora2html/tag/chitsuki.rb +15 -0
- data/lib/aozora2html/tag/dakuten_katakana.rb +23 -0
- data/lib/aozora2html/tag/decorate.rb +18 -0
- data/lib/aozora2html/tag/dir.rb +15 -0
- data/lib/aozora2html/tag/editor_note.rb +16 -0
- data/lib/aozora2html/tag/embed_gaiji.rb +48 -0
- data/lib/aozora2html/tag/font_size.rb +17 -0
- data/lib/aozora2html/tag/gaiji.rb +11 -0
- data/lib/aozora2html/tag/img.rb +21 -0
- data/lib/aozora2html/tag/indent.rb +8 -0
- data/lib/aozora2html/tag/inline.rb +13 -0
- data/lib/aozora2html/tag/inline_caption.rb +15 -0
- data/lib/aozora2html/tag/inline_font_size.rb +18 -0
- data/lib/aozora2html/tag/inline_keigakomi.rb +15 -0
- data/lib/aozora2html/tag/inline_yokogumi.rb +16 -0
- data/lib/aozora2html/tag/jisage.rb +15 -0
- data/lib/aozora2html/tag/jizume.rb +16 -0
- data/lib/aozora2html/tag/kaeriten.rb +15 -0
- data/lib/aozora2html/tag/keigakomi.rb +13 -0
- data/lib/aozora2html/tag/kunten.rb +12 -0
- data/lib/aozora2html/tag/midashi.rb +18 -0
- data/lib/aozora2html/tag/multiline.rb +6 -0
- data/lib/aozora2html/tag/multiline_caption.rb +15 -0
- data/lib/aozora2html/tag/multiline_chitsuki.rb +8 -0
- data/lib/aozora2html/tag/multiline_jisage.rb +8 -0
- data/lib/aozora2html/tag/multiline_midashi.rb +22 -0
- data/lib/aozora2html/tag/multiline_style.rb +17 -0
- data/lib/aozora2html/tag/multiline_yokogumi.rb +17 -0
- data/lib/aozora2html/tag/okurigana.rb +15 -0
- data/lib/aozora2html/tag/oneline_chitsuki.rb +9 -0
- data/lib/aozora2html/tag/oneline_indent.rb +2 -0
- data/lib/aozora2html/tag/oneline_jisage.rb +7 -0
- data/lib/aozora2html/tag/reference_mentioned.rb +46 -0
- data/lib/aozora2html/tag/ruby.rb +98 -0
- data/lib/aozora2html/tag/un_embed_gaiji.rb +24 -0
- data/lib/aozora2html/tag.rb +55 -0
- data/lib/aozora2html/tag_parser.rb +53 -0
- data/lib/aozora2html/utils.rb +93 -0
- data/lib/aozora2html/version.rb +1 -1
- data/lib/aozora2html/yaml_loader.rb +31 -0
- data/lib/aozora2html.rb +0 -4
- data/lib/extensions.rb +44 -0
- data/lib/jstream.rb +68 -0
- data/lib/t2hs.rb +837 -1765
- data/test/test_aozora2html.rb +320 -43
- data/test/test_aozora_accent_parser.rb +13 -2
- data/test/test_command_parse.rb +213 -0
- data/test/test_dakuten_katakana_tag.rb +5 -4
- data/test/test_decorate_tag.rb +5 -4
- data/test/test_dir_tag.rb +5 -4
- data/test/test_editor_note_tag.rb +4 -4
- data/test/test_exception.rb +4 -4
- data/test/test_font_size_tag.rb +15 -7
- data/test/test_gaiji_tag.rb +14 -7
- data/test/test_header.rb +60 -0
- data/test/test_i18n.rb +23 -0
- data/test/test_img_tag.rb +5 -4
- data/test/test_inline_caption_tag.rb +5 -4
- data/test/test_inline_font_size_tag.rb +7 -6
- data/test/test_inline_keigakomi_tag.rb +5 -4
- data/test/test_inline_yokogumi_tag.rb +5 -4
- data/test/test_jizume_tag.rb +7 -6
- data/test/test_jstream.rb +5 -5
- data/test/test_kaeriten_tag.rb +5 -4
- data/test/test_keigakomi_tag.rb +8 -7
- data/test/test_midashi_tag.rb +38 -0
- data/test/test_multiline_caption_tag.rb +7 -6
- data/test/test_multiline_midashi_tag.rb +24 -7
- data/test/test_multiline_style_tag.rb +7 -6
- data/test/test_multiline_yokogumi_tag.rb +7 -6
- data/test/test_okurigana_tag.rb +5 -4
- data/test/test_ruby_parse.rb +130 -0
- data/test/test_ruby_tag.rb +5 -4
- data/test/test_tag_parser.rb +10 -10
- data/vendor/jis2ucs/README.md +3 -6
- data/yml/accent_table.yml +240 -0
- data/yml/command_table.yml +61 -0
- data/yml/jis2ucs.yml +11234 -0
- metadata +74 -42
- data/appveyor.yml +0 -19
- data/lib/accent_tag.rb +0 -23
- data/lib/aozora2html/jis2ucs.rb +0 -11237
- data/lib/embed_gaiji_tag.rb +0 -34
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
class Aozora2Html
|
3
|
+
class YamlLoader
|
4
|
+
def initialize(base_dir)
|
5
|
+
@base_dir = base_dir
|
6
|
+
end
|
7
|
+
|
8
|
+
def load(path)
|
9
|
+
tmp_data = YAML.load_file(File.join(@base_dir, path))
|
10
|
+
normalize_data(tmp_data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def normalize_data(data)
|
14
|
+
case data
|
15
|
+
when String
|
16
|
+
data.encode("shift_jis")
|
17
|
+
when Hash
|
18
|
+
new_data = {}
|
19
|
+
data.each do |k, v|
|
20
|
+
new_data[normalize_data(k)] = normalize_data(v)
|
21
|
+
end
|
22
|
+
new_data
|
23
|
+
when Array
|
24
|
+
data.map{|item| normalize_data(item)}
|
25
|
+
else
|
26
|
+
# noop
|
27
|
+
data
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/aozora2html.rb
CHANGED
data/lib/extensions.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# 1.8 like to_s method to Array
|
3
|
+
class Array
|
4
|
+
def to_s
|
5
|
+
self.join
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class String
|
10
|
+
|
11
|
+
# used in Aozora2Html#char_type
|
12
|
+
def char_type
|
13
|
+
ch = self
|
14
|
+
if ch.match(Regexp.new("[ぁ-んゝゞ]".encode("shift_jis")))
|
15
|
+
:hiragana
|
16
|
+
elsif ch.match(Regexp.new("[ァ-ンーヽヾヴ]".encode("shift_jis")))
|
17
|
+
:katakana
|
18
|
+
elsif ch.match(Regexp.new("[0-9A-Za-zΑ-Ωα-ωА-Яа-я−&’,.]".encode("shift_jis")))
|
19
|
+
:zenkaku
|
20
|
+
elsif ch.match(Regexp.new("[A-Za-z0-9#\\-\\&'\\,]".encode("shift_jis")))
|
21
|
+
:hankaku
|
22
|
+
elsif ch.match(Regexp.new("[亜-熙々※仝〆〇ヶ]".encode("shift_jis")))
|
23
|
+
:kanji
|
24
|
+
elsif ch.match(/[\.\;\"\?\!\)]/)
|
25
|
+
:hankaku_terminate
|
26
|
+
else
|
27
|
+
:else
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_sjis
|
32
|
+
self.encode("shift_jis")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module Kernel
|
37
|
+
alias original_kernel_puts puts
|
38
|
+
|
39
|
+
def puts(*args)
|
40
|
+
original_kernel_puts(args)
|
41
|
+
rescue Encoding::CompatibilityError
|
42
|
+
original_kernel_puts(args.map { |arg| arg.force_encoding('utf-8') })
|
43
|
+
end
|
44
|
+
end
|
data/lib/jstream.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "aozora2html/error"
|
2
|
+
require "aozora2html/i18n"
|
3
|
+
|
4
|
+
##
|
5
|
+
# Stream class for reading a file.
|
6
|
+
#
|
7
|
+
# It's just a wrapper class of IO to read characters.
|
8
|
+
# when finished to read IO, return a symbol :eof.
|
9
|
+
# when found line terminator except CR+LF, exit.
|
10
|
+
#
|
11
|
+
class Jstream
|
12
|
+
|
13
|
+
attr_accessor :line
|
14
|
+
|
15
|
+
def initialize(file_io)
|
16
|
+
@line = 0
|
17
|
+
@entry = false
|
18
|
+
@file = file_io
|
19
|
+
begin
|
20
|
+
store_to_buffer
|
21
|
+
rescue Aozora2Html::Error => e
|
22
|
+
puts e.message(1)
|
23
|
+
if e.is_a?(Aozora2Html::Error)
|
24
|
+
exit(2)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def inspect
|
30
|
+
"#<jcode-stream input " + @file.inspect + ">"
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_char
|
34
|
+
found = @buffer.shift
|
35
|
+
if @entry
|
36
|
+
@line += 1
|
37
|
+
@entry = false
|
38
|
+
end
|
39
|
+
if found
|
40
|
+
return found
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
store_to_buffer
|
45
|
+
rescue EOFError
|
46
|
+
@buffer = [:eof]
|
47
|
+
end
|
48
|
+
"\r\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
def peek_char(pos)
|
52
|
+
@buffer[pos] || "\r\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def close
|
56
|
+
@file.close
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def store_to_buffer
|
61
|
+
if tmp = @file.readline.chomp!("\r\n")
|
62
|
+
@buffer = tmp.each_char.to_a
|
63
|
+
else
|
64
|
+
raise Aozora2Html::Error, Aozora2Html::I18n.t(:use_crlf)
|
65
|
+
end
|
66
|
+
@entry = true
|
67
|
+
end
|
68
|
+
end
|