arti_mark 0.0.1.beta1 → 0.0.1.beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/arti_mark/context.rb +1 -1
- data/lib/arti_mark/paragraph_parser.rb +6 -4
- data/lib/arti_mark/syntax.rb +5 -0
- data/lib/arti_mark/version.rb +1 -1
- data/spec/arti_mark_spec.rb +28 -11
- metadata +1 -1
data/lib/arti_mark/context.rb
CHANGED
@@ -11,17 +11,19 @@ module ArtiMark
|
|
11
11
|
def parse(lines, context, syntax)
|
12
12
|
lines.shift while lines[0].size == 0
|
13
13
|
return unless syntax.determine_parser(lines).nil?
|
14
|
-
context << process_paragraph_group(lines,
|
14
|
+
context << process_paragraph_group(lines, syntax, context)
|
15
15
|
end
|
16
16
|
|
17
|
-
def process_paragraph_group(lines,
|
18
|
-
paragraph
|
17
|
+
def process_paragraph_group(lines, syntax, context)
|
18
|
+
paragraph = ''
|
19
19
|
while (lines.size > 0 &&
|
20
20
|
lines[0] != '}' && # TODO: is this correct...?
|
21
21
|
syntax.determine_parser(lines).nil?)
|
22
22
|
paragraph << process_line(lines.shift, syntax, context)
|
23
23
|
end
|
24
|
-
paragraph
|
24
|
+
if paragraph.size > 0
|
25
|
+
paragraph = "<div class='pgroup'>\n#{paragraph}</div>\n" if context.enable_pgroup
|
26
|
+
end
|
25
27
|
paragraph
|
26
28
|
end
|
27
29
|
end
|
data/lib/arti_mark/syntax.rb
CHANGED
@@ -83,6 +83,11 @@ module ArtiMark
|
|
83
83
|
''
|
84
84
|
end
|
85
85
|
|
86
|
+
def @linecommand_handler.lang(lexed, context)
|
87
|
+
context.lang = lexed[:text].strip
|
88
|
+
''
|
89
|
+
end
|
90
|
+
|
86
91
|
#univarsal line command handler
|
87
92
|
def @linecommand_handler.method_missing(cmd, *args)
|
88
93
|
"<#{cmd}#{class_string(args[0][:cls])}>#{args[0][:text].strip}</#{cmd}>\n"
|
data/lib/arti_mark/version.rb
CHANGED
data/spec/arti_mark_spec.rb
CHANGED
@@ -438,19 +438,36 @@ describe ArtiMark do
|
|
438
438
|
expect(r.shift.strip).to eq('<dt>definition<></dt><dd><>&</dd>')
|
439
439
|
end
|
440
440
|
it 'should specify stylesheets' do
|
441
|
-
text = "stylesheets:css/default.css, css/specific.css, css/iphone.css:(only screen and (min-device-width : 320px) and (max-device-width : 480px))\ntext."
|
441
|
+
text = "stylesheets:css/default.css, css/specific.css, css/iphone.css:(only screen and (min-device-width : 320px) and (max-device-width : 480px))\n\ntext."
|
442
442
|
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
443
443
|
converted = artimark.convert(text)
|
444
|
-
|
445
|
-
expect(
|
446
|
-
expect(
|
447
|
-
expect(
|
448
|
-
expect(
|
449
|
-
|
450
|
-
|
451
|
-
expect(
|
452
|
-
|
453
|
-
|
444
|
+
head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
|
445
|
+
expect(head.element_children[0].a).to eq ['title', 'the document title']
|
446
|
+
expect(head.element_children[1].a).to eq ["link[rel='stylesheet'][type='text/css'][href='css/default.css']", '']
|
447
|
+
expect(head.element_children[2].a).to eq ["link[rel='stylesheet'][type='text/css'][href='css/specific.css']", '']
|
448
|
+
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
|
+
|
450
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
451
|
+
expect(body.element_children[0].selector_and_childs).to eq(
|
452
|
+
['div.pgroup',
|
453
|
+
['p',
|
454
|
+
'text.']])
|
455
|
+
end
|
456
|
+
|
457
|
+
it 'should specify title' do
|
458
|
+
text = "title:the title of the book in the text.\n\ntext."
|
459
|
+
artimark = ArtiMark::Document.new(:lang => 'ja', :title => 'the document title')
|
460
|
+
converted = artimark.convert(text)
|
461
|
+
head = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:head')
|
462
|
+
expect(head.element_children[0].a).to eq ['title', 'the title of the book in the text.']
|
463
|
+
end
|
464
|
+
|
465
|
+
it 'should specify lang' do
|
466
|
+
text = "lang:ja\n\n日本語 text."
|
467
|
+
artimark = ArtiMark::Document.new(:lang => 'en', :title => 'the document title')
|
468
|
+
converted = artimark.convert(text)
|
469
|
+
root = Nokogiri::XML::Document.parse(converted[0]).root
|
470
|
+
expect(root['lang']).to eq 'ja'
|
454
471
|
end
|
455
472
|
end
|
456
473
|
end
|