aozora2html 0.7.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +34 -0
  3. data/.gitignore +8 -3
  4. data/.rubocop.yml +227 -0
  5. data/.travis.yml +5 -0
  6. data/CHANGELOG.md +33 -0
  7. data/LICENSE +116 -0
  8. data/README.md +16 -11
  9. data/aozora2html.gemspec +6 -6
  10. data/bin/aozora2html +6 -54
  11. data/lib/aozora2html/accent_parser.rb +91 -0
  12. data/lib/aozora2html/error.rb +16 -0
  13. data/lib/aozora2html/header.rb +139 -0
  14. data/lib/aozora2html/i18n.rb +28 -0
  15. data/lib/aozora2html/ruby_buffer.rb +81 -0
  16. data/lib/aozora2html/style_stack.rb +27 -0
  17. data/lib/aozora2html/tag/accent.rb +39 -0
  18. data/lib/aozora2html/tag/block.rb +19 -0
  19. data/lib/aozora2html/tag/chitsuki.rb +15 -0
  20. data/lib/aozora2html/tag/dakuten_katakana.rb +23 -0
  21. data/lib/aozora2html/tag/decorate.rb +18 -0
  22. data/lib/aozora2html/tag/dir.rb +15 -0
  23. data/lib/aozora2html/tag/editor_note.rb +16 -0
  24. data/lib/aozora2html/tag/embed_gaiji.rb +48 -0
  25. data/lib/aozora2html/tag/font_size.rb +17 -0
  26. data/lib/aozora2html/tag/gaiji.rb +11 -0
  27. data/lib/aozora2html/tag/img.rb +21 -0
  28. data/lib/aozora2html/tag/indent.rb +8 -0
  29. data/lib/aozora2html/tag/inline.rb +13 -0
  30. data/lib/aozora2html/tag/inline_caption.rb +15 -0
  31. data/lib/aozora2html/tag/inline_font_size.rb +18 -0
  32. data/lib/aozora2html/tag/inline_keigakomi.rb +15 -0
  33. data/lib/aozora2html/tag/inline_yokogumi.rb +16 -0
  34. data/lib/aozora2html/tag/jisage.rb +15 -0
  35. data/lib/aozora2html/tag/jizume.rb +16 -0
  36. data/lib/aozora2html/tag/kaeriten.rb +15 -0
  37. data/lib/aozora2html/tag/keigakomi.rb +13 -0
  38. data/lib/aozora2html/tag/kunten.rb +12 -0
  39. data/lib/aozora2html/tag/midashi.rb +18 -0
  40. data/lib/aozora2html/tag/multiline.rb +6 -0
  41. data/lib/aozora2html/tag/multiline_caption.rb +15 -0
  42. data/lib/aozora2html/tag/multiline_chitsuki.rb +8 -0
  43. data/lib/aozora2html/tag/multiline_jisage.rb +8 -0
  44. data/lib/aozora2html/tag/multiline_midashi.rb +22 -0
  45. data/lib/aozora2html/tag/multiline_style.rb +17 -0
  46. data/lib/aozora2html/tag/multiline_yokogumi.rb +17 -0
  47. data/lib/aozora2html/tag/okurigana.rb +15 -0
  48. data/lib/aozora2html/tag/oneline_chitsuki.rb +9 -0
  49. data/lib/aozora2html/tag/oneline_indent.rb +2 -0
  50. data/lib/aozora2html/tag/oneline_jisage.rb +7 -0
  51. data/lib/aozora2html/tag/reference_mentioned.rb +46 -0
  52. data/lib/aozora2html/tag/ruby.rb +98 -0
  53. data/lib/aozora2html/tag/un_embed_gaiji.rb +24 -0
  54. data/lib/aozora2html/tag.rb +55 -0
  55. data/lib/aozora2html/tag_parser.rb +53 -0
  56. data/lib/aozora2html/utils.rb +93 -0
  57. data/lib/aozora2html/version.rb +1 -1
  58. data/lib/aozora2html/yaml_loader.rb +31 -0
  59. data/lib/aozora2html.rb +0 -4
  60. data/lib/extensions.rb +44 -0
  61. data/lib/jstream.rb +68 -0
  62. data/lib/t2hs.rb +837 -1765
  63. data/test/test_aozora2html.rb +320 -43
  64. data/test/test_aozora_accent_parser.rb +13 -2
  65. data/test/test_command_parse.rb +213 -0
  66. data/test/test_dakuten_katakana_tag.rb +5 -4
  67. data/test/test_decorate_tag.rb +5 -4
  68. data/test/test_dir_tag.rb +5 -4
  69. data/test/test_editor_note_tag.rb +4 -4
  70. data/test/test_exception.rb +4 -4
  71. data/test/test_font_size_tag.rb +15 -7
  72. data/test/test_gaiji_tag.rb +14 -7
  73. data/test/test_header.rb +60 -0
  74. data/test/test_i18n.rb +23 -0
  75. data/test/test_img_tag.rb +5 -4
  76. data/test/test_inline_caption_tag.rb +5 -4
  77. data/test/test_inline_font_size_tag.rb +7 -6
  78. data/test/test_inline_keigakomi_tag.rb +5 -4
  79. data/test/test_inline_yokogumi_tag.rb +5 -4
  80. data/test/test_jizume_tag.rb +7 -6
  81. data/test/test_jstream.rb +5 -5
  82. data/test/test_kaeriten_tag.rb +5 -4
  83. data/test/test_keigakomi_tag.rb +8 -7
  84. data/test/test_midashi_tag.rb +38 -0
  85. data/test/test_multiline_caption_tag.rb +7 -6
  86. data/test/test_multiline_midashi_tag.rb +24 -7
  87. data/test/test_multiline_style_tag.rb +7 -6
  88. data/test/test_multiline_yokogumi_tag.rb +7 -6
  89. data/test/test_okurigana_tag.rb +5 -4
  90. data/test/test_ruby_parse.rb +130 -0
  91. data/test/test_ruby_tag.rb +5 -4
  92. data/test/test_tag_parser.rb +10 -10
  93. data/vendor/jis2ucs/README.md +3 -6
  94. data/yml/accent_table.yml +240 -0
  95. data/yml/command_table.yml +61 -0
  96. data/yml/jis2ucs.yml +11234 -0
  97. metadata +74 -42
  98. data/appveyor.yml +0 -19
  99. data/lib/accent_tag.rb +0 -23
  100. data/lib/aozora2html/jis2ucs.rb +0 -11237
  101. data/lib/embed_gaiji_tag.rb +0 -34
