arti_mark 0.0.1.beta1 → 0.0.1.beta2

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.
@@ -1,6 +1,6 @@
1
1
  module ArtiMark
2
2
  class Context
3
- attr_accessor :title, :head_inserters, :toc, :stylesheets, :enable_pgroup
3
+ attr_accessor :title, :head_inserters, :toc, :lang, :stylesheets, :enable_pgroup
4
4
  def initialize(param = {})
5
5
  @head_inserters = []
6
6
  @toc = []
@@ -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, '', syntax, context)
14
+ context << process_paragraph_group(lines, syntax, context)
15
15
  end
16
16
 
17
- def process_paragraph_group(lines, paragraph, syntax, context)
18
- paragraph << "<div class='pgroup'>\n" if context.enable_pgroup
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 << "</div>\n" if context.enable_pgroup
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
@@ -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"
@@ -1,3 +1,3 @@
1
1
  module ArtiMark
2
- VERSION = "0.0.1.beta1"
2
+ VERSION = "0.0.1.beta2"
3
3
  end
@@ -438,19 +438,36 @@ describe ArtiMark do
438
438
  expect(r.shift.strip).to eq('<dt>definition&lt;&gt;</dt><dd>&lt;&gt;&amp;</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
- r = converted[0].rstrip.split(/\r?\n/).map { |line| line.chomp }
445
- expect(r.shift.strip).to eq('<?xml version="1.0" encoding="UTF-8"?>')
446
- expect(r.shift.strip).to eq('<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">')
447
- expect(r.shift.strip).to eq('<head>')
448
- expect(r.shift.strip).to eq('<title>the document title</title>')
449
- expect(r.shift.strip).to eq('<link rel="stylesheet" type="text/css" href="css/default.css" />')
450
- expect(r.shift.strip).to eq('<link rel="stylesheet" type="text/css" href="css/specific.css" />')
451
- expect(r.shift.strip).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" />')
452
- expect(r.shift.strip).to eq('</head>')
453
- expect(r.shift.strip).to eq('<body>')
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
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.beta1
4
+ version: 0.0.1.beta2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: