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,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,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,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,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,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(@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,82 @@
|
|
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
|
+
end
|
81
|
+
end
|
82
|
+
|