nora_mark 0.2beta19 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/dependabot.yml +8 -0
  4. data/.github/workflows/test.yml +19 -0
  5. data/.rubocop.yml +3 -0
  6. data/.travis.yml +2 -2
  7. data/CHANGELOG.md +5 -0
  8. data/Gemfile +0 -1
  9. data/README.md +1 -2
  10. data/Rakefile +1 -4
  11. data/lib/nora_mark/document.rb +14 -14
  12. data/lib/nora_mark/extensions.rb +6 -6
  13. data/lib/nora_mark/html/abstract_node_writer.rb +2 -1
  14. data/lib/nora_mark/html/context.rb +16 -14
  15. data/lib/nora_mark/html/default_transformer.rb +36 -38
  16. data/lib/nora_mark/html/frontmatter_writer.rb +2 -2
  17. data/lib/nora_mark/html/generator.rb +19 -22
  18. data/lib/nora_mark/html/pages.rb +13 -14
  19. data/lib/nora_mark/html/paragraph_writer.rb +24 -26
  20. data/lib/nora_mark/html/raw_text_block_writer.rb +2 -1
  21. data/lib/nora_mark/html/tag_writer.rb +14 -13
  22. data/lib/nora_mark/html/util.rb +5 -5
  23. data/lib/nora_mark/node.rb +45 -55
  24. data/lib/nora_mark/node_set.rb +1 -1
  25. data/lib/nora_mark/node_util.rb +7 -8
  26. data/lib/nora_mark/parser.kpeg.rb +16 -16
  27. data/lib/nora_mark/parser.rb +1 -3
  28. data/lib/nora_mark/rake_task.rb +16 -20
  29. data/lib/nora_mark/transformer.rb +13 -15
  30. data/lib/nora_mark/version.rb +1 -1
  31. data/lib/nora_mark.rb +0 -4
  32. data/lib/tilt/nora_mark.rb +1 -1
  33. data/nora_mark.gemspec +6 -5
  34. data/spec/extensions_spec.rb +1 -2
  35. data/spec/fixtures/test-plugins/nora_mark_tester.rb +3 -1
  36. data/spec/node_spec.rb +69 -49
  37. data/spec/nokogiri_test_helper.rb +9 -7
  38. data/spec/nora_mark_spec.rb +437 -498
  39. data/spec/spec_helper.rb +1 -5
  40. data/spec/tilt_spec.rb +1 -1
  41. data/spec/transformer_spec.rb +16 -18
  42. metadata +36 -27
@@ -350,7 +350,7 @@ class NoraMark::Parser < KPeg::CompiledParser
350
350
 
351
351
  # BOM = /\uFEFF/
352
352
  def _BOM
353
- _tmp = scan(/\A(?-mix:\uFEFF)/)
353
+ _tmp = scan(/\G(?-mix:\uFEFF)/)
354
354
  set_failed_rule :_BOM unless _tmp
355
355
  return _tmp
356
356
  end
@@ -507,7 +507,7 @@ class NoraMark::Parser < KPeg::CompiledParser
507
507
 
508
508
  _save = self.pos
509
509
  while true # sequence
510
- _tmp = scan(/\A(?-mix:^)/)
510
+ _tmp = scan(/\G(?-mix:^)/)
511
511
  unless _tmp
512
512
  self.pos = _save
513
513
  break
@@ -544,7 +544,7 @@ class NoraMark::Parser < KPeg::CompiledParser
544
544
 
545
545
  # Nl = /\r?\n/
546
546
  def _Nl
547
- _tmp = scan(/\A(?-mix:\r?\n)/)
547
+ _tmp = scan(/\G(?-mix:\r?\n)/)
548
548
  set_failed_rule :_Nl unless _tmp
549
549
  return _tmp
550
550
  end
@@ -576,7 +576,7 @@ class NoraMark::Parser < KPeg::CompiledParser
576
576
 
577
577
  _save1 = self.pos
578
578
  while true # sequence
579
- _tmp = scan(/\A(?-mix:[\w])/)
579
+ _tmp = scan(/\G(?-mix:[\w])/)
580
580
  unless _tmp
581
581
  self.pos = _save1
582
582
  break
@@ -588,7 +588,7 @@ class NoraMark::Parser < KPeg::CompiledParser
588
588
  _tmp = match_string("-")
589
589
  break if _tmp
590
590
  self.pos = _save3
