aozora2html 0.7.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/bin/aozora2html +3 -50
  3. data/lib/aozora2html.rb +0 -4
  4. data/lib/aozora2html/accent_parser.rb +91 -0
  5. data/lib/aozora2html/error.rb +16 -0
  6. data/lib/aozora2html/header.rb +139 -0
  7. data/lib/aozora2html/i18n.rb +17 -0
  8. data/lib/aozora2html/ruby_buffer.rb +81 -0
  9. data/lib/aozora2html/style_stack.rb +27 -0
  10. data/lib/aozora2html/tag.rb +55 -0
  11. data/lib/aozora2html/tag/accent.rb +39 -0
  12. data/lib/aozora2html/tag/block.rb +19 -0
  13. data/lib/aozora2html/tag/chitsuki.rb +15 -0
  14. data/lib/aozora2html/tag/dakuten_katakana.rb +23 -0
  15. data/lib/aozora2html/tag/decorate.rb +18 -0
  16. data/lib/aozora2html/tag/dir.rb +15 -0
  17. data/lib/aozora2html/tag/editor_note.rb +16 -0
  18. data/lib/aozora2html/tag/embed_gaiji.rb +48 -0
  19. data/lib/aozora2html/tag/font_size.rb +17 -0
  20. data/lib/aozora2html/tag/gaiji.rb +11 -0
  21. data/lib/aozora2html/tag/img.rb +21 -0
  22. data/lib/aozora2html/tag/indent.rb +8 -0
  23. data/lib/aozora2html/tag/inline.rb +13 -0
  24. data/lib/aozora2html/tag/inline_caption.rb +15 -0
  25. data/lib/aozora2html/tag/inline_font_size.rb +18 -0
  26. data/lib/aozora2html/tag/inline_keigakomi.rb +15 -0
  27. data/lib/aozora2html/tag/inline_yokogumi.rb +16 -0
  28. data/lib/aozora2html/tag/jisage.rb +15 -0
  29. data/lib/aozora2html/tag/jizume.rb +16 -0
  30. data/lib/aozora2html/tag/kaeriten.rb +15 -0
  31. data/lib/aozora2html/tag/keigakomi.rb +13 -0
  32. data/lib/aozora2html/tag/kunten.rb +12 -0
  33. data/lib/aozora2html/tag/midashi.rb +18 -0
  34. data/lib/aozora2html/tag/multiline.rb +6 -0
  35. data/lib/aozora2html/tag/multiline_caption.rb +15 -0
  36. data/lib/aozora2html/tag/multiline_chitsuki.rb +8 -0
  37. data/lib/aozora2html/tag/multiline_jisage.rb +8 -0
  38. data/lib/aozora2html/tag/multiline_midashi.rb +22 -0
  39. data/lib/aozora2html/tag/multiline_style.rb +17 -0
  40. data/lib/aozora2html/tag/multiline_yokogumi.rb +17 -0
  41. data/lib/aozora2html/tag/okurigana.rb +15 -0
  42. data/lib/aozora2html/tag/oneline_chitsuki.rb +9 -0
  43. data/lib/aozora2html/tag/oneline_indent.rb +2 -0
  44. data/lib/aozora2html/tag/oneline_jisage.rb +7 -0
  45. data/lib/aozora2html/tag/reference_mentioned.rb +46 -0
  46. data/lib/aozora2html/tag/ruby.rb +98 -0
  47. data/lib/aozora2html/tag/un_embed_gaiji.rb +24 -0
  48. data/lib/aozora2html/tag_parser.rb +53 -0
  49. data/lib/aozora2html/utils.rb +82 -0
  50. data/lib/aozora2html/version.rb +1 -1
  51. data/lib/aozora2html/yaml_loader.rb +31 -0
  52. data/lib/extensions.rb +31 -0
  53. data/lib/jstream.rb +68 -0
  54. data/lib/t2hs.rb +485 -1490
  55. data/test/test_aozora2html.rb +161 -57
  56. data/test/test_aozora_accent_parser.rb +13 -2
  57. data/test/test_command_parse.rb +213 -0
  58. data/test/test_dakuten_katakana_tag.rb +5 -4
  59. data/test/test_decorate_tag.rb +5 -4
  60. data/test/test_dir_tag.rb +5 -4
  61. data/test/test_editor_note_tag.rb +4 -4
  62. data/test/test_exception.rb +4 -4
  63. data/test/test_font_size_tag.rb +8 -7
  64. data/test/test_gaiji_tag.rb +14 -7
  65. data/test/test_header.rb +60 -0
  66. data/test/test_img_tag.rb +5 -4
  67. data/test/test_inline_caption_tag.rb +5 -4
  68. data/test/test_inline_font_size_tag.rb +7 -6
  69. data/test/test_inline_keigakomi_tag.rb +5 -4
  70. data/test/test_inline_yokogumi_tag.rb +5 -4
  71. data/test/test_jizume_tag.rb +7 -6
  72. data/test/test_jstream.rb +5 -5
  73. data/test/test_kaeriten_tag.rb +5 -4
  74. data/test/test_keigakomi_tag.rb +8 -7
  75. data/test/test_midashi_tag.rb +38 -0
  76. data/test/test_multiline_caption_tag.rb +7 -6
  77. data/test/test_multiline_midashi_tag.rb +12 -11
  78. data/test/test_multiline_style_tag.rb +7 -6
  79. data/test/test_multiline_yokogumi_tag.rb +7 -6
  80. data/test/test_okurigana_tag.rb +5 -4
  81. data/test/test_ruby_parse.rb +116 -0
  82. data/test/test_ruby_tag.rb +5 -4
  83. data/test/test_tag_parser.rb +10 -10
  84. data/yml/accent_table.yml +240 -0
  85. data/yml/command_table.yml +61 -0
  86. data/yml/jis2ucs.yml +11234 -0
  87. metadata +63 -6
  88. data/lib/accent_tag.rb +0 -23
  89. data/lib/aozora2html/jis2ucs.rb +0 -11237
  90. data/lib/embed_gaiji_tag.rb +0 -34
