arti_mark 0.1.beta3 → 0.1.beta5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1 @@
|
|
1
|
+
*.xhtml
|
@@ -1,3 +1,4 @@
|
|
1
|
+
title: the sample text
|
1
2
|
sect.preface {
|
2
3
|
h1: 前書き
|
3
4
|
前書きのようなものをここでかく。
|
@@ -7,6 +8,7 @@ h1: 前書き
|
|
7
8
|
newpage:
|
8
9
|
|
9
10
|
art.main {
|
11
|
+
|
10
12
|
h1: 本文
|
11
13
|
ここからが本文。
|
12
14
|
チェックする項目は
|
@@ -31,7 +33,7 @@ h1: 本文
|
|
31
33
|
|
32
34
|
コマンドについて説明する。
|
33
35
|
|
34
|
-
;:コマンド文字列: <コマンド名>[
|
36
|
+
;:コマンド文字列: <コマンド名>[#id名]*[.クラス名]*[(パラメータ)]
|
35
37
|
;: 行コマンド : 行先頭に、<コマンド文字列>: がくる。続く行末までの文字が処理対象となる。p/h以外のブロック要素を生成する行コマンドは、暗黙のブロックを中断する。
|
36
38
|
;: ブロックコマンド : 行先頭に<コマンド文字列>{ がくる。その行では文字を続けない。} 単独の行で閉じる。
|
37
39
|
;: インラインコマンド : 行の途中にあらわれる[<コマンド文字列>{<文字>}] の列。
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arti_mark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.beta5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KOJIMA Satoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02
|
11
|
+
date: 2014-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kpeg
|
@@ -67,33 +67,21 @@ files:
|
|
67
67
|
- Rakefile
|
68
68
|
- arti_mark.gemspec
|
69
69
|
- lib/arti_mark.rb
|
70
|
-
- lib/arti_mark/
|
71
|
-
- lib/arti_mark/base_parser.rb
|
72
|
-
- lib/arti_mark/block_image_parser.rb
|
73
|
-
- lib/arti_mark/command_lexer.rb
|
74
|
-
- lib/arti_mark/common_block_parser.rb
|
75
|
-
- lib/arti_mark/definition_list_parser.rb
|
76
|
-
- lib/arti_mark/div_parser.rb
|
77
|
-
- lib/arti_mark/head_parser.rb
|
70
|
+
- lib/arti_mark/html/abstract_item_writer.rb
|
78
71
|
- lib/arti_mark/html/context.rb
|
79
72
|
- lib/arti_mark/html/generator.rb
|
80
73
|
- lib/arti_mark/html/header_writer.rb
|
81
|
-
- lib/arti_mark/html/
|
74
|
+
- lib/arti_mark/html/pages.rb
|
75
|
+
- lib/arti_mark/html/paragraph_writer.rb
|
82
76
|
- lib/arti_mark/html/tag_writer.rb
|
83
77
|
- lib/arti_mark/html/util.rb
|
84
78
|
- lib/arti_mark/html/writer_selector.rb
|
85
|
-
- lib/arti_mark/list_parser.rb
|
86
|
-
- lib/arti_mark/ordered_list_parser.rb
|
87
|
-
- lib/arti_mark/paragraph_parser.rb
|
88
79
|
- lib/arti_mark/parser.kpeg
|
89
80
|
- lib/arti_mark/parser.kpeg.rb
|
90
81
|
- lib/arti_mark/parser.rb
|
91
|
-
- lib/arti_mark/section_parser.rb
|
92
|
-
- lib/arti_mark/syntax.rb
|
93
|
-
- lib/arti_mark/universal_block_parser.rb
|
94
|
-
- lib/arti_mark/unordered_list_parser.rb
|
95
82
|
- lib/arti_mark/version.rb
|
96
83
|
- spec/arti_mark_spec.rb
|
84
|
+
- spec/created_files/.gitignore
|
97
85
|
- spec/fixture/test_src_ja.arti
|
98
86
|
- spec/nokogiri_test_helper.rb
|
99
87
|
- spec/spec_helper.rb
|
@@ -122,6 +110,7 @@ specification_version: 4
|
|
122
110
|
summary: simple and customizable text markup language for EPUB
|
123
111
|
test_files:
|
124
112
|
- spec/arti_mark_spec.rb
|
113
|
+
- spec/created_files/.gitignore
|
125
114
|
- spec/fixture/test_src_ja.arti
|
126
115
|
- spec/nokogiri_test_helper.rb
|
127
116
|
- spec/spec_helper.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
module ArtiMark
|
3
|
-
module BaseParser
|
4
|
-
include CommandLexer
|
5
|
-
|
6
|
-
|
7
|
-
def paragraph(line, syntax, cls_array = [])
|
8
|
-
if line =~/^(「|『|()/ # TODO: should be plaggable
|
9
|
-
cls_array << 'noindent'
|
10
|
-
end
|
11
|
-
"<p#{class_string(cls_array)}>#{line}</p>\n"
|
12
|
-
end
|
13
|
-
|
14
|
-
def process_line(line, syntax, context)
|
15
|
-
return '' if line =~ /^#.*$/
|
16
|
-
line = escape_html line
|
17
|
-
line = replace_inline_commands(line, syntax, context)
|
18
|
-
lexed = lex_line_command(line)
|
19
|
-
if !lexed[:cmd].nil? && syntax.linecommand_handler.respond_to?(lexed[:cmd].to_sym)
|
20
|
-
syntax.linecommand_handler.send(lexed[:cmd], lexed, context)
|
21
|
-
else
|
22
|
-
paragraph(line, syntax)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
#require 'singleton'
|
2
|
-
|
3
|
-
module ArtiMark
|
4
|
-
class BlockImageParser
|
5
|
-
include BaseParser, Singleton
|
6
|
-
def accept?(lines)
|
7
|
-
lex_line_command(lines[0])[:cmd] =~ /image/
|
8
|
-
end
|
9
|
-
|
10
|
-
def parse(lines, r, syntax)
|
11
|
-
lexed = lex_line_command(lines[0])
|
12
|
-
raise 'HeadParser called for #{lines[0]}' unless lexed[:cmd] =~ /image/
|
13
|
-
lines.shift
|
14
|
-
lexed[:cls] << 'img-wrap' if lexed[:cls].size == 0
|
15
|
-
src = lexed[:params][0].strip
|
16
|
-
alt = lexed[:params][1].strip if !lexed[:params][1].nil?
|
17
|
-
caption = lexed[:text].strip
|
18
|
-
caption_before = lexed[:named_params][:caption_before]
|
19
|
-
|
20
|
-
r << "<div#{ids_string(lexed[:ids])}#{class_string(lexed[:cls])}>"
|
21
|
-
r << "<p>#{caption}</p>" if !caption.nil? && caption.size > 0 && caption_before
|
22
|
-
r << "<img src='#{src}' alt='#{escape_html alt}' />"
|
23
|
-
r << "<p>#{escape_html caption}</p>" if !caption.nil? && caption.size > 0 && !caption_before
|
24
|
-
r << "</div>\n"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
module ArtiMark
|
3
|
-
module CommandLexer
|
4
|
-
def escape_html(string)
|
5
|
-
string.to_s.gsub("&", "&").
|
6
|
-
gsub("<", "<").
|
7
|
-
gsub(">", ">").
|
8
|
-
gsub('"', """)
|
9
|
-
end
|
10
|
-
|
11
|
-
def attr_string(the_array, attr_name)
|
12
|
-
if the_array.size == 0
|
13
|
-
''
|
14
|
-
else
|
15
|
-
" #{attr_name}='#{the_array.join(' ')}'"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def class_string(cls_array)
|
20
|
-
attr_string(cls_array, 'class')
|
21
|
-
end
|
22
|
-
|
23
|
-
def ids_string(ids_array)
|
24
|
-
attr_string(ids_array, 'id')
|
25
|
-
end
|
26
|
-
def attr_array(part, separator=".")
|
27
|
-
the_array = []
|
28
|
-
if !part.nil? && part.size > 0
|
29
|
-
the_array = part[1..-1].split(separator)
|
30
|
-
end
|
31
|
-
the_array
|
32
|
-
end
|
33
|
-
def id_array(id_part)
|
34
|
-
attr_array(id_part, '#')
|
35
|
-
end
|
36
|
-
|
37
|
-
def class_array(cls_part)
|
38
|
-
attr_array(cls_part, '.')
|
39
|
-
end
|
40
|
-
|
41
|
-
def param_parse(param_part)
|
42
|
-
r = []
|
43
|
-
named = {}
|
44
|
-
if !param_part.nil? && param_part.size > 0
|
45
|
-
r = param_part.split(',')
|
46
|
-
end
|
47
|
-
r.each {
|
48
|
-
|param|
|
49
|
-
splitted = param.split(':', 2)
|
50
|
-
if (splitted.size == 2)
|
51
|
-
named[splitted[0].strip.to_sym] = splitted[1]
|
52
|
-
end
|
53
|
-
}
|
54
|
-
return r, named
|
55
|
-
end
|
56
|
-
|
57
|
-
def lex_line_command(line)
|
58
|
-
line =~ /^([\w\*;]+?)((?:\#[A-Za-z0-9_\-]+?)*)((?:\.[A-Za-z0-9_\-]+?)*)(?:\((.+?)\))?\s*:(.*?)$/
|
59
|
-
all_params, named_params = param_parse($4)
|
60
|
-
return { :cmd => $1, :ids => id_array($2), :cls => class_array($3), :params => all_params, :named_params => named_params, :text => $5 }
|
61
|
-
end
|
62
|
-
|
63
|
-
def lex_block_command(line)
|
64
|
-
line =~ /^(\w+?)((?:\#[A-Za-z0-9_\-]+?)*)((?:\.[A-Za-z0-9_\-]+?)*)(?:\((.+?)\))?\s*(?:{(---)?)\s*$/
|
65
|
-
not_named, named = param_parse($4)
|
66
|
-
return { :cmd => $1, :ids => id_array($2), :cls => class_array($3), :params => not_named, :named_params => named, :delimiter => $5||''}
|
67
|
-
end
|
68
|
-
|
69
|
-
def replace_inline_commands(line, syntax, context)
|
70
|
-
line.gsub(/\[(\w+?)((?:\#[A-Za-z0-9_\-]+?)*)((?:\.[A-Za-z0-9_\-]+?)*)(?:\((.+?)\))?\s*{(.*?)}\]/) {
|
71
|
-
|matched|
|
72
|
-
not_named, named = param_parse($4)
|
73
|
-
lexed = {:cmd => $1, :ids => id_array($2), :cls => class_array($3), :params => not_named, :named_params => named, :text => $5 }
|
74
|
-
if !lexed[:cmd].nil?
|
75
|
-
syntax.inline_handler.send(lexed[:cmd], lexed, context)
|
76
|
-
else
|
77
|
-
matched
|
78
|
-
end
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'singleton'
|
3
|
-
|
4
|
-
module ArtiMark
|
5
|
-
module CommonBlockParser
|
6
|
-
include BaseParser
|
7
|
-
def accept?(lines)
|
8
|
-
lex_block_command(lines[0])[:cmd] =~ @command
|
9
|
-
end
|
10
|
-
|
11
|
-
def parse(lines, r, syntax)
|
12
|
-
lexed = lex_block_command(lines.shift)
|
13
|
-
throw 'something wrong here #{lines}' unless lexed[:cmd] =~ @command
|
14
|
-
@markup = lexed[:cmd] if @markup.nil?
|
15
|
-
r.enter_block(lexed)
|
16
|
-
process_block(lines, r, syntax, lexed[:ids], lexed[:cls], lexed[:params])
|
17
|
-
r.exit_block(lexed)
|
18
|
-
end
|
19
|
-
|
20
|
-
def process_block(lines, r, syntax, ids_array, cls_array, params)
|
21
|
-
previous_pgroup , r.enable_pgroup = r.enable_pgroup , false if params.member? 'wo-pgroup'
|
22
|
-
r << "<#{@markup}#{ids_string(ids_array)}#{class_string(cls_array)}>\n"
|
23
|
-
while lines.size > 0
|
24
|
-
if r.block_close? lines[0]
|
25
|
-
lines.shift
|
26
|
-
break
|
27
|
-
else
|
28
|
-
syntax.determine_parser(lines, :get_default => true).call(lines, r, syntax)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
r << "</#{@markup}>\n"
|
32
|
-
r.enable_pgroup = previous_pgroup if !previous_pgroup.nil?
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'singleton'
|
3
|
-
|
4
|
-
module ArtiMark
|
5
|
-
class DefinitionListParser
|
6
|
-
include ListParser, Singleton
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@cmd = /;/
|
10
|
-
@blockname = 'dl'
|
11
|
-
end
|
12
|
-
|
13
|
-
def process_block(lines, r, syntax)
|
14
|
-
while lines.size > 0
|
15
|
-
lexed = lex_line_command(lines[0])
|
16
|
-
return unless lexed[:cmd] =~ @cmd
|
17
|
-
dt, dd = lexed[:text].split(':', 2).map(&:strip)
|
18
|
-
r << "<dt>#{escape_html dt}</dt><dd>#{escape_html dd}</dd>\n"
|
19
|
-
lines.shift
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/arti_mark/div_parser.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
#require 'singleton'
|
2
|
-
|
3
|
-
module ArtiMark
|
4
|
-
class HeadParser
|
5
|
-
include BaseParser, Singleton
|
6
|
-
def accept?(lines)
|
7
|
-
lex_line_command(lines[0])[:cmd] =~ /h[1-6]/
|
8
|
-
end
|
9
|
-
|
10
|
-
def parse(lines, r, syntax)
|
11
|
-
line = escape_html lines[0]
|
12
|
-
line = replace_inline_commands(line, syntax, r)
|
13
|
-
lexed = lex_line_command(line)
|
14
|
-
raise 'HeadParser called for #{lines[0]}' unless lexed[:cmd] =~ /h([1-6])/
|
15
|
-
lines.shift
|
16
|
-
r << "<#{lexed[:cmd]}#{ids_string(lexed[:ids])}#{class_string(lexed[:cls])}>#{lexed[:text].strip}</#{lexed[:cmd]}>\n"
|
17
|
-
r.toc = lexed[:text].strip if lexed[:params].member? 'in-toc'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module ArtiMark
|
2
|
-
module Html
|
3
|
-
class Context
|
4
|
-
class Result < Array
|
5
|
-
def initialize
|
6
|
-
super
|
7
|
-
end
|
8
|
-
|
9
|
-
def write_as_files(prefix, format='%03d')
|
10
|
-
self.each_with_index {
|
11
|
-
|converted, i|
|
12
|
-
File.open("#{prefix}_#{format%(i+1)}.xhtml", 'w+') {
|
13
|
-
|file|
|
14
|
-
file << converted
|
15
|
-
}
|
16
|
-
}
|
17
|
-
end
|
18
|
-
def write_as_single_file(filename)
|
19
|
-
File.open(filename, 'w+') {
|
20
|
-
|file|
|
21
|
-
file << self[0]
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
module ArtiMark
|
4
|
-
module ListParser
|
5
|
-
include BaseParser
|
6
|
-
|
7
|
-
def accept?(lines)
|
8
|
-
lex_line_command(lines[0])[:cmd] =~ @cmd
|
9
|
-
end
|
10
|
-
|
11
|
-
def parse(lines, r, syntax)
|
12
|
-
lexed = lex_line_command(lines[0])
|
13
|
-
r << "<#{@blockname}#{ids_string(lexed[:ids])}#{class_string(lexed[:cls])}>\n"
|
14
|
-
process_block(lines, r, syntax)
|
15
|
-
r << "</#{@blockname}>\n"
|
16
|
-
end
|
17
|
-
|
18
|
-
def process_block(lines, r, syntax)
|
19
|
-
while lines.size > 0
|
20
|
-
lexed = lex_line_command(lines[0])
|
21
|
-
return unless lexed[:cmd] =~ @cmd
|
22
|
-
r << "<li>#{escape_html lexed[:text].strip}</li>\n"
|
23
|
-
lines.shift
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'singleton'
|
3
|
-
|
4
|
-
module ArtiMark
|
5
|
-
class ParagraphParser
|
6
|
-
include BaseParser, Singleton
|
7
|
-
|
8
|
-
def accept?(lines)
|
9
|
-
lines[0].size == 0
|
10
|
-
end
|
11
|
-
def parse(lines, context, syntax)
|
12
|
-
lines.shift while lines[0].size == 0
|
13
|
-
return unless syntax.determine_parser(lines).nil?
|
14
|
-
context << process_paragraph_group(lines, syntax, context)
|
15
|
-
end
|
16
|
-
|
17
|
-
def process_paragraph_group(lines, syntax, context)
|
18
|
-
paragraph = ''
|
19
|
-
while (lines.size > 0 &&
|
20
|
-
!context.block_close?(lines[0]) &&
|
21
|
-
syntax.determine_parser(lines).nil?)
|
22
|
-
paragraph << process_line(lines.shift, syntax, context)
|
23
|
-
end
|
24
|
-
if paragraph.size > 0
|
25
|
-
paragraph = "<div class='pgroup'>\n#{paragraph}</div>\n" if context.enable_pgroup
|
26
|
-
end
|
27
|
-
paragraph
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|