591
- _tmp = scan(/\A(?-mix:[\w])/)
591
+ _tmp = scan(/\G(?-mix:[\w])/)
592
592
  break if _tmp
593
593
  self.pos = _save3
594
594
  break
@@ -891,7 +891,7 @@ class NoraMark::Parser < KPeg::CompiledParser
891
891
  break
892
892
  end
893
893
  _save1 = self.pos
894
- _tmp = scan(/\A(?-mix:[,)])/)
894
+ _tmp = scan(/\G(?-mix:[,)])/)
895
895
  self.pos = _save1
896
896
  unless _tmp
897
897
  self.pos = _save
@@ -936,7 +936,7 @@ class NoraMark::Parser < KPeg::CompiledParser
936
936
  break
937
937
  end
938
938
  _save1 = self.pos
939
- _tmp = scan(/\A(?-mix:[,)])/)
939
+ _tmp = scan(/\G(?-mix:[,)])/)
940
940
  self.pos = _save1
941
941
  unless _tmp
942
942
  self.pos = _save
@@ -998,7 +998,7 @@ class NoraMark::Parser < KPeg::CompiledParser
998
998
  while true # sequence
999
999
  _text_start = self.pos
1000
1000
  while true
1001
- _tmp = scan(/\A(?-mix:[^,\]])/)
1001
+ _tmp = scan(/\G(?-mix:[^,\]])/)
1002
1002
  break unless _tmp
1003
1003
  end
1004
1004
  _tmp = true
@@ -1033,7 +1033,7 @@ class NoraMark::Parser < KPeg::CompiledParser
1033
1033
  end
1034
1034
  _text_start = self.pos
1035
1035
  while true