@@ -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,39 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Accent < Aozora2Html::Tag
4
+
5
+ @use_jisx0213 = nil
6
+
7
+ def self.use_jisx0213=(val)
8
+ @use_jisx0213 = val
9
+ end
10
+
11
+ def self.use_jisx0213
12
+ @use_jisx0213
13
+ end
14
+
15
+ include Aozora2Html::Tag::Inline
16
+ def initialize(parser, code, name)
17
+ @code = code
18
+ @name = name
19
+ super
20
+ end
21
+
22
+ def jisx0213_to_unicode(code)
23
+ Aozora2Html::JIS2UCS[code]
24
+ end
25
+
26
+ def char_type
27
+ :hankaku
28
+ end
29
+
30
+ def to_s
31
+ if Aozora2Html::Tag::Accent.use_jisx0213
32
+ jisx0213_to_unicode(@code.sub(%r|.*/|,"").to_sym)
33
+ else
34
+ "<img src=\"#{$gaiji_dir}#{@code}.png\" alt=\"" + GAIJI_MARK + "(#{@name})\" class=\"gaiji\" />"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ module Block
4
+ def initialize(parser, *args)
5
+ if parser.block_allowed_context?
6
+ nil
7
+ else
8
+ syntax_error
9
+ end
10
+ end
11
+
12
+ # 必要に基づきmethod overrideする
13
+ def close_tag
14
+ "</div>"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,15 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Chitsuki < Aozora2Html::Tag::Indent
4
+
5
+ def initialize(parser, length)
6
+ @length = length
7
+ super
8
+ end
9
+
10
+ def to_s
11
+ '<div class="chitsuki_' + @length + '" style="text-align:right; margin-right: ' + @length + 'em">'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ class Aozora2Html
3
+ class Tag
4
+ class DakutenKatakana < Aozora2Html::Tag
5
+ include Aozora2Html::Tag::Inline
6
+
7
+ def initialize(parser, n, katakana)
8
+ @n = n
9
+ @katakana = katakana
10
+ super
11
+ end
12
+
13
+ def char_type
14
+ :katakana
15
+ end
16
+
17
+ def to_s
18
+ "<img src=\"#{$gaiji_dir}/1-07/1-07-8#{@n}.png\" alt=\"" + "※(濁点付き片仮名「".encode("shift_jis") + @katakana + "」、1-07-8".encode("shift_jis") + "#{@n})\" class=\"gaiji\" />"
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,18 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Decorate < Aozora2Html::Tag::ReferenceMentioned
4
+
5
+ def initialize(parser, target, html_class, html_tag)
6
+ @target = target
7
+ @close = "</#{html_tag}>"
8
+ @open = "<#{html_tag} class=\"#{html_class}\">"
9
+ super
10
+ end
11
+
12
+ def to_s
13
+ @open+@target.to_s+@close
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,15 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Dir < Aozora2Html::Tag::ReferenceMentioned
4
+
5
+ def initialize(parser, target)
6
+ @target = target
7
+ super
8
+ end
9
+
10
+ def to_s
11
+ "<span dir=\"ltr\">#{@target.to_s}</span>"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ class Aozora2Html
3
+ class Tag
4
+ class EditorNote < Aozora2Html::Tag
5
+ include Aozora2Html::Tag::Inline
6
+ def initialize(parser, desc)
7
+ @desc = desc
8
+ super
9
+ end
10
+
11
+ def to_s
12
+ '<span class="notes">[#'.encode("shift_jis") + @desc + ']</span>'.encode("shift_jis")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class EmbedGaiji < Aozora2Html::Tag::Gaiji
4
+ attr_accessor :unicode
5
+
6
+ @use_jisx0213 = nil
7
+ @use_unicode = nil
8
+
9
+ def self.use_jisx0213=(val)
10
+ @use_jisx0213 = val
11
+ end
12
+
13
+ def self.use_jisx0213
14
+ @use_jisx0213
15
+ end
16
+
17
+ def self.use_unicode=(val)
18
+ @use_unicode = val
19
+ end
20
+
21
+ def self.use_unicode
22
+ @use_unicode
23
+ end
24
+
25
+ def initialize(parser, folder, code, name, unicode_num = nil)
26
+ @folder = folder
27
+ @code = code
28
+ @name = name
29
+ @unicode = unicode_num
30
+ super
31
+ end
32
+
33
+ def jisx0213_to_unicode(code)
34
+ Aozora2Html::JIS2UCS[code]
35
+ end
36
+
37
+ def to_s
38
+ if Aozora2Html::Tag::EmbedGaiji.use_jisx0213 && @code
39
+ jisx0213_to_unicode(@code.to_sym)
40
+ elsif Aozora2Html::Tag::EmbedGaiji.use_unicode && @unicode
41
+ '&#x'+@unicode+';'
42
+ else
43
+ "<img src=\"#{$gaiji_dir}#{@folder}/#{@code}.png\" alt=\"" + GAIJI_MARK + "(#{@name})\" class=\"gaiji\" />"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,17 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class FontSize < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Block, Aozora2Html::Tag::Multiline
5
+
6
+ def initialize(parser, times, daisho)
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
+ "<div class=\"#{@class}\" style=\"font-size: #{@style};\">"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Gaiji < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Inline
5
+
6
+ def char_type
7
+ :kanji
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Img < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Inline
5
+
6
+ def initialize(parser, filename, css_class, alt, width, height)
7
+ @filename = filename
8
+ @css_class = css_class
9
+ @alt = alt
10
+ @width = width
11
+ @height = height
12
+ super
13
+ end
14
+
15
+ def to_s
16
+ "<img class=\"#{@css_class}\" width=\"#{@width}\" height=\"#{@height}\" src=\"#{@filename}\" alt=\"#{@alt}\" />"
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,8 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class Indent < Aozora2Html::Tag
4
+ include Aozora2Html::Tag::Block
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,13 @@
1
+ # 全ての青空記法はHTML elementに変換される
2
+ # したがって、block/inlineの区別がある
3
+ # 全ての末端青空classはどちらかのmoduleをincludeする必要がある
4
+ class Aozora2Html
5
+ class Tag
6
+ module Inline
7
+ def initialize(*args)
8
+ true
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,15 @@
1
+ class Aozora2Html
2
+ class Tag
3
+ class InlineCaption < Aozora2Html::Tag::ReferenceMentioned
4
+ def initialize(parser, target)
5
+ @target = target
6
+ super
7
+ end
8
+
9
+ def to_s
10
+ "<span class=\"caption\">#{@target.to_s}</span>"
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -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