@@ -0,0 +1,18 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class InlineFontSize < Aozora2Html::Tag::ReferenceMentioned
4
+
5
+ def initialize(parser, target, times, daisho)
6
+ @target = target
7
+ @class = daisho.to_s + times.to_s
8
+ @style = Utils.create_font_size(times, daisho)
9
+ super
10
+ end
11
+
12
+ def to_s
13
+ "<span class=\"#{@class}\" style=\"font-size: #{@style};\">" + @target.to_s + "</span>"
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,15 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class InlineKeigakomi < Aozora2Html::Tag::ReferenceMentioned
4
+ def initialize(parser, target)
5
+ @target = target
6
+ super
7
+ end
8
+
9
+ def to_s
10
+ "<span class=\"keigakomi\">#{@target.to_s}</span>"
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,16 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class InlineYokogumi < Aozora2Html::Tag::ReferenceMentioned
4
+
5
+ def initialize(parser, target)
6
+ @target = target
7
+ super
8
+ end
9
+
10
+ def to_s
11
+ "<span class=\"yokogumi\">#{@target.to_s}</span>"
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,15 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Jisage < Aozora2Html::Tag::Indent
4
+
5
+ def initialize(parser, width)
6
+ @width = width
7
+ super
8
+ end
9
+
10
+ def to_s
11
+ "<div class=\"jisage_#{@width}\" style=\"margin-left: #{@width}em\">"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Jizume < Aozora2Html::Tag::Indent
4
+ include Aozora2Html::Tag::Multiline
5
+
6
+ def initialize(parser, width)
7
+ @w = width
8
+ super
9
+ end
10
+
11
+ def to_s
12
+ "<div class=\"jizume_#{@w}\" style=\"width: #{@w}em\">"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Kaeriten < Aozora2Html::Tag::Kunten
4
+
5
+ def initialize(parser, string)
6
+ @string = string
7
+ super
8
+ end
9
+
10
+ def to_s
11
+ "<sub class=\"kaeriten\">#{@string.to_s}</sub>"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class Aozora2Html::Tag::Keigakomi < Aozora2Html::Tag
2
+ include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
3
+
4
+ def initialize(parser, size = 1)
5
+ @size = size
6
+ super
7
+ end
8
+
9
+ def to_s
10
+ "<div class=\"keigakomi\" style=\"border: solid #{@size}px\">"
11
+ end
12
+ end
13
+
@@ -0,0 +1,12 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Kunten < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Inline
5
+
6
+ def char_type
7
+ :else # just remove this line
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,18 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Midashi < Aozora2Html::Tag::ReferenceMentioned
4
+
5
+ def initialize(parser, target, size, type)
6
+ super
7
+ @target = target
8
+ @tag = Utils.create_midashi_tag(size)
9
+ @id = parser.new_midashi_id(size)
10
+ @class = Utils.create_midashi_class(type, @tag)
11
+ end
12
+
13
+ def to_s
14
+ "<#{@tag} class=\"#{@class}\"><a class=\"midashi_anchor\" id=\"midashi#{@id}\">#{@target}</a></#{@tag}>"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ module Multiline
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class MultilineCaption < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
+
6
+ def initialize(parser)
7
+ super
8
+ end
9
+
10
+ def to_s
11
+ "<div class=\"caption\">"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class MultilineChitsuki < Aozora2Html::Tag::Chitsuki
4
+ include Aozora2Html::Tag::Multiline
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,8 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class MultilineJisage < Aozora2Html::Tag::Jisage
4
+ include Aozora2Html::Tag::Multiline
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,22 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class MultilineMidashi < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
+
6
+ def initialize(parser,size,type)
7
+ super
8
+ @tag = Utils.create_midashi_tag(size)
9
+ @id = parser.new_midashi_id(size)
10
+ @class = Utils.create_midashi_class(type, @tag)
11
+ end
12
+
13
+ def to_s
14
+ "<#{@tag} class=\"#{@class}\"><a class=\"midashi_anchor\" id=\"midashi#{@id}\">"
15
+ end
16
+
17
+ def close_tag
18
+ "</a></#{@tag}>"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class MultilineStyle < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
+
6
+ def initialize(parser, style)
7
+ @style = style
8
+ super
9
+ end
10
+
11
+ def to_s
12
+ "<div class=\"#{@style}\">"
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class MultilineYokogumi < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
+
6
+ def initialize(parser)
7
+ super
8
+ end
9
+
10
+ def to_s
11
+ "<div class=\"yokogumi\">"
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+
@@ -0,0 +1,15 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Okurigana < Aozora2Html::Tag::Kunten
4
+
5
+ def initialize(parser, string)
6
+ @string = string
7
+ super
8
+ end
9
+
10
+ def to_s
11
+ "<sup class=\"okurigana\">#{@string.to_s}</sup>"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class OnelineChitsuki < Aozora2Html::Tag::Chitsuki
4
+ include Aozora2Html::Tag::OnelineIndent
5
+ end
6
+ end
7
+ end
8
+
9
+
@@ -0,0 +1,2 @@
1
+ module Aozora2Html::Tag::OnelineIndent
2
+ end
@@ -0,0 +1,7 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class OnelineJisage < Aozora2Html::Tag::Jisage
4
+ include Aozora2Html::Tag::OnelineIndent
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,46 @@
1
+ # 前方参照でこいつだけは中身をチェックする
2
+ # 子要素を持つAozora2Html::Tag::Inlineは全てこいつのサブクラス
3
+ class Aozora2Html
4
+ class Tag
5
+ class ReferenceMentioned < Aozora2Html::Tag
6
+ include Aozora2Html::Tag::Inline
7
+ attr_accessor :target
8
+
9
+ def initialize(*args)
10
+ if defined?(@target) && block_element?(@target)
11
+ syntax_error
12
+ end
13
+ end
14
+
15
+ def block_element?(elt)
16
+ if elt.is_a?(Array)
17
+ elt.each do |x|
18
+ if block_element?(x)
19
+ return true
20
+ end
21
+ end
22
+ nil
23
+ elsif elt.is_a?(String)
24
+ elt.match(/<div/)
25
+ else
26
+ elt.is_a?(Aozora2Html::Tag::Block)
27
+ end
28
+ end
29
+
30
+ def target_string
31
+ if @target.is_a?(Aozora2Html::Tag::ReferenceMentioned)
32
+ @target.target_string
33
+ elsif @target.is_a?(Array)
34
+ @target.collect{|x|
35
+ if x.is_a?(Aozora2Html::Tag::ReferenceMentioned)
36
+ x.target_string
37
+ else
38
+ x
39
+ end}.to_s
40
+ else
41
+ @target
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+ # complex ruby markup
3
+ # if css3 is major supported, please fix ruby position with property "ruby-position"
4
+ # see also: http://www.w3.org/TR/2001/WD-css3-ruby-20010216/
5
+ class Aozora2Html
6
+ class Tag
7
+ class Ruby < Aozora2Html::Tag::ReferenceMentioned
8
+ attr_accessor :ruby, :under_ruby
9
+
10
+ def initialize(parser, string, ruby, under_ruby = "")
11
+ @target = string
12
+ @ruby = ruby
13
+ @under_ruby = under_ruby
14
+ super
15
+ end
16
+
17
+ def gen_rt(string)
18
+ if string != ""
19
+ "<rt class=\"real_ruby\">#{string}</rt>"
20
+ else
21
+ "<rt class=\"dummy_ruby\"></rt>"
22
+ end
23
+ end
24
+
25
+ def to_s
26
+ "<ruby><rb>#{@target.to_s}</rb><rp>" + "(".encode("shift_jis") + "</rp><rt>#{@ruby.to_s}</rt><rp>" + ")".encode("shift_jis") + "</rp></ruby>"
27
+ end
28
+
29
+ # complex ruby is waiting for IE support and CSS3 candidate
30
+ =begin
31
+ def to_s
32
+ ans = "<ruby class=\"complex_ruby\"><rbc>" # indicator of new version of aozora ruby
33
+ if @ruby.is_a?(Array) and @ruby.length > 0
34
+ # cell is used
35
+ @rbspan = @ruby.length
36
+ end
37
+ if @under_ruby.is_a?(Array) and @under_ruby.length > 0
38
+ # cell is used, but two way cell is not supported
39
+ if @rbspan
40
+ raise Aozora2Html::Error, I18n.t(:unsupported_ruby)
41
+ else
42
+ @rbspan = @under_ruby.length
43
+ end
44
+ end
45
+
46
+ # target
47
+ if @rbspan
48
+ @target.each{|x|
49
+ ans.concat("<rb>#{x.to_s}</rb>")
50
+ }
51
+ else
52
+ ans.concat("<rb>#{@target.to_s}</rb>")
53
+ end
54
+
55
+ ans.concat("</rbc><rtc>")
56
+
57
+ # upper ruby
58
+ if @ruby.is_a?(Array)
59
+ @ruby.each{|x|
60
+ ans.concat(gen_rt(x))
61
+ }
62
+ elsif @rbspan
63
+ if @ruby != ""
64
+ ans.concat("<rt class=\"real_ruby\" rbspan=\"#{@rbspan}\">#{@ruby}</rt>")
65
+ else
66
+ ans.concat("<rt class=\"dummy_ruby\" rbspan=\"#{@rbspan}\"></rt>")
67
+ end
68
+ else
69
+ ans.concat(gen_rt(@ruby))
70
+ end
71
+
72
+ ans.concat("</rtc>")
73
+
74
+ # under_ruby (if exists)
75
+ if @under_ruby.length > 0
76
+ ans.concat("<rtc>")
77
+ if @under_ruby.is_a?(Array)
78
+ @under_ruby.each{|x|
79
+ ans.concat(gen_rt(x))
80
+ }
81
+ elsif @rbspan
82
+ ans.concat("<rt class=\"real_ruby\" rbspan=\"#{@rbspan}\">#{@under_ruby}</rt>")
83
+ else
84
+ ans.concat(gen_rt(@under_ruby))
85
+ end
86
+ ans.concat("</rtc>")
87
+ end
88
+
89
+ # finalize
90
+ ans.concat("</ruby>")
91
+
92
+ ans
93
+ end
94
+ =end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ class Aozora2Html
3
+ class Tag
4
+ class UnEmbedGaiji < Aozora2Html::Tag::Gaiji
5
+ def initialize(parser, desc)
6
+ @desc = desc
7
+ @escaped = false
8
+ super
9
+ end
10
+
11
+ def to_s
12
+ '<span class="notes">['.encode("shift_jis") + @desc + ']</span>'.encode("shift_jis")
13
+ end
14
+
15
+ def escaped?
16
+ @escaped
17
+ end
18
+
19
+ def escape!
20
+ @escaped = true
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,55 @@
1
+ require "aozora2html/tag/inline"
2
+ require "aozora2html/tag/block"
3
+ require "aozora2html/tag/accent"
4
+ require "aozora2html/tag/gaiji"
5
+ require "aozora2html/tag/embed_gaiji"
6
+ require "aozora2html/tag/un_embed_gaiji"
7
+ require "aozora2html/tag/editor_note"
8
+ require "aozora2html/tag/indent"
9
+ require "aozora2html/tag/oneline_indent"
10
+ require "aozora2html/tag/multiline"
11
+ require "aozora2html/tag/multiline_style"
12
+ require "aozora2html/tag/font_size"
13
+ require "aozora2html/tag/jizume"
14
+ require "aozora2html/tag/keigakomi"
15
+ require "aozora2html/tag/multiline_yokogumi"
16
+ require "aozora2html/tag/multiline_caption"
17
+ require "aozora2html/tag/multiline_midashi"
18
+ require "aozora2html/tag/jisage"
19
+ require "aozora2html/tag/oneline_jisage"
20
+ require "aozora2html/tag/multiline_jisage"
21
+ require "aozora2html/tag/chitsuki"
22
+ require "aozora2html/tag/oneline_chitsuki"
23
+ require "aozora2html/tag/multiline_chitsuki"
24
+ require "aozora2html/tag/reference_mentioned"
25
+ require "aozora2html/tag/midashi"
26
+ require "aozora2html/tag/ruby"
27
+ require "aozora2html/tag/kunten"
28
+ require "aozora2html/tag/kaeriten"
29
+ require "aozora2html/tag/okurigana"
30
+ require "aozora2html/tag/inline_keigakomi"
31
+ require "aozora2html/tag/inline_yokogumi"
32
+ require "aozora2html/tag/inline_caption"
33
+ require "aozora2html/tag/inline_font_size"
34
+ require "aozora2html/tag/decorate"
35
+ require "aozora2html/tag/dakuten_katakana"
36
+ require "aozora2html/tag/dir"
37
+ require "aozora2html/tag/img"
38
+
39
+ # 変換される青空記法class
40
+ class Aozora2Html
41
+ class Tag
42
+ # debug用
43
+ def inspect
44
+ to_s
45
+ end
46
+
47
+ def char_type
48
+ :else
49
+ end
50
+
51
+ def syntax_error
52
+ raise Aozora2Html::Error, I18n.t(:tag_syntax_error)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,53 @@
1
+ # 青空記法の入れ子に対応(?)
2
+ require 'aozora2html/ruby_buffer'
3
+ class Aozora2Html
4
+ class TagParser < Aozora2Html
5
+ def initialize(input, endchar, chuuki, image)
6
+ if not(input.is_a?(Jstream))
7
+ raise ArgumentError, "tag_parser must supply Jstream as input"
8
+ end
9
+ @stream = input
10
+ @buffer = []
11
+ @ruby_buf = RubyBuffer.new
12
+ @chuuki_table = chuuki
13
+ @images = image # globalな環境を記録するアイテムは共有する必要あり
14
+ @endchar = endchar # 改行を越えるべきか否か…
15
+ @section = :tail # 末尾処理と記法内はインデントをしないので等価
16
+ @raw = "" # 外字変換前の生テキストを残したいことがあるらしい
17
+ end
18
+
19
+ def read_char # method override!
20
+ c = @stream.read_char
21
+ @raw.concat(c)
22
+ c
23
+ end
24
+
25
+ def read_to_nest(endchar)
26
+ ans = super(endchar)
27
+ @raw.concat(ans[1])
28
+ ans
29
+ end
30
+
31
+ def general_output # 出力は[String,String]返しで!
32
+ @ruby_buf.dump_into(@buffer)
33
+ ans=""
34
+ @buffer.each do |s|
35
+ if s.is_a?(Aozora2Html::Tag::UnEmbedGaiji) and !s.escaped?
36
+ # 消してあった※を復活させて
37
+ ans.concat(GAIJI_MARK)
38
+ end
39
+ ans.concat(s.to_s)
40
+ end
41
+ [ans,@raw]
42
+ end
43
+
44
+ def process()
45
+ catch(:terminate) do
46
+ loop do
47
+ parse
48
+ end
49
+ end
50
+ general_output
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,93 @@
1
+ # encoding: utf-8
2
+ class Aozora2Html
3
+ module Utils
4
+
5
+ def create_font_size(times, daisho)
6
+ size = ""
7
+ case times
8
+ when 1
9
+ size = ""
10
+ when 2
11
+ size = "x-"
12
+ else
13
+ if times >= 3
14
+ size = "xx-"
15
+ else
16
+ raise Aozora2Html::Error, I18n.t(:invalid_font_size)
17
+ end
18
+ end
19
+
20
+ case daisho
21
+ when :dai
22
+ size << "large"
23
+ when :sho
24
+ size << "small"
25
+ else
26
+ raise Aozora2Html::Error, I18n.t(:invalid_font_size)
27
+ end
28
+
29
+ size
30
+ end
31
+ module_function :create_font_size
32
+
33
+ def create_midashi_tag(size)
34
+ if size.match(SIZE_SMALL)
35
+ "h5"
36
+ elsif size.match(SIZE_MIDDLE)
37
+ "h4"
38
+ elsif size.match(SIZE_LARGE)
39
+ "h3"
40
+ else
41
+ raise Aozora2Html::Error, I18n.t(:undefined_header)
42
+ end
43
+ end
44
+ module_function :create_midashi_tag
45
+
46
+ def create_midashi_class(type, tag)
47
+ case type
48
+ when :normal
49
+ case tag
50
+ when "h5"
51
+ "ko-midashi"
52
+ when "h4"
53
+ "naka-midashi"
54
+ when "h3"
55
+ "o-midashi"
56
+ end
57
+ when :dogyo
58
+ case tag
59
+ when "h5"
60
+ "dogyo-ko-midashi"
61
+ when "h4"
62
+ "dogyo-naka-midashi"
63
+ when "h3"
64
+ "dogyo-o-midashi"
65
+ end
66
+ when :mado
67
+ case tag
68
+ when "h5"
69
+ "mado-ko-midashi"
70
+ when "h4"
71
+ "mado-naka-midashi"
72
+ when "h3"
73
+ "mado-o-midashi"
74
+ end
75
+ else
76
+ raise Aozora2Html::Error, I18n.t(:undefined_header)
77
+ end
78
+ end
79
+ module_function :create_midashi_class
80
+
81
+ def convert_japanese_number(command)
82
+ tmp = command.tr("0-9".encode("shift_jis"), "0-9")
83
+ tmp.tr!("一二三四五六七八九〇".encode("shift_jis"),"1234567890")
84
+ tmp.gsub!(/(\d)#{"十".encode("shift_jis")}(\d)/){"#{$1}#{$2}"}
85
+ tmp.gsub!(/(\d)#{"十".encode("shift_jis")}/){"#{$1}0"}
86
+ tmp.gsub!(/#{"十".encode("shift_jis")}(\d)/){"1#{$1}"}
87
+ tmp.gsub!(/#{"十".encode("shift_jis")}/,"10")
88
+ tmp
89
+ end
90
+ module_function :convert_japanese_number
91
+ end
92
+ end
93
+
@@ -1,3 +1,3 @@
1
1
  class Aozora2Html
2
- VERSION = "0.7.0"
2
+ VERSION = "2.0.0"
3
3
  end