arti_mark 0.0.1.beta2 → 0.0.1.beta3
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.
- data/README.md +22 -9
- data/lib/arti_mark/base_parser.rb +1 -0
- data/lib/arti_mark/command_lexer.rb +2 -2
- data/lib/arti_mark/common_block_parser.rb +3 -1
- data/lib/arti_mark/context.rb +14 -0
- data/lib/arti_mark/head_parser_flymake.rb +18 -0
- data/lib/arti_mark/paragraph_parser.rb +3 -3
- data/lib/arti_mark/syntax.rb +7 -1
- data/lib/arti_mark/version.rb +1 -1
- data/lib/arti_mark.rb +13 -1
- data/spec/arti_mark_spec.rb +137 -38
- data/spec/nokogiri_test_helper.rb +2 -2
- metadata +3 -2
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ArtiMark
|
2
2
|
|
3
|
-
ArtiMark is a simple text markup language. It
|
3
|
+
ArtiMark is a simple text markup language. It is designed to create XHTML files for EPUB books. It is optimized for Japanese text for the present.
|
4
4
|
|
5
5
|
**CAUTION This is very early alpha version, so it's not stable at all. Even the markup syntax will change. **
|
6
6
|
|
@@ -8,8 +8,6 @@ I hope it will be partly stable by the end of Feburary, 2013
|
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
Note: This gem is not yet released to rubygems.org.
|
12
|
-
|
13
11
|
Add this line to your application's Gemfile:
|
14
12
|
|
15
13
|
gem 'arti_mark'
|
@@ -26,11 +24,18 @@ Or install it yourself as:
|
|
26
24
|
|
27
25
|
require 'arti_mark'
|
28
26
|
|
29
|
-
document = ArtiMark::Document.new(
|
30
|
-
document.
|
27
|
+
document = ArtiMark::Document.new()
|
28
|
+
document.convert(string_or_io)
|
31
29
|
put document.result[0] # outputs 1st page of converted XHTML file
|
32
30
|
|
33
|
-
|
31
|
+
an example of markup text
|
32
|
+
|
33
|
+
# line begins with # is a comment.
|
34
|
+
# you don't need to indent artimark text.
|
35
|
+
|
36
|
+
lang: en
|
37
|
+
title: test title
|
38
|
+
stylesheets: css/normalize.css, css/main.css
|
34
39
|
|
35
40
|
art {
|
36
41
|
h1: header 1
|
@@ -41,12 +46,20 @@ Source text looks like this.
|
|
41
46
|
|
42
47
|
d.column {
|
43
48
|
This block will produce div.column.
|
44
|
-
Inline commands like [
|
49
|
+
Inline commands like [link(http://github.com/skoji/arti_mark/){this}] and [s.strong{this}] is available.
|
45
50
|
}
|
46
51
|
}
|
47
|
-
|
48
|
-
It is converted to XHTML like this, sorrounded with appropriate html,head and body tags.
|
49
52
|
|
53
|
+
The converted XHTML file
|
54
|
+
|
55
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
56
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
57
|
+
<head>
|
58
|
+
<title> test title</title>
|
59
|
+
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
|
60
|
+
<link rel="stylesheet" type="text/css" href="css/main.css" />
|
61
|
+
</head>
|
62
|
+
<body>
|
50
63
|
<article>
|
51
64
|
<h1>header 1</h1>
|
52
65
|
<div class='pgroup'>
|
@@ -38,8 +38,8 @@ module ArtiMark
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def lex_block_command(line)
|
41
|
-
line =~ /^(\w+?)((?:\.[A-Za-z0-9_\-]+?)*)(?:\((.+?)\))?\s*{\s*$/
|
42
|
-
return { :cmd => $1, :cls => class_array($2), :params => param_array($3)}
|
41
|
+
line =~ /^(\w+?)((?:\.[A-Za-z0-9_\-]+?)*)(?:\((.+?)\))?\s*(?:{(---)?)\s*$/
|
42
|
+
return { :cmd => $1, :cls => class_array($2), :params => param_array($3), :delimiter => $4||''}
|
43
43
|
end
|
44
44
|
|
45
45
|
def replace_inline_commands(line, syntax, context)
|
@@ -12,14 +12,16 @@ module ArtiMark
|
|
12
12
|
lexed = lex_block_command(lines.shift)
|
13
13
|
throw 'something wrong here #{lines}' unless lexed[:cmd] =~ @command
|
14
14
|
@markup = lexed[:cmd] if @markup.nil?
|
15
|
+
r.enter_block(lexed)
|
15
16
|
process_block(lines, r, syntax, lexed[:cls], lexed[:params])
|
17
|
+
r.exit_block(lexed)
|
16
18
|
end
|
17
19
|
|
18
20
|
def process_block(lines, r, syntax, cls_array, params)
|
19
21
|
previous_pgroup , r.enable_pgroup = r.enable_pgroup , false if params.member? 'wo-pgroup'
|
20
22
|
r << "<#{@markup}#{class_string(cls_array)}>\n"
|
21
23
|
while lines.size > 0
|
22
|
-
if lines[0]
|
24
|
+
if r.block_close? lines[0]
|
23
25
|
lines.shift
|
24
26
|
break
|
25
27
|
else
|
data/lib/arti_mark/context.rb
CHANGED
@@ -10,6 +10,7 @@ module ArtiMark
|
|
10
10
|
@stylesheets_alt = param[:stylesheets_alt] || []
|
11
11
|
@enable_pgroup = param[:enable_pgroup] || true
|
12
12
|
@pages = Result.new
|
13
|
+
@block_delimiter_stack = []
|
13
14
|
head_inserter do
|
14
15
|
ret = ""
|
15
16
|
@stylesheets.each { |s|
|
@@ -57,6 +58,19 @@ module ArtiMark
|
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
61
|
+
def enter_block(lexed)
|
62
|
+
@block_delimiter_stack.push(lexed[:delimiter])
|
63
|
+
end
|
64
|
+
|
65
|
+
def exit_block(lexed)
|
66
|
+
@block_delimiter_stack.pop
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def block_close?(line)
|
71
|
+
line == (@block_delimiter_stack.last || '') + '}'
|
72
|
+
end
|
73
|
+
|
60
74
|
def toc=(label)
|
61
75
|
@toc[-1] = label if @toc.size > 0
|
62
76
|
end
|
@@ -0,0 +1,18 @@
|
|
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
|
+
lexed = lex_line_command(lines[0])
|
12
|
+
raise 'HeadParser called for #{lines[0]}' unless lexed[:cmd] =~ /h([1-6])/
|
13
|
+
lines.shift
|
14
|
+
r << "<#{lexed[:cmd]}#{class_string(lexed[:cls])}>#{escape_html lexed[:text].strip}</#{lexed[:cmd]}>\n"
|
15
|
+
r.toc = lexed[:text].strip if lexed[:params].member? 'in-toc'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -17,11 +17,11 @@ module ArtiMark
|
|
17
17
|
def process_paragraph_group(lines, syntax, context)
|
18
18
|
paragraph = ''
|
19
19
|
while (lines.size > 0 &&
|
20
|
-
|
21
|
-
|
20
|
+
!context.block_close?(lines[0]) &&
|
21
|
+
syntax.determine_parser(lines).nil?)
|
22
22
|
paragraph << process_line(lines.shift, syntax, context)
|
23
23
|
end
|
24
|
-
if paragraph.size > 0
|
24
|
+
if paragraph.size > 0
|
25
25
|
paragraph = "<div class='pgroup'>\n#{paragraph}</div>\n" if context.enable_pgroup
|
26
26
|
end
|
27
27
|
paragraph
|
data/lib/arti_mark/syntax.rb
CHANGED
@@ -55,6 +55,12 @@ module ArtiMark
|
|
55
55
|
"<ruby#{class_string(cls)}>#{text.strip}<rp>(</rp><rt>#{param.join}</rt><rp>)</rp></ruby>"
|
56
56
|
end
|
57
57
|
|
58
|
+
def @inline_handler.tcy(lexed, context)
|
59
|
+
cls, text = lexed[:cls], lexed[:text]
|
60
|
+
cls << 'tcy'
|
61
|
+
"<span#{class_string(cls)}>#{text.strip}</span>"
|
62
|
+
end
|
63
|
+
|
58
64
|
# universal inline command handler
|
59
65
|
def @inline_handler.method_missing(cmd, *args)
|
60
66
|
cls, text = args[0][:cls], args[0][:text]
|
@@ -125,4 +131,4 @@ module ArtiMark
|
|
125
131
|
end
|
126
132
|
|
127
133
|
end
|
128
|
-
end
|
134
|
+
end
|
data/lib/arti_mark/version.rb
CHANGED
data/lib/arti_mark.rb
CHANGED
@@ -23,11 +23,23 @@ module ArtiMark
|
|
23
23
|
def initialize(param = {})
|
24
24
|
@context = Context.new(param)
|
25
25
|
@syntax = Syntax.new
|
26
|
+
@preprocessors = [
|
27
|
+
Proc.new { |text| text.gsub(/\r?\n(\r?\n)+/, "\n\n") },
|
28
|
+
Proc.new { |text| text.strip.gsub(/ /, ' ') } # Japanese full-width spece to half space width
|
29
|
+
]
|
26
30
|
end
|
27
31
|
|
32
|
+
def preprocessor(&block)
|
33
|
+
@preprocessors << block
|
34
|
+
end
|
35
|
+
|
28
36
|
def convert(text)
|
37
|
+
@preprocessors.each {
|
38
|
+
|pr|
|
39
|
+
text = pr.call(text)
|
40
|
+
}
|
29
41
|
# split text to lines
|
30
|
-
lines = text.
|
42
|
+
lines = text.split(/\r?\n/).map { |line| line.strip }
|
31
43
|
process_lines(lines, @context)
|
32
44
|
@context.result
|
33
45
|
end
|
data/spec/arti_mark_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe ArtiMark do
|
|
24
24
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
25
25
|
expect(body.element_children.size).to eq 2
|
26
26
|
|
27
|
-
expect(body.element_children[0].
|
27
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
28
28
|
['div.pgroup',
|
29
29
|
['p', 'ここから、パラグラフがはじまります。'],
|
30
30
|
['p.noindent', '「二行目です。」'],
|
@@ -32,7 +32,7 @@ describe ArtiMark do
|
|
32
32
|
]
|
33
33
|
)
|
34
34
|
|
35
|
-
expect(body.element_children[1].
|
35
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
36
36
|
['div.pgroup',
|
37
37
|
['p', 'ここから、次のパラグラフです。']]
|
38
38
|
)
|
@@ -44,13 +44,13 @@ describe ArtiMark do
|
|
44
44
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
45
45
|
expect(body.element_children.size).to eq 5
|
46
46
|
expect(body.element_children[0].a).to eq ['h1', 'タイトルです。']
|
47
|
-
expect(body.element_children[1].
|
47
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
48
48
|
['div.pgroup',
|
49
49
|
['p', 'ここから、パラグラフがはじまります。']
|
50
50
|
]
|
51
51
|
)
|
52
52
|
expect(body.element_children[2].a).to eq ['h2.column', 'ふたつめの見出しです。']
|
53
|
-
expect(body.element_children[3].
|
53
|
+
expect(body.element_children[3].selector_and_children).to eq(
|
54
54
|
['div.pgroup',
|
55
55
|
['p', 'ここから、次のパラグラフです。']
|
56
56
|
]
|
@@ -63,7 +63,21 @@ describe ArtiMark do
|
|
63
63
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
64
64
|
converted = artimark.convert(text)
|
65
65
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
66
|
-
expect(body.element_children[0].
|
66
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
67
|
+
['div',
|
68
|
+
['div.pgroup',
|
69
|
+
['p', '1st line.']
|
70
|
+
]
|
71
|
+
]
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should convert div and paragraph with alternate style' do
|
76
|
+
text = "d {---\n1st line. \n---}"
|
77
|
+
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
78
|
+
converted = artimark.convert(text)
|
79
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
80
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
67
81
|
['div',
|
68
82
|
['div.pgroup',
|
69
83
|
['p', '1st line.']
|
@@ -76,7 +90,7 @@ describe ArtiMark do
|
|
76
90
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
77
91
|
converted = artimark.convert(text)
|
78
92
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
79
|
-
expect(body.element_children[0].
|
93
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
80
94
|
['div',
|
81
95
|
['p', '1st line.']
|
82
96
|
]
|
@@ -88,7 +102,7 @@ describe ArtiMark do
|
|
88
102
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
89
103
|
converted = artimark.convert(text)
|
90
104
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
91
|
-
expect(body.element_children[0].
|
105
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
92
106
|
['div',
|
93
107
|
['div',
|
94
108
|
['p', 'nested.']
|
@@ -102,18 +116,19 @@ describe ArtiMark do
|
|
102
116
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
103
117
|
converted = artimark.convert(text)
|
104
118
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
105
|
-
expect(body.element_children[0].
|
119
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
106
120
|
['div.preface-one',
|
107
121
|
['h1', 'title.']
|
108
122
|
]
|
109
123
|
)
|
110
124
|
end
|
125
|
+
|
111
126
|
it 'should convert nested div' do
|
112
127
|
text = "d.preface {\n outer div. \n d.nested {\n nested!\n}\nouter div again.\n}"
|
113
128
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
114
129
|
converted = artimark.convert(text)
|
115
130
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
116
|
-
expect(body.element_children[0].
|
131
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
117
132
|
['div.preface',
|
118
133
|
['div.pgroup',
|
119
134
|
['p', 'outer div.']
|
@@ -130,12 +145,57 @@ describe ArtiMark do
|
|
130
145
|
)
|
131
146
|
end
|
132
147
|
|
148
|
+
it 'should convert nested div with alternate style inside' do
|
149
|
+
text = "d.preface {\n outer div. \n d.nested {---\n nested!\n---}\nouter div again.\n}"
|
150
|
+
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
151
|
+
converted = artimark.convert(text)
|
152
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
153
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
154
|
+
['div.preface',
|
155
|
+
['div.pgroup',
|
156
|
+
['p', 'outer div.']
|
157
|
+
],
|
158
|
+
['div.nested',
|
159
|
+
['div.pgroup',
|
160
|
+
['p', 'nested!']
|
161
|
+
]
|
162
|
+
],
|
163
|
+
['div.pgroup',
|
164
|
+
['p', 'outer div again.']
|
165
|
+
],
|
166
|
+
]
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should convert nested div with alternate style outside' do
|
171
|
+
text = "d.preface {---\n outer div. \n}\nyou can write curly brace as above.\nd.nested {\n nested!\n}\nouter div again.\n---}"
|
172
|
+
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
173
|
+
converted = artimark.convert(text)
|
174
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
175
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
176
|
+
['div.preface',
|
177
|
+
['div.pgroup',
|
178
|
+
['p', 'outer div.'],
|
179
|
+
['p', '}'],
|
180
|
+
['p', 'you can write curly brace as above.']
|
181
|
+
],
|
182
|
+
['div.nested',
|
183
|
+
['div.pgroup',
|
184
|
+
['p', 'nested!']
|
185
|
+
]
|
186
|
+
],
|
187
|
+
['div.pgroup',
|
188
|
+
['p', 'outer div again.']
|
189
|
+
],
|
190
|
+
]
|
191
|
+
)
|
192
|
+
end
|
133
193
|
it 'should convert article' do
|
134
194
|
text = "art {\n in the article.\n}"
|
135
195
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
136
196
|
converted = artimark.convert(text)
|
137
197
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
138
|
-
expect(body.element_children[0].
|
198
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
139
199
|
['article',
|
140
200
|
['div.pgroup',
|
141
201
|
['p', 'in the article.']
|
@@ -149,12 +209,12 @@ describe ArtiMark do
|
|
149
209
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
150
210
|
converted = artimark.convert(text)
|
151
211
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
152
|
-
expect(body.element_children[0].
|
212
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
153
213
|
['div.pgroup',
|
154
214
|
['p', 'this is normal line.']
|
155
215
|
]
|
156
216
|
)
|
157
|
-
expect(body.element_children[1].
|
217
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
158
218
|
['div.img-wrap',
|
159
219
|
["img[src='./image1.jpg'][alt='alt text']", ''],
|
160
220
|
['p', 'caption text']
|
@@ -168,7 +228,7 @@ describe ArtiMark do
|
|
168
228
|
converted = artimark.convert(text)
|
169
229
|
expect(converted.size).to eq 3
|
170
230
|
body1 = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
171
|
-
expect(body1.element_children[0].
|
231
|
+
expect(body1.element_children[0].selector_and_children).to eq(
|
172
232
|
['div.pgroup',
|
173
233
|
['p', 'this is start.']
|
174
234
|
]
|
@@ -177,7 +237,7 @@ describe ArtiMark do
|
|
177
237
|
head2 = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:head')
|
178
238
|
expect(head2.element_children[0].a).to eq ['title', 'page changed']
|
179
239
|
body2 = Nokogiri::XML::Document.parse(converted[1]).root.at_xpath('xmlns:body')
|
180
|
-
expect(body2.element_children[0].
|
240
|
+
expect(body2.element_children[0].selector_and_children).to eq(
|
181
241
|
['div.pgroup',
|
182
242
|
['p', 'this is second page.']
|
183
243
|
]
|
@@ -186,7 +246,7 @@ describe ArtiMark do
|
|
186
246
|
head3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:head')
|
187
247
|
expect(head3.element_children[0].a).to eq ['title', 'page changed']
|
188
248
|
body3 = Nokogiri::XML::Document.parse(converted[2]).root.at_xpath('xmlns:body')
|
189
|
-
expect(body3.element_children[0].
|
249
|
+
expect(body3.element_children[0].selector_and_children).to eq(
|
190
250
|
['div.pgroup',
|
191
251
|
['p', 'and the third.']
|
192
252
|
]
|
@@ -208,7 +268,7 @@ describe ArtiMark do
|
|
208
268
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
209
269
|
converted = artimark.convert(text)
|
210
270
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
211
|
-
expect(body.element_children[0].
|
271
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
212
272
|
['div.pgroup',
|
213
273
|
['p',
|
214
274
|
'link to ',
|
@@ -224,7 +284,7 @@ describe ArtiMark do
|
|
224
284
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
225
285
|
converted = artimark.convert(text)
|
226
286
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
227
|
-
expect(body.element_children[0].
|
287
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
228
288
|
['div.pgroup',
|
229
289
|
['p',
|
230
290
|
'link to ',
|
@@ -240,7 +300,7 @@ describe ArtiMark do
|
|
240
300
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
241
301
|
converted = artimark.convert(text)
|
242
302
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
243
|
-
expect(body.element_children[0].
|
303
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
244
304
|
['div.pgroup',
|
245
305
|
['p', 'this is normal line.'],
|
246
306
|
['p.custom', 'this text is in custom class.']
|
@@ -252,7 +312,7 @@ describe ArtiMark do
|
|
252
312
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
253
313
|
converted = artimark.convert(text)
|
254
314
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
255
|
-
expect(body.element_children[0].
|
315
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
256
316
|
['div.pgroup',
|
257
317
|
['p.custom', 'this text is in ', ['span.keyword', 'custom'], ' class.'
|
258
318
|
]]
|
@@ -263,12 +323,12 @@ describe ArtiMark do
|
|
263
323
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
264
324
|
converted = artimark.convert(text)
|
265
325
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
266
|
-
expect(body.element_children[0].
|
326
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
267
327
|
['div.pgroup',
|
268
328
|
['p', 'this is normal line.']
|
269
329
|
]
|
270
330
|
)
|
271
|
-
expect(body.element_children[1].
|
331
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
272
332
|
['cite',
|
273
333
|
['div.pgroup',
|
274
334
|
['p', 'this block should be in cite.']
|
@@ -281,7 +341,7 @@ describe ArtiMark do
|
|
281
341
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
282
342
|
converted = artimark.convert(text)
|
283
343
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
284
|
-
expect(body.element_children[0].
|
344
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
285
345
|
['div.pgroup',
|
286
346
|
['p',
|
287
347
|
'simple image ', ["img[src='./image1.jpg'][alt='caption']", ''], '.']]
|
@@ -289,23 +349,16 @@ describe ArtiMark do
|
|
289
349
|
end
|
290
350
|
|
291
351
|
it 'should handle any inline' do
|
292
|
-
text = "
|
352
|
+
text = "should be [strong{marked as strong}]."
|
293
353
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
294
354
|
converted = artimark.convert(text)
|
295
|
-
|
296
|
-
expect(
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
expect(r.shift.strip).to eq('</head>')
|
301
|
-
expect(r.shift.strip).to eq('<body>')
|
302
|
-
expect(r.shift.strip).to eq("<div class='pgroup'>")
|
303
|
-
expect(r.shift.strip).to eq("<p>this is normal line.</p>")
|
304
|
-
expect(r.shift.strip).to eq("<p>in this line, this should be <strong>marked as strong</strong>.</p>")
|
305
|
-
expect(r.shift.strip).to eq("</div>")
|
306
|
-
expect(r.shift.strip).to eq("</body>")
|
307
|
-
expect(r.shift.strip).to eq("</html>")
|
355
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
356
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
357
|
+
['div.pgroup',
|
358
|
+
['p', 'should be ', ['strong', 'marked as strong'],'.']]
|
359
|
+
)
|
308
360
|
end
|
361
|
+
|
309
362
|
it 'should generate toc: with newpage parameter' do
|
310
363
|
text = "newpage(1st chapter):\n1st chapter.\nnewpage(2nd chapter):\n2nd chapger.\nnewpage: 2nd chapter continued.\nnewpage(3rd chapter):\n3rd chapter."
|
311
364
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
@@ -345,7 +398,16 @@ describe ArtiMark do
|
|
345
398
|
expect(r.shift.strip).to eq("</body>")
|
346
399
|
expect(r.shift.strip).to eq("</html>")
|
347
400
|
end
|
348
|
-
|
401
|
+
it 'should handle tatechuyoko' do
|
402
|
+
text = "[tcy{10}]年前のことだった"
|
403
|
+
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
404
|
+
converted = artimark.convert(text)
|
405
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
406
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
407
|
+
['div.pgroup',
|
408
|
+
['p', ['span.tcy', '10'], '年前のことだった']
|
409
|
+
])
|
410
|
+
end
|
349
411
|
|
350
412
|
it 'should handle ordered list ' do
|
351
413
|
text = "this is normal line.\n1: for the 1st.\n2: secondly, blah.\n3: and last...\nthe ordered list ends."
|
@@ -448,7 +510,7 @@ describe ArtiMark do
|
|
448
510
|
expect(head.element_children[3].a).to eq ["link[rel='stylesheet'][type='text/css'][media='only screen and (min-device-width : 320px) and (max-device-width : 480px)'][href='css/iphone.css']", '']
|
449
511
|
|
450
512
|
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
451
|
-
expect(body.element_children[0].
|
513
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
452
514
|
['div.pgroup',
|
453
515
|
['p',
|
454
516
|
'text.']])
|
@@ -469,6 +531,43 @@ describe ArtiMark do
|
|
469
531
|
root = Nokogiri::XML::Document.parse(converted[0]).root
|
470
532
|
expect(root['lang']).to eq 'ja'
|
471
533
|
end
|
534
|
+
|
535
|
+
it 'should ignore comments' do
|
536
|
+
text = "#この行はコメントです\nここから、パラグラフがはじまります。\n#これもコメント\n「二行目です。」\n三行目です。\n\n#これもコメント\n\n ここから、次のパラグラフです。"
|
537
|
+
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
538
|
+
converted = artimark.convert(text)
|
539
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
540
|
+
expect(body.element_children.size).to eq 2
|
541
|
+
|
542
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
543
|
+
['div.pgroup',
|
544
|
+
['p', 'ここから、パラグラフがはじまります。'],
|
545
|
+
['p.noindent', '「二行目です。」'],
|
546
|
+
['p', '三行目です。']
|
547
|
+
]
|
548
|
+
)
|
549
|
+
|
550
|
+
expect(body.element_children[1].selector_and_children).to eq(
|
551
|
+
['div.pgroup',
|
552
|
+
['p', 'ここから、次のパラグラフです。']]
|
553
|
+
)
|
554
|
+
end
|
555
|
+
|
556
|
+
it 'should handle preprocessor' do
|
557
|
+
text = "pre-preprocess text"
|
558
|
+
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
559
|
+
artimark.preprocessor do
|
560
|
+
|text|
|
561
|
+
text.gsub('pre-preprocess', 'post-process')
|
562
|
+
end
|
563
|
+
converted = artimark.convert(text)
|
564
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
565
|
+
expect(body.element_children[0].selector_and_children).to eq(
|
566
|
+
['div.pgroup',
|
567
|
+
['p', 'post-process text'],
|
568
|
+
]
|
569
|
+
)
|
570
|
+
end
|
472
571
|
end
|
473
572
|
end
|
474
573
|
|
@@ -25,14 +25,14 @@ module Nokogiri
|
|
25
25
|
def child_a(index)
|
26
26
|
element_children[index].selector_and_text
|
27
27
|
end
|
28
|
-
def
|
28
|
+
def selector_and_children
|
29
29
|
[selector] + children.select{|c| c.elem? || c.text.strip.size > 0}.map{|c|
|
30
30
|
if !c.elem?
|
31
31
|
c.text
|
32
32
|
elsif c.element_children.size == 0
|
33
33
|
c.selector_and_text
|
34
34
|
else
|
35
|
-
c.
|
35
|
+
c.selector_and_children
|
36
36
|
end
|
37
37
|
}
|
38
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arti_mark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta3
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/arti_mark/definition_list_parser.rb
|
67
67
|
- lib/arti_mark/div_parser.rb
|
68
68
|
- lib/arti_mark/head_parser.rb
|
69
|
+
- lib/arti_mark/head_parser_flymake.rb
|
69
70
|
- lib/arti_mark/list_parser.rb
|
70
71
|
- lib/arti_mark/ordered_list_parser.rb
|
71
72
|
- lib/arti_mark/paragraph_parser.rb
|