arti_mark 0.1.beta3 → 0.1.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -4
- data/README.md +108 -7
- data/lib/arti_mark.rb +30 -35
- data/lib/arti_mark/html/abstract_item_writer.rb +14 -0
- data/lib/arti_mark/html/context.rb +100 -79
- data/lib/arti_mark/html/generator.rb +51 -34
- data/lib/arti_mark/html/header_writer.rb +3 -0
- data/lib/arti_mark/html/pages.rb +56 -0
- data/lib/arti_mark/html/paragraph_writer.rb +52 -0
- data/lib/arti_mark/parser.kpeg +34 -6
- data/lib/arti_mark/parser.kpeg.rb +1015 -128
- data/lib/arti_mark/version.rb +1 -1
- data/spec/arti_mark_spec.rb +338 -82
- data/spec/created_files/.gitignore +1 -0
- data/spec/fixture/test_src_ja.arti +3 -1
- metadata +7 -18
- data/lib/arti_mark/article_parser.rb +0 -12
- data/lib/arti_mark/base_parser.rb +0 -26
- data/lib/arti_mark/block_image_parser.rb +0 -27
- data/lib/arti_mark/command_lexer.rb +0 -83
- data/lib/arti_mark/common_block_parser.rb +0 -36
- data/lib/arti_mark/definition_list_parser.rb +0 -23
- data/lib/arti_mark/div_parser.rb +0 -12
- data/lib/arti_mark/head_parser.rb +0 -20
- data/lib/arti_mark/html/result.rb +0 -27
- data/lib/arti_mark/list_parser.rb +0 -27
- data/lib/arti_mark/ordered_list_parser.rb +0 -14
- data/lib/arti_mark/paragraph_parser.rb +0 -30
- data/lib/arti_mark/section_parser.rb +0 -12
- data/lib/arti_mark/syntax.rb +0 -147
- data/lib/arti_mark/universal_block_parser.rb +0 -10
- data/lib/arti_mark/unordered_list_parser.rb +0 -14
data/lib/arti_mark/syntax.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
module ArtiMark
|
2
|
-
class Syntax
|
3
|
-
include CommandLexer
|
4
|
-
|
5
|
-
attr_accessor :inline_handler, :linecommand_handler
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@inline_handler = Class.new do extend CommandLexer end
|
9
|
-
@linecommand_handler = Class.new do extend CommandLexer end
|
10
|
-
@block_parsers = []
|
11
|
-
@block_parsers <<
|
12
|
-
[
|
13
|
-
Proc.new { |lines| lex_line_command(lines[0])[:cmd] == 'newpage' },
|
14
|
-
Proc.new {
|
15
|
-
|lines, context, syntax|
|
16
|
-
lexed = lex_line_command(lines.shift)
|
17
|
-
if lexed[:params].size > 0
|
18
|
-
title = escape_html lexed[:params].first
|
19
|
-
else
|
20
|
-
title = nil
|
21
|
-
end
|
22
|
-
context.start_html(title)
|
23
|
-
}
|
24
|
-
]
|
25
|
-
|
26
|
-
[DivParser.instance, ArticleParser.instance, ParagraphParser.instance, HeadParser.instance, BlockImageParser.instance, OrderedListParser.instance, UnorderedListParser.instance, DefinitionListParser.instance].each {
|
27
|
-
|parser|
|
28
|
-
@block_parsers << [
|
29
|
-
parser.method(:accept?),
|
30
|
-
parser.method(:parse)
|
31
|
-
]
|
32
|
-
}
|
33
|
-
def @inline_handler.l(lexed, context)
|
34
|
-
ref = lexed[:params][0].strip
|
35
|
-
"<a#{ids_string(lexed[:ids])}#{class_string(lexed[:cls])} href='#{ref}'>#{lexed[:text].strip}</a>"
|
36
|
-
end
|
37
|
-
|
38
|
-
def @inline_handler.link(lexed, context)
|
39
|
-
l(lexed, context)
|
40
|
-
end
|
41
|
-
|
42
|
-
def @inline_handler.s(lexed, context)
|
43
|
-
cls, text = lexed[:cls], lexed[:text]
|
44
|
-
"<span#{ids_string(lexed[:ids])}#{class_string(cls)}>#{text.strip}</span>"
|
45
|
-
end
|
46
|
-
|
47
|
-
def @inline_handler.img(lexed, context)
|
48
|
-
cls, param, text = lexed[:cls], lexed[:params], lexed[:text]
|
49
|
-
"<img#{ids_string(lexed[:ids])}#{class_string(cls)} src='#{text.strip}' alt='#{param.join(' ')}' />"
|
50
|
-
end
|
51
|
-
|
52
|
-
def @inline_handler.ruby(lexed, context)
|
53
|
-
cls, param, text = lexed[:cls], lexed[:params], lexed[:text]
|
54
|
-
"<ruby#{ids_string(lexed[:ids])}#{class_string(cls)}>#{text.strip}<rp>(</rp><rt>#{param.join}</rt><rp>)</rp></ruby>"
|
55
|
-
end
|
56
|
-
|
57
|
-
def @inline_handler.tcy(lexed, context)
|
58
|
-
cls, text = lexed[:cls], lexed[:text]
|
59
|
-
cls << 'tcy'
|
60
|
-
"<span#{ids_string(lexed[:ids])}#{class_string(cls)}>#{text.strip}</span>"
|
61
|
-
end
|
62
|
-
|
63
|
-
# universal inline command handler
|
64
|
-
def @inline_handler.method_missing(cmd, *args)
|
65
|
-
ids, cls, text = args[0][:ids], args[0][:cls], args[0][:text]
|
66
|
-
"<#{cmd}#{ids_string(ids)}#{class_string(cls)}>#{text.strip}</#{cmd}>"
|
67
|
-
end
|
68
|
-
|
69
|
-
def @linecommand_handler.p(lexed, context)
|
70
|
-
cls, text = lexed[:cls], lexed[:text]
|
71
|
-
"<p#{ids_string(lexed[:ids])}#{class_string(cls)}>#{text.strip}</p>\n"
|
72
|
-
end
|
73
|
-
|
74
|
-
def @linecommand_handler.stylesheets(lexed, context)
|
75
|
-
context.stylesheets = lexed[:text].split(',').map {|s|
|
76
|
-
s.strip!
|
77
|
-
if s =~ /^(.+?\.css):\((.+?)\)$/
|
78
|
-
[$1, $2]
|
79
|
-
else
|
80
|
-
s
|
81
|
-
end
|
82
|
-
}
|
83
|
-
''
|
84
|
-
end
|
85
|
-
|
86
|
-
def @linecommand_handler.title(lexed, context)
|
87
|
-
context.title = lexed[:text].strip
|
88
|
-
''
|
89
|
-
end
|
90
|
-
|
91
|
-
def @linecommand_handler.lang(lexed, context)
|
92
|
-
context.lang = lexed[:text].strip
|
93
|
-
''
|
94
|
-
end
|
95
|
-
|
96
|
-
#univarsal line command handler
|
97
|
-
def @linecommand_handler.method_missing(cmd, *args)
|
98
|
-
"<#{cmd}#{ids_string(args[0][:ids])}#{class_string(args[0][:cls])}>#{args[0][:text].strip}</#{cmd}>\n"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def determine_parser(lines, opt = {})
|
103
|
-
@block_parsers.each {
|
104
|
-
|accept, parser|
|
105
|
-
return parser if accept.call(lines)
|
106
|
-
}
|
107
|
-
|
108
|
-
if UniversalBlockParser.instance.accept?(lines)
|
109
|
-
UniversalBlockParser.instance.method(:parse)
|
110
|
-
elsif opt[:get_default]
|
111
|
-
default_parser
|
112
|
-
else
|
113
|
-
nil
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def append_parser(parser)
|
118
|
-
if parser.respond_to?(:accept?) && parser.respond_to?(:parse)
|
119
|
-
@block_parsers << [
|
120
|
-
parser.method(:accept?),
|
121
|
-
parser.method(:parse)
|
122
|
-
]
|
123
|
-
elsif parser[:accept?] && parser[:parse]
|
124
|
-
@block_parsers << [
|
125
|
-
parser[:accept?],
|
126
|
-
parser[:parse]
|
127
|
-
]
|
128
|
-
else
|
129
|
-
raise 'parser should define accept? and parse' if !(parser.respond_to?(:accept?) && parser.respond_to?(:parse))
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def default_parser
|
134
|
-
ParagraphParser.instance.method(:parse)
|
135
|
-
end
|
136
|
-
|
137
|
-
def parse(lines, context)
|
138
|
-
throw "something wrong: #{lines}" if lines[0] == '}' # TODO: should do something here with paragraph_parser
|
139
|
-
if parser = determine_parser(lines)
|
140
|
-
parser.call(lines, context, self)
|
141
|
-
else
|
142
|
-
default_parser.call(lines, context, self)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
147
|
-
end
|