1036
- _tmp = scan(/\A(?-mix:[^"])/)
1036
+ _tmp = scan(/\G(?-mix:[^"])/)
1037
1037
  break unless _tmp
1038
1038
  end
1039
1039
  _tmp = true
@@ -1055,7 +1055,7 @@ class NoraMark::Parser < KPeg::CompiledParser
1055
1055
  break
1056
1056
  end
1057
1057
  _save2 = self.pos
1058
- _tmp = scan(/\A(?-mix:[,\]])/)
1058
+ _tmp = scan(/\G(?-mix:[,\]])/)
1059
1059
  self.pos = _save2
1060
1060
  unless _tmp
1061
1061
  self.pos = _save
@@ -1085,7 +1085,7 @@ class NoraMark::Parser < KPeg::CompiledParser
1085
1085
  end
1086
1086
  _text_start = self.pos
1087
1087
  while true
1088
- _tmp = scan(/\A(?-mix:[^'])/)
1088
+ _tmp = scan(/\G(?-mix:[^'])/)
1089
1089
  break unless _tmp
1090
1090
  end
1091
1091
  _tmp = true
@@ -1107,7 +1107,7 @@ class NoraMark::Parser < KPeg::CompiledParser
1107
1107
  break
1108
1108
  end
1109
1109
  _save2 = self.pos
1110
- _tmp = scan(/\A(?-mix:[,\]])/)
1110
+ _tmp = scan(/\G(?-mix:[,\]])/)
1111
1111
  self.pos = _save2
1112
1112
  unless _tmp
1113
1113
  self.pos = _save
@@ -2943,7 +2943,7 @@ class NoraMark::Parser < KPeg::CompiledParser
2943
2943
  break
2944
2944
  end
2945
2945
  _text_start = self.pos
2946
- _tmp = scan(/\A(?-mix:[`])/)
2946
+ _tmp = scan(/\G(?-mix:[`])/)
2947
2947
  if _tmp
2948
2948
  text = get_text(_text_start)
2949
2949
  end
@@ -3076,7 +3076,7 @@ class NoraMark::Parser < KPeg::CompiledParser
3076
3076
 
3077
3077
  _save = self.pos
3078
3078
  while true # sequence
3079
- _tmp = scan(/\A(?-mix:^)/)
3079
+ _tmp = scan(/\G(?-mix:^)/)
3080
3080
  unless _tmp
3081
3081
  self.pos = _save
3082
3082
  break
@@ -3087,7 +3087,7 @@ class NoraMark::Parser < KPeg::CompiledParser
3087
3087
  break
3088
3088
  end
3089
3089
  _text_start = self.pos
3090
- _tmp = scan(/\A(?-mix:\*+)/)
3090
+ _tmp = scan(/\G(?-mix:\*+)/)
3091
3091
  if _tmp
3092
3092
  text = get_text(_text_start)
3093
3093
  end
@@ -4533,7 +4533,7 @@ class NoraMark::Parser < KPeg::CompiledParser
4533
4533
  _save = self.pos
4534
4534
  while true # sequence
4535
4535
  _text_start = self.pos
4536
- _tmp = scan(/\A(?-mix:[[:print:]])/)
4536
+ _tmp = scan(/\G(?-mix:[[:print:]])/)
4537
4537
  if _tmp
4538
4538
  text = get_text(_text_start)
4539
4539
  end
@@ -4,9 +4,7 @@ require 'nora_mark/node'
4
4
  module NoraMark
5
5
  class Parser
6
6
  def initialize(src)
7
- super src
7
+ super src
8
8
  end
9
-
10
9
  end
11
10
  end
12
-
@@ -31,44 +31,40 @@ module NoraMark
31
31
 
32
32
  def define
33
33
  desc "rule for *-nora.txt to *-nora_xxx.html. Use *-nora-transform.rb on same directory as transformer"
34
- rule( /-((nora)|(arti))_[0-9]{#{page_number_digits}}\.xhtml/ =>
35
- proc {|task_name|
34
+ rule(/-((nora)|(arti))_[0-9]{#{page_number_digits}}\.xhtml/ =>
35
+ proc { |task_name|
36
36
  task_name.sub(/^(.+?-((nora)|(arti)))_[0-9]{#{page_number_digits}}\.xhtml/, '\1.txt')
37
- }) do
38
- |t|
37
+ }) do |t|
39
38
 
40
- dir = File.dirname File.expand_path(t.source)
39
+ dir = File.dirname File.expand_path(t.source)
41
40
  basename = File.basename(t.source, '.txt')
42
41
  transformer_name = File.join dir, basename + '-transform.rb'
43
42
  parameters = {
44
43
  :lang => @lang.to_s,
45
44
  :sequence_format => "%0#{page_number_digits}d",
46
- :document_name=>t.name.sub(/_[0-9]{#{page_number_digits}}\.xhtml/, '')
45
+ :document_name => t.name.sub(/_[0-9]{#{page_number_digits}}\.xhtml/, '')
47
46
  }
48
47
  parameters[:stylesheets] = @stylesheets unless @stylesheets.nil?
49
48
  parameters[:title] = @title unless @title.nil?
50
49
  @nora =
51
50
  NoraMark::Document.parse(
52
- File.open(t.source), parameters) do
53
- |doc|
54
- @preprocessors.each do
55
- |prepro|
56
- doc.preprocessor(&prepro)
51
+ File.open(t.source), parameters
52
+ ) do |doc|
53
+ @preprocessors.each do |prepro|
54
+ doc.preprocessor(&prepro)
55
+ end
56
+ @transformers.each do |transformer|
57
+ doc.add_transformer(&transformer)
58
+ end
59
+ if File.exist? transformer_name
60
+ doc.add_transformer(text: File.open(transformer_name).read)
61
+ end
57
62
  end
58
- @transformers.each do
59
- |transformer|
60
- doc.add_transformer(&transformer)
61
- end
62
- if File.exist? transformer_name
63
- doc.add_transformer(text: File.open(transformer_name).read)
64
- end
65
- end
66
63
  @nora.html.write_as_files
67
64
  if (@write_toc_file)
68
65
  @nora.html.write_toc_as_file
69
66
  end
70
67
  end
71
-
72
68
  end
73
69
  end
74
70
  end
@@ -10,13 +10,12 @@ module NoraMark
10
10
  def transform(node)
11
11
  frontmatter_node = node.find_node :type => :Frontmatter
12
12
  @frontmatter = frontmatter_node.yaml if frontmatter_node
13
- node.all_nodes.unshift(node).each do
14
- |n|
15
- if match_rule = @rules.find { |rule| n.match?(rule[0]) }
16
- action, p = match_rule[1,2]
13
+ node.all_nodes.unshift(node).each do |n|
14
+ if (match_rule = @rules.find { |rule| n.match?(rule[0]) })
15
+ action, p = match_rule[1, 2]
17
16
  @node = n
18
17
  send(action, &p)
19
- end
18
+ end
20
19
  end
21
20
  node
22
21
  end
@@ -29,12 +28,11 @@ module NoraMark
29
28
  new_node = instance_eval(&block)
30
29
  @node.replace new_node if new_node
31
30
  end
32
-
33
31
  end
34
-
32
+
35
33
  class TransformerFactory
36
34
  attr_accessor :rules, :options
37
-
35
+
38
36
  def self.create(text: nil, &block)
39
37
  instance = new
40
38
  instance.instance_eval do
@@ -47,22 +45,22 @@ module NoraMark
47
45
  end
48
46
  Transformer.new(@rules, @options)
49
47
  end
50
- end
51
-
48
+ end
49
+
52
50
  def transform_options options
53
- (@options ||= {}).merge options
51
+ (@options ||= {}).merge options
54
52
  end
55
-
53
+
56
54
  def modify(selector, &block)
57
- @rules << [ selector, :modify, block ]
55
+ @rules << [selector, :modify, block]
58
56
  end
59
57
 
60
58
  def replace(selector, &block)
61
- @rules << [ selector, :replace, block ]
59
+ @rules << [selector, :replace, block]
62
60
  end
63
61
 
64
62
  def rename(selector, name)
65
- @rules << [ selector, :modify, proc { @node.name = name } ]
63
+ @rules << [selector, :modify, proc { @node.name = name }]
66
64
  end
67
65
  end
68
66
  end
@@ -1,3 +1,3 @@
1
1
  module NoraMark
2
- VERSION = "0.2beta19"
2
+ VERSION = "0.3"
3
3
  end
data/lib/nora_mark.rb CHANGED
@@ -6,7 +6,3 @@ require 'nora_mark/node_set'
6
6
  require 'nora_mark/html/generator'
7
7
  require 'nora_mark/document'
8
8
  require 'nora_mark/extensions'
9
-
10
-
11
-
12
-
@@ -9,7 +9,7 @@ module Tilt
9
9
  @document = NoraMark::Document.parse(data).render_parameter(nonpaged: true)
10
10
  end
11
11
 
12
- def evaluate(scope, locals, &block)
12
+ def evaluate(_scope, _locals)
13
13
  @html ||= @document.html[0]
14
14
  end
15
15
  end
data/nora_mark.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+
2
3
  require File.expand_path('../lib/nora_mark/version', __FILE__)
3
4
 
4
5
  Gem::Specification.new do |gem|
@@ -9,17 +10,17 @@ Gem::Specification.new do |gem|
9
10
  gem.homepage = ""
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
13
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
15
  gem.name = "nora_mark"
15
16
  gem.require_paths = ["lib"]
16
17
  gem.version = NoraMark::VERSION
17
18
 
18
- gem.required_ruby_version = '>= 2.0.0'
19
- gem.add_dependency "kpeg"
19
+ gem.required_ruby_version = '>= 3.0.0'
20
+ gem.add_dependency "kpeg", "1.3.1"
21
+ gem.add_development_dependency "debug"
20
22
  gem.add_development_dependency "tilt", ">= 2.0"
21
23
  gem.add_development_dependency "rspec", ">= 2.14"
22
24
  gem.add_development_dependency "rake"
23
- gem.add_development_dependency "byebug"
24
- gem.add_development_dependency "nokogiri", "~> 1.7.0"
25
+ gem.add_development_dependency "nokogiri", ">= 1.13.6", "< 2.0"
25
26
  end
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+
2
3
  require File.dirname(__FILE__) + '/spec_helper.rb'
3
4
  require File.dirname(__FILE__) + '/../lib/nora_mark'
4
5
  require 'nokogiri'
@@ -25,7 +26,5 @@ describe NoraMark::Extensions do
25
26
  after(:each) do
26
27
  $:.delete @test_plugin_dir
27
28
  end
28
-
29
29
  end
30
30
  end
31
-
@@ -4,9 +4,11 @@ module NoraMark
4
4
  def self.name
5
5
  :tester
6
6
  end
7
+
7
8
  def initialize(param = {})
8
9
  end
9
- def convert(parsed_result, render_parameter = {})
10
+
11
+ def convert(_parsed_result, _render_parameter = {})
10
12
  'it is just a test.'
11
13
  end
12
14
  end
data/spec/node_spec.rb CHANGED
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../lib/nora_mark'
3
3
  require 'nokogiri'
4
4
  require File.dirname(__FILE__) + '/nokogiri_test_helper.rb'
5
5
 
6
- describe NoraMark::Node do
6
+ describe NoraMark::Node do
7
7
  describe 'node manipulation' do
8
8
  before do
9
9
  @text = <<EOF
@@ -24,17 +24,18 @@ EOF
24
24
  expect(page.children[2].children[0].line_no).to eq 5
25
25
  end
26
26
 
27
- it 'replace existing node' do
27
+ it 'replace existing node' do
28
28
  noramark = NoraMark::Document.parse(@text)
29
29
  page = noramark.root.children[0]
30
30
  first_pgroup = page.children[0]
31
31
  line_no = first_pgroup.line_no
32
- new_node = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [ NoraMark::Text.new("replaced.", line_no)], line_no)
32
+ new_node = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [NoraMark::Text.new("replaced.", line_no)], line_no)
33
33
  first_pgroup.replace(new_node)
34
34
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
35
35
  expect(body.element_children[0].selector_and_children(remove_id: false))
36
36
  .to eq(
37
- ['p#the_id.the_class', 'replaced.'])
37
+ ['p#the_id.the_class', 'replaced.']
38
+ )
38
39
  end
39
40
 
40
41
  it 'replace existing node by multiple nodes' do
@@ -42,91 +43,104 @@ EOF
42
43
  page = noramark.root.children[0]
43
44
  first_pgroup = page.children[0]
44
45
  line_no = first_pgroup.line_no
45
- new_node1 = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [ NoraMark::Text.new("replaced.", line_no)], line_no)
46
- new_node2 = NoraMark::ParagraphGroup.new(['the_id2'], ['the_class2'], [], {}, [ NoraMark::Text.new("replaced2.", line_no)], line_no)
46
+ new_node1 = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [NoraMark::Text.new("replaced.", line_no)], line_no)
47
+ new_node2 = NoraMark::ParagraphGroup.new(['the_id2'], ['the_class2'], [], {}, [NoraMark::Text.new("replaced2.", line_no)], line_no)
47
48
  first_pgroup.replace([new_node1, new_node2])
48
49
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
49
50
  expect(body.element_children[0].selector_and_children(remove_id: false))
50
51
  .to eq(
51
- ['p#the_id.the_class', 'replaced.'])
52
+ ['p#the_id.the_class', 'replaced.']
53
+ )
52
54
  expect(body.element_children[1].selector_and_children(remove_id: false))
53
55
  .to eq(
54
- ['p#the_id2.the_class2', 'replaced2.'])
56
+ ['p#the_id2.the_class2', 'replaced2.']
57
+ )
55
58
  expect(body.element_children[2].selector_and_children(remove_id: false))
56
59
  .to eq(
57
- ['div.the_class', ['p', '3rd line.']])
60
+ ['div.the_class', ['p', '3rd line.']]
61
+ )
58
62
  end
59
63
 
60
- it 'wraps existing node' do
64
+ it 'wraps existing node' do
61
65
  noramark = NoraMark::Document.parse(@text)
62
66
  page = noramark.root.children[0]
63
67
  first_pgroup = page.children[0]
64
68
  line_no = first_pgroup.line_no
65
69
  new_node = NoraMark::Block.new('div', ['the_id'], ['the_class'], [], {}, [
66
- NoraMark::Block.new('p', [], [], [], {}, [
67
- NoraMark::Text.new("replaced.", line_no)], line_no)
68
- ], line_no)
70
+ NoraMark::Block.new('p', [], [], [], {}, [
71
+ NoraMark::Text.new("replaced.", line_no)
72
+ ], line_no)
73
+ ], line_no)
69
74
  first_pgroup.wrap(new_node)
70
75
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
71
76
  expect(body.element_children[0].selector_and_children(remove_id: false))
72
77
  .to eq(['div#the_id.the_class', ['p', '1st line.'], ['p', 'replaced.']])
73
78
  end
74
79
 
75
- it 'append to existing node' do
80
+ it 'append to existing node' do
76
81
  noramark = NoraMark::Document.parse(@text)
77
82
  page = noramark.root.children[0]
78
83
  first_pgroup = page.children[0]
79
84
  line_no = first_pgroup.line_no
80
- new_node = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [ NoraMark::Text.new("added.", line_no)], line_no)
85
+ new_node = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [NoraMark::Text.new("added.", line_no)], line_no)
81
86
  first_pgroup.after(new_node)
82
87
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
83
88
  expect(body.element_children[0].selector_and_children(remove_id: false))
84
89
  .to eq(
85
- ['p', '1st line.'])
90
+ ['p', '1st line.']
91
+ )
86
92
  expect(body.element_children[1].selector_and_children(remove_id: false))
87
93
  .to eq(
88
- ['p#the_id.the_class', 'added.'])
94
+ ['p#the_id.the_class', 'added.']
95
+ )
89
96
  expect(body.element_children[2].selector_and_children(remove_id: false))
90
97
  .to eq(
91
- ['div.the_class', ['p', '3rd line.']])
98
+ ['div.the_class', ['p', '3rd line.']]
99
+ )
92
100
  end
