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,91 @@
1
+ # encoding: utf-8
2
+ require 'aozora2html/ruby_buffer'
3
+ class Aozora2Html
4
+
5
+ # accent特殊文字を生かすための再帰呼び出し
6
+ class AccentParser < Aozora2Html
7
+
8
+ def initialize(input, endchar, chuuki, image)
9
+ if not(input.is_a?(Jstream))
10
+ raise ArgumentError, "tag_parser must supply Jstream as input"
11
+ end
12
+ @stream = input
13
+ @buffer = []
14
+ @ruby_buf = Aozora2Html::RubyBuffer.new
15
+ @chuuki_table = chuuki
16
+ @images = image # globalな環境を記録するアイテムは共有する必要あり
17
+ @endchar = endchar # 改行は越えられない <br />を出力していられない
18
+ @closed = nil # 改行での強制撤退チェックフラグ
19
+ @encount_accent = nil
20
+ end
21
+
22
+ def general_output # 出力は配列で返す
23
+ @ruby_buf.dump_into(@buffer)
24
+ if !@encount_accent
25
+ @buffer.unshift("〔".encode("shift_jis"))
26
+ end
27
+ if @closed and !@encount_accent
28
+ @buffer.push("〕".encode("shift_jis"))
29
+ elsif not(@closed)
30
+ @buffer.push("<br />\r\n")
31
+ end
32
+ @buffer
33
+ end
34
+
35
+ def parse
36
+ first = read_char
37
+ if found = Aozora2Html::ACCENT_TABLE[first]
38
+ if found2 = found[@stream.peek_char(0)]
39
+ if found2.is_a?(Hash)
40
+ if found3 = found2[@stream.peek_char(1)]
41
+ first = Aozora2Html::Tag::Accent.new(self, *found3)
42
+ @encount_accent = true
43
+ @chuuki_table[:accent] = true
44
+ read_char
45
+ read_char
46
+ end
47
+ elsif found2
48
+ first = Aozora2Html::Tag::Accent.new(self, *found2)
49
+ @encount_accent = true
50
+ read_char
51
+ @chuuki_table[:accent] = true
52
+ end
53
+ end
54
+ end
55
+ case first
56
+ when Aozora2Html::GAIJI_MARK
57
+ first = dispatch_gaiji
58
+ when "[".encode("shift_jis")
59
+ first = dispatch_aozora_command
60
+ when Aozora2Html::KU
61
+ assign_kunoji
62
+ when "《".encode("shift_jis")
63
+ first = apply_ruby
64
+ end
65
+ if first == "\r\n"
66
+ if @encount_accent
67
+ puts "警告(#{line_number}行目):アクセント分解の亀甲括弧の始めと終わりが、行中で揃っていません".encode("shift_jis")
68
+ end
69
+ throw :terminate
70
+ elsif first == "〕".encode("shift_jis")
71
+ @closed = true
72
+ throw :terminate
73
+ elsif first == RUBY_PREFIX
74
+ @ruby_buf.dump_into(@buffer)
75
+ @ruby_buf.protected = true
76
+ elsif first != "" and first != nil
77
+ illegal_char_check(first, line_number)
78
+ push_chars(first)
79
+ end
80
+ end
81
+
82
+ def process
83
+ catch(:terminate) do
84
+ loop do
85
+ parse
86
+ end
87
+ end
88
+ general_output
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,16 @@
1
+ require "aozora2html/i18n"
2
+
3
+ # 例外class
4
+ class Aozora2Html
5
+ class Error < StandardError
6
+
7
+ def initialize(msg)
8
+ @message = msg
9
+ end
10
+
11
+ def message(line = 0)
12
+ I18n.t(:error_stop, line, @message)
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,139 @@
1
+ # encoding: utf-8
2
+ class Aozora2Html
3
+ class Header
4
+ def initialize()
5
+ @header = []
6
+ end
7
+
8
+ def push(line)
9
+ @header.push(line)
10
+ end
11
+
12
+ def out_header_info(hash, attr, true_name = nil)
13
+ found = hash[attr]
14
+ if found
15
+ "<h2 class=\"#{true_name or attr}\">#{found}</h2>\r\n"
16
+ else
17
+ ""
18
+ end
19
+ end
20
+
21
+ def header_element_type(string)
22
+ original = true
23
+ string.each_char do |ch|
24
+ code = ch.unpack("H*")[0]
25
+ if ("00" <= code and code <= "7f") or # 1byte
26
+ ("8140" <= code and code <= "8258") or # 1-1, 3-25
27
+ ("839f" <= code and code <= "8491") # 6-1, 7-81
28
+ # continue
29
+ else
30
+ original = false
31
+ break
32
+ end
33
+ end
34
+ if original
35
+ :original
36
+ elsif string.match(PAT_EDITOR)
37
+ :editor
38
+ elsif string.match(PAT_HENYAKU)
39
+ :henyaku
40
+ elsif string.match(PAT_TRANSLATOR)
41
+ :translator
42
+ end
43
+ end
44
+
45
+ def process_person(string, header_info)
46
+ type = header_element_type(string)
47
+ case type
48
+ when :editor
49
+ header_info[:editor] = string
50
+ when :translator
51
+ header_info[:translator] = string
52
+ when :henyaku
53
+ header_info[:henyaku] = string
54
+ else
55
+ type = :author
56
+ header_info[:author] = string
57
+ end
58
+ type
59
+ end
60
+
61
+ def build_title(header_info)
62
+ buf = [:author, :translator, :editor, :henyaku,
63
+ :title, :original_title,
64
+ :subtitle, :original_subtitle].map{|item| header_info[item]}.compact
65
+ buf_str = buf.join(" ")
66
+ "<title>#{buf_str}</title>"
67
+ end
68
+
69
+ def build_header_info
70
+ header_info = {:title => @header[0]}
71
+ case @header.length
72
+ when 2
73
+ process_person(@header[1], header_info)
74
+ when 3
75
+ if header_element_type(@header[1]) == :original
76
+ header_info[:original_title] = @header[1]
77
+ process_person(@header[2], header_info)
78
+ elsif process_person(@header[2], header_info) == :author
79
+ header_info[:subtitle] = @header[1]
80
+ else
81
+ header_info[:author] = @header[1]
82
+ end
83
+ when 4
84
+ if header_element_type(@header[1]) == :original
85
+ header_info[:original_title] = @header[1]
86
+ else
87
+ header_info[:subtitle] = @header[1]
88
+ end
89
+ if process_person(@header[3], header_info) == :author
90
+ header_info[:subtitle] = @header[2]
91
+ else
92
+ header_info[:author] = @header[2]
93
+ end
94
+ when 5
95
+ header_info[:original_title] = @header[1]
96
+ header_info[:subtitle] = @header[2]
97
+ header_info[:author] = @header[3]
98
+ if process_person(@header[4], header_info) == :author
99
+ raise Aozora2Html::Error, "parser encounted author twice"
100
+ end
101
+ when 6
102
+ header_info[:original_title] = @header[1]
103
+ header_info[:subtitle] = @header[2]
104
+ header_info[:original_subtitle] = @header[3]
105
+ header_info[:author] = @header[4]
106
+ if process_person(@header[5], header_info) == :author
107
+ raise Aozora2Html::Error, "parser encounted author twice"
108
+ end
109
+ end
110
+ header_info
111
+ end
112
+
113
+ def to_html
114
+ header_info = build_header_info()
115
+
116
+ # <title> 行を構築
117
+ html_title = build_title(header_info)
118
+
119
+ # 出力
120
+ out_buf = []
121
+ out_buf.push("<?xml version=\"1.0\" encoding=\"Shift_JIS\"?>\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"ja\" >\r\n<head>\r\n <meta http-equiv=\"Content-Type\" content=\"text/html;charset=Shift_JIS\" />\r\n <meta http-equiv=\"content-style-type\" content=\"text/css\" />\r\n")
122
+ $css_files.each do |css|
123
+ out_buf.push("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"" + css + "\" />\r\n")
124
+ end
125
+ out_buf.push("\t#{html_title}\r\n <script type=\"text/javascript\" src=\"../../jquery-1.4.2.min.js\"></script>\r\n <link rel=\"Schema.DC\" href=\"http://purl.org/dc/elements/1.1/\" />\r\n <meta name=\"DC.Title\" content=\"#{header_info[:title]}\" />\r\n <meta name=\"DC.Creator\" content=\"#{header_info[:author]}\" />\r\n <meta name=\"DC.Publisher\" content=\"#{AOZORABUNKO}\" />\r\n</head>\r\n<body>\r\n<div class=\"metadata\">\r\n")
126
+ out_buf.push("<h1 class=\"title\">#{header_info[:title]}</h1>\r\n" +
127
+ out_header_info(header_info, :original_title) +
128
+ out_header_info(header_info, :subtitle) +
129
+ out_header_info(header_info, :original_subtitle) +
130
+ out_header_info(header_info, :author) +
131
+ out_header_info(header_info, :editor) +
132
+ out_header_info(header_info, :translator) +
133
+ out_header_info(header_info, :henyaku, "editor-translator"))
134
+ out_buf.push("<br />\r\n<br />\r\n</div>\r\n<div id=\"contents\" style=\"display:none\"></div><div class=\"main_text\">")
135
+ out_buf.join("")
136
+ end
137
+
138
+ end
139
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ class Aozora2Html
3
+ class I18n
4
+ MSG = {
5
+ :tag_syntax_error => "注記を重ねる際の原則、「狭い範囲を先に、広い範囲を後に」が守られていません。リンク先の指針を参考に、書き方をあらためてください",
6
+ :undefined_header => "未定義な見出しです",
7
+ :use_crlf => "改行コードを、「CR+LF」にあらためてください",
8
+ :error_stop => "エラー(%d行目):%s. \r\n処理を停止します",
9
+ :invalid_font_size => "文字サイズの指定が不正です",
10
+ :unsupported_ruby => "サポートされていない複雑なルビ付けです",
11
+ :warn_onebyte => "警告(%d行目):1バイトの「%s」が使われています",
12
+ :warn_chuki => "警告(%d行目):注記記号の誤用の可能性がある、「%s」が使われています",
13
+ :warn_jis_gaiji => "警告(%d行目):JIS外字「%s」が使われています",
14
+ :dont_crlf_in_style => "%s中に改行されました。改行をまたぐ要素にはブロック表記を用いてください",
15
+ :terminate_in_style => "%s中に本文が終了しました",
16
+ :invalid_closing => "%sを閉じようとしましたが、%s中ではありません",
17
+ :invalid_nesting => "%sを終了しようとしましたが、%s中です",
18
+ :dont_use_double_ruby => "同じ箇所に2つのルビはつけられません",
19
+ :dont_allow_triple_ruby => "1つの単語に3つのルビはつけられません",
20
+ :warn_unexpected_terminator => "警告(%d行目):予期せぬファイル終端",
21
+ :warn_undefined_command => "警告(%d行目):「%s」は未対応のコマンドのため無視します",
22
+ }
23
+
24
+ def self.t(msg, *args)
25
+ (MSG[msg].encode("shift_jis") % args)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,81 @@
1
+ class Aozora2Html
2
+ class RubyBuffer
3
+
4
+ # `|`が来た時に真にする。ルビの親文字のガード用。
5
+ attr_accessor :protected
6
+
7
+ # @ruby_buf内の文字のchar_type
8
+ attr_accessor :char_type
9
+
10
+ def initialize(item=nil)
11
+ clear(item)
12
+ end
13
+
14
+ # バッファの初期化。引数itemがあるときはその1要素のバッファに、
15
+ # 引数がなければ`""`の1要素のバッファにする。
16
+ def clear(item=nil)
17
+ if item
18
+ @ruby_buf = [item]
19
+ else
20
+ @ruby_buf = [""]
21
+ end
22
+ @protected = nil
23
+ @char_type = nil
24
+ end
25
+
26
+ def empty?
27
+ @ruby_buf.empty?
28
+ end
29
+
30
+ def present?
31
+ !empty?
32
+ end
33
+
34
+ def to_a
35
+ @ruby_buf
36
+ end
37
+
38
+ def each(&block)
39
+ @ruby_buf.each(&block)
40
+ end
41
+
42
+ def last
43
+ @ruby_buf.last
44
+ end
45
+
46
+ def push(item)
47
+ @ruby_buf.push(item)
48
+ end
49
+
50
+ def length
51
+ @ruby_buf.length
52
+ end
53
+
54
+ def last_concat(item)
55
+ @ruby_buf.last.concat(item)
56
+ end
57
+
58
+ def last_is_string?
59
+ @ruby_buf.last.is_a?(String)
60
+ end
61
+
62
+ # buffer management
63
+ def dump_into(buffer)
64
+ if @protected
65
+ @ruby_buf.unshift(RUBY_PREFIX)
66
+ @protected = nil
67
+ end
68
+ top = @ruby_buf[0]
69
+ if top.is_a?(String) and buffer.last.is_a?(String)
70
+ buffer.last.concat(top)
71
+ buffer.concat(@ruby_buf[1,@ruby_buf.length])
72
+ else
73
+ buffer.concat(@ruby_buf)
74
+ end
75
+ clear
76
+ buffer
77
+ end
78
+
79
+ end
80
+ end
81
+
@@ -0,0 +1,27 @@
1
+ class Aozora2Html
2
+ class StyleStack
3
+ def initialize
4
+ @stack = []
5
+ end
6
+
7
+ def push(elem)
8
+ @stack.push(elem)
9
+ end
10
+
11
+ def empty?
12
+ @stack.empty?
13
+ end
14
+
15
+ def pop
16
+ @stack.pop
17
+ end
18
+
19
+ def last
20
+ @stack.last
21
+ end
22
+
23
+ def last_command
24
+ @stack.last[0]
25
+ end
26
+ end
27
+ 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
+