aozora2html 0.7.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/aozora2html +3 -50
- data/lib/aozora2html.rb +0 -4
- 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 +17 -0
- data/lib/aozora2html/ruby_buffer.rb +81 -0
- data/lib/aozora2html/style_stack.rb +27 -0
- data/lib/aozora2html/tag.rb +55 -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_parser.rb +53 -0
- data/lib/aozora2html/utils.rb +82 -0
- data/lib/aozora2html/version.rb +1 -1
- data/lib/aozora2html/yaml_loader.rb +31 -0
- data/lib/extensions.rb +31 -0
- data/lib/jstream.rb +68 -0
- data/lib/t2hs.rb +485 -1490
- data/test/test_aozora2html.rb +161 -57
- 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 +8 -7
- data/test/test_gaiji_tag.rb +14 -7
- data/test/test_header.rb +60 -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 +12 -11
- 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 +116 -0
- data/test/test_ruby_tag.rb +5 -4
- data/test/test_tag_parser.rb +10 -10
- data/yml/accent_table.yml +240 -0
- data/yml/command_table.yml +61 -0
- data/yml/jis2ucs.yml +11234 -0
- metadata +63 -6
- 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,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,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,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,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
|