93
101
 
94
- it 'append to the last existing node' do
102
+ it 'append to the last existing node' do
95
103
  noramark = NoraMark::Document.parse(@text)
96
104
  page = noramark.root.children[0]
97
105
  last_pgroup = page.children[2]
98
106
  line_no = last_pgroup.line_no
99
- new_node = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [ NoraMark::Text.new("added.", line_no)], line_no)
107
+ new_node = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [NoraMark::Text.new("added.", line_no)], line_no)
100
108
  last_pgroup.after(new_node)
101
109
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
102
110
  expect(body.element_children[1].selector_and_children(remove_id: false))
103
111
  .to eq(
104
- ['div.the_class', ['p', '3rd line.']])
112
+ ['div.the_class', ['p', '3rd line.']]
113
+ )
105
114
  expect(body.element_children[2].selector_and_children(remove_id: false))
106
115
  .to eq(
107
- ['p', '5th line.'])
116
+ ['p', '5th line.']
117
+ )
108
118
  expect(body.element_children[3].selector_and_children(remove_id: false))
109
119
  .to eq(
110
- ['p#the_id.the_class', 'added.'])
120
+ ['p#the_id.the_class', 'added.']
121
+ )
111
122
  end
112
-
113
- it 'prepend to existing node' do
123
+
124
+ it 'prepend to existing node' do
114
125
  noramark = NoraMark::Document.parse(@text)
115
126
  page = noramark.root.children[0]
116
127
  first_pgroup = page.children[0]
117
128
  line_no = first_pgroup.line_no
118
- new_node = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [ NoraMark::Text.new("added.", line_no)], line_no)
129
+ new_node = NoraMark::ParagraphGroup.new(['the_id'], ['the_class'], [], {}, [NoraMark::Text.new("added.", line_no)], line_no)
119
130
  first_pgroup.before(new_node)
120
131
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
121
132
  expect(body.element_children[0].selector_and_children(remove_id: false))
122
133
  .to eq(
123
- ['p#the_id.the_class', 'added.'])
134
+ ['p#the_id.the_class', 'added.']
135
+ )
124
136
  expect(body.element_children[1].selector_and_children(remove_id: false))
125
137
  .to eq(
126
- ['p', '1st line.'])
138
+ ['p', '1st line.']
139
+ )
127
140
  expect(body.element_children[2].selector_and_children(remove_id: false))
128
141
  .to eq(
129
- ['div.the_class', ['p', '3rd line.']])
142
+ ['div.the_class', ['p', '3rd line.']]
143
+ )
130
144
  end
131
145
 
132
146
  it 'removes node' do
@@ -161,7 +175,6 @@ EOF
161
175
  .to eq(["body", ["div.the_class", ["p", "3rd line."]], ["p", "5th line."]])
162
176
  end
163
177
 
164
-
165
178
  it 'modify existing node by DSL' do
166
179
  text = "1st line.\nfoobar(title)[level: 3] {\n in the section.\n}\n# section 2."
167
180
  noramark = NoraMark::Document.parse(text, lang: 'ja')
@@ -175,13 +188,16 @@ EOF
175
188
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
176
189
  expect(body.element_children[0].selector_and_children())
177
190
  .to eq(
178
- ['div.pgroup', [ 'p', '1st line.' ]])
191
+ ['div.pgroup', ['p', '1st line.']]
192
+ )
179
193
  expect(body.element_children[1].selector_and_children())
180
194
  .to eq(
181
- ['section', [ 'h3', 'title' ], ['div.pgroup', ['p', 'in the section.']]])
195
+ ['section', ['h3', 'title'], ['div.pgroup', ['p', 'in the section.']]]
196
+ )
182
197
  expect(body.element_children[2].selector_and_children())
183
198
  .to eq(
184
- ['section', [ 'h1','section 2.' ]])
199
+ ['section', ['h1', 'section 2.']]
200
+ )
185
201
  end
186
202
  it 'replace existing node by DSL' do
187
203
  text = "1st line.\nfoobar(title)[level: 3] {\n in the section.\n}\n# section 2."
@@ -191,20 +207,23 @@ EOF
191
207
  replace 'foobar' do
192
208
  block('section',
193
209
  [
194
- block( "h#{@node.named_params[:level]}", @node.params[0]),
210
+ block("h#{@node.named_params[:level]}", @node.params[0]),
195
211
  ] + @node.children)
196
212
  end
197
213
  end
198
214
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
199
215
  expect(body.element_children[0].selector_and_children())
200
216
  .to eq(
201
- ['div.pgroup', [ 'p', '1st line.' ]])
217
+ ['div.pgroup', ['p', '1st line.']]
218
+ )
202
219
  expect(body.element_children[1].selector_and_children())
203
220
  .to eq(
204
- ['section', [ 'h3', 'title' ], ['div.pgroup', ['p', 'in the section.']]])
221
+ ['section', ['h3', 'title'], ['div.pgroup', ['p', 'in the section.']]]
222
+ )
205
223
  expect(body.element_children[2].selector_and_children())
206
224
  .to eq(
207
- ['section', [ 'h1','section 2.' ]])
225
+ ['section', ['h1', 'section 2.']]
226
+ )
208
227
  end
209
228
  it 'generate complex-style headed section' do
210
229
  text = <<EOF
@@ -221,26 +240,27 @@ sub: 副見出し
221
240
  EOF
222
241
  noramark = NoraMark::Document.parse(text)
223
242
  noramark.add_transformer(generator: :html) do
224
- replace({:type => :HeadedSection}) do
243
+ replace({ :type => :HeadedSection }) do
225
244
  header = block('header',
226
245
  block('div',
227
246
  block("h#{@node.level}", @node.heading),
228
- classes: ['hgroup']))
247
+ classes: ['hgroup']))
229
248
  if (fc = @node.first_child).name == 'sub'
230
249
  fc.name = 'p'
231
250
  fc.classes = ['subh']
232
- header.first_child.append_child fc
251
+ header.first_child.append_child fc
233
252
  end
234
- body = block('div', @node.children, classes:['section-body'])
235
- block('section', [ header, body ], template: @node)
253
+ body = block('div', @node.children, classes: ['section-body'])
254
+ block('section', [header, body], template: @node)
236
255
  end
237
256
  end
238
257
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
239
258
  expect(body.element_children[0].selector_and_children())
240
259
  .to eq(
241
- ['section', [ 'header', ['div.hgroup', ['h1', '見出し'], ['p.subh', '副見出し']]],
242
- ['div.section-body',
243
- ['div.pgroup', ['p', 'パラグラフ。'], ['p', 'パラグラフ。']]]])
260
+ ['section', ['header', ['div.hgroup', ['h1', '見出し'], ['p.subh', '副見出し']]],
261
+ ['div.section-body',
262
+ ['div.pgroup', ['p', 'パラグラフ。'], ['p', 'パラグラフ。']]]]
263
+ )
244
264
  end
245
265
  it 'converts my markup' do
246
266
  text = "speak(Alice): Alice is speaking.\nspeak(Bob): and this is Bob."
@@ -254,13 +274,13 @@ EOF
254
274
  body = Nokogiri::XML::Document.parse(noramark.html[0]).root.at_xpath('xmlns:body')
255
275
  expect(body.element_children[0].selector_and_children())
256
276
  .to eq(
257
- ['p', ['span.speaker', 'Alice'], 'Alice is speaking.'])
277
+ ['p', ['span.speaker', 'Alice'], 'Alice is speaking.']
278
+ )
258
279
  expect(body.element_children[1].selector_and_children())
259
280
  .to eq(
260
- ['p', ['span.speaker', 'Bob'], 'and this is Bob.'])
261
-
281
+ ['p', ['span.speaker', 'Bob'], 'and this is Bob.']
282
+ )
262
283
  end
263
-
264
284
 
265
285
  it 'should reparent tree' do
266
286
  text = <<EOF