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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 397d46aaec05bdd60c4a1ba23267cf0a679ec6d1
4
- data.tar.gz: 999258023f60c38397e833f9c907ae0f1bdfc7fe
2
+ SHA256:
3
+ metadata.gz: a401d3cef71e3eec2bebbfbd6b552a9df37972cb7796949ce76ba3dc1e4fde67
4
+ data.tar.gz: d6c6e6e6a345c97e73992bd270a8669e34d9fa2654af324b9a214cacedd9d43a
5
5
  SHA512:
6
- metadata.gz: 913123b4eacbe4cc65ce0fc010dd78041f4d3e1242462f238ce5f2967a1608816805a0623ad4b292b6e84ec9344cec5a64a1c1283de1191222ecc9ceb2cfa468
7
- data.tar.gz: 1c1c64ebcef150e061455063ec24f3bdd77414b804402b2ab23a7f3c4a9ac703c9b13cc2d669a50d8bbc7b7816295e84c21a42082e7310114f197c56cb03678c
6
+ metadata.gz: fa6db5a1d5606ce45949603156d380d2182a1671c63ff30116b5295c384d363aa2bde5b55d16b5543bbfbd4d23d175893a3ab5e0a8028246480eb7c71e5a71ea
7
+ data.tar.gz: 8ee3306e81d0e3ef5f20f2ee06da56e7b748618b3acc51d30c6a096c32a6001f6d4c9e59d26ba86beb23abdd43527a39c63c657d93ec04a03ce7886d78eac98e
@@ -0,0 +1,3 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: skoji
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "20:00"
8
+ open-pull-requests-limit: 10
@@ -0,0 +1,19 @@
1
+ name: Test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ matrix:
7
+ ruby: [3.0, 3.1]
8
+ platform: [ubuntu-latest, macos-latest, windows-latest]
9
+ runs-on: ${{ matrix.platform }}
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby
13
+ uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ - name: setup gems
17
+ run: bundle install --jobs 4 --retry 3
18
+ - name: run test
19
+ run: bundle exec rake spec
data/.rubocop.yml ADDED
@@ -0,0 +1,3 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'lib/nora_mark/parser.kpeg.rb'
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.2.2
3
+ - 2.5.7
4
+ - 2.6.5
5
5
  script: bundle exec rake spec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # version 0.3
2
+
3
+ * Update dependencies
4
+ * Only support Ruby 3.0
5
+
1
6
  # version 0.2beta8 to 0.2beta12
2
7
 
3
8
  * Plugin API for generator
data/Gemfile CHANGED
@@ -3,4 +3,3 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in nora_mark.gemspec
4
4
  gemspec
5
5
 
6
- gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # NoraMark
2
2
 
3
3
  [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/skoji/noramark?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
- [<img src="https://secure.travis-ci.org/skoji/noramark.png" />](http://travis-ci.org/skoji/noramark) [![Coverage Status](https://coveralls.io/repos/skoji/noramark/badge.png?branch=master)](https://coveralls.io/r/skoji/noramark?branch=master)
5
4
  [![Dependency Status](https://gemnasium.com/skoji/noramark.png)](https://gemnasium.com/skoji/noramark)
6
5
  [![Gem Version](https://badge.fury.io/rb/nora_mark.png)](http://badge.fury.io/rb/nora_mark)
7
6
 
@@ -13,7 +12,7 @@ In non-beta release version, the syntax will be more stable.
13
12
 
14
13
  ## Requirements
15
14
 
16
- * Ruby 2.0.0 or greater
15
+ * Ruby 3.0.0 or greater
17
16
 
18
17
  ## Installation
19
18
 
data/Rakefile CHANGED
@@ -2,11 +2,8 @@
2
2
  require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
4
 
5
- rule(/\.kpeg\.rb/ => proc {|task_name| task_name.sub(/kpeg\.rb$/, 'kpeg')}) do
6
- |t|
5
+ rule(/\.kpeg\.rb/ => proc { |task_name| task_name.sub(/kpeg\.rb$/, 'kpeg') }) do |t|
7
6
  system "kpeg -f #{t.prerequisites[0]}"
8
7
  end
9
8
 
10
9
  RSpec::Core::RakeTask.new(:spec => ["lib/nora_mark/parser.kpeg.rb"])
11
-
12
-
@@ -1,14 +1,14 @@
1
1
  require 'securerandom'
2
2
 
3
3
  module NoraMark
4
- class Document
4
+ class Document
5
5
  attr_accessor :document_name, :root
6
- private_class_method :new
6
+ private_class_method :new
7
7
 
8
8
  def self.generators
9
9
  @generators ||= {}
10
10
  end
11
-
11
+
12
12
  def self.register_generator(generator)
13
13
  @generators ||= {}
14
14
  generator_name = generator.name
@@ -24,7 +24,7 @@ module NoraMark
24
24
  if generator.is_a? Symbol or generator.is_a? String
25
25
  generator_name = generator.to_sym
26
26
  else
27
- generator_name = generator.name
27
+ generator_name = generator.name
28
28
  end
29
29
 
30
30
  @generators.delete generator_name
@@ -38,15 +38,15 @@ module NoraMark
38
38
  instance = new param
39
39
  src = (string_or_io.respond_to?(:read) ? string_or_io.read : string_or_io).encode 'utf-8'
40
40
  yield instance if block_given?
41
- instance.instance_eval do
42
- @preprocessors.each do
43
- |pr|
41
+ instance.instance_eval do
42
+ @preprocessors.each do |pr|
44
43
  src = pr.call(src)
45
44
  end
46
45
  parser = Parser.new(src)
47
46
  if (!parser.parse)
48
47
  raise parser.raise_error
49
48
  end
49
+
50
50
  @root = parser.result
51
51
  @root.document_name ||= @document_name
52
52
  @root.reparent
@@ -58,7 +58,7 @@ module NoraMark
58
58
  NoraMark::Extensions.register_generator(frontmatter.yaml['generator'].to_sym)
59
59
  end
60
60
  end
61
-
61
+
62
62
  instance
63
63
  end
64
64
 
@@ -69,7 +69,7 @@ module NoraMark
69
69
  def transformers(generator_name)
70
70
  @transformers[generator_name] ||= []
71
71
  end
72
-
72
+
73
73
  def generate(generator_name)
74
74
  if @result[generator_name].nil?
75
75
  transformers(generator_name).each { |t| t.transform @root }
@@ -86,16 +86,16 @@ module NoraMark
86
86
  def add_transformer(generator: :html, text: nil, &block)
87
87
  (@transformers[generator] ||= []) << TransformerFactory.create(text: text, &block)
88
88
  end
89
-
89
+
90
90
  def initialize(param = {})
91
91
  @param = param
92
92
  @result = {}
93
93
  @preprocessors = [
94
- Proc.new { |text| text.gsub(/\r?\n(\r?\n)+/, "\n\n") },
95
- ]
94
+ Proc.new { |text| text.gsub(/\r?\n(\r?\n)+/, "\n\n") },
95
+ ]
96
96
  @document_name = param[:document_name] || "noramark_#{SecureRandom.uuid}"
97
97
  @render_parameter = {}
98
- @transformers = { }
99
- end
98
+ @transformers = {}
99
+ end
100
100
  end
101
101
  end
@@ -1,27 +1,27 @@
1
1
  module NoraMark
2
2
  class Extensions
3
3
  def self.register_generator(generator)
4
- if !generator.respond_to? :name
4
+ if generator.is_a? Symbol or generator.is_a? String
5
5
  generator = load_generator(generator)
6
6
  end
7
7
  NoraMark::Document.register_generator(generator)
8
8
  end
9
-
9
+
10
10
  def self.unregister_generator(generator)
11
11
  NoraMark::Document.unregister_generator(generator)
12
12
  end
13
-
13
+
14
14
  def self.const_get_if_available(name)
15
- name.split(/::/).inject(Object){|o,c|
15
+ name.split(/::/).inject(Object) { |o, c|
16
16
  o.const_get(c) if !o.nil? and o.const_defined? c
17
- }
17
+ }
18
18
  end
19
19
 
20
- private
21
20
  def self.load_generator(generator)
22
21
  module_name = "NoraMark::#{generator.to_s.capitalize}::Generator"
23
22
  generator_module = const_get_if_available(module_name)
24
23
  return generator_module unless generator_module.nil?
24
+
25
25
  path = "#{generator.to_s.downcase}.rb"
26
26
  current_dir_path = File.expand_path(File.join('.', '.noramark-plugins', path))
27
27
  home_dir_path = File.expand_path(File.join(ENV['HOME'], '.noramark-plugins', path))
@@ -4,6 +4,7 @@ module NoraMark
4
4
  def initialize(generator)
5
5
  @generator = generator
6
6
  end
7
+
7
8
  def write(node)
8
9
  node.children.each do |child|
9
10
  @generator.to_html child
@@ -11,4 +12,4 @@ module NoraMark
11
12
  end
12
13
  end
13
14
  end
14
- end
15
+ end
@@ -9,7 +9,7 @@ module NoraMark
9
9
  @title = param[:title] || 'NoraMark generated document'
10
10
  @stylesheets = param[:stylesheets] || []
11
11
  @enable_pgroup = param[:enable_pgroup] || true
12
- self.paragraph_style= param[:paragraph_style]
12
+ self.paragraph_style = param[:paragraph_style]
13
13
  @pages = Pages.new(param[:sequence_format])
14
14
  @metas = param[:metas] || []
15
15
  @namespaces = {}
@@ -20,13 +20,13 @@ module NoraMark
20
20
  if s.is_a? String
21
21
  ret << "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{s}\" />\n"
22
22
  elsif s.is_a? Array
23
- ret << "<link rel=\"stylesheet\" type=\"text/css\" media=\"#{s[1]}\" href=\"#{s[0]}\" />\n"
23
+ ret << "<link rel=\"stylesheet\" type=\"text/css\" media=\"#{s[1]}\" href=\"#{s[0]}\" />\n"
24
24
  else
25
25
  raise "Can't use #{s} as a stylesheet"
26
26
  end
27
27
  end
28
28
  ret << @metas.map do |meta|
29
- "<meta " + meta.map do |k,v|
29
+ "<meta " + meta.map do |k, v|
30
30
  "#{k}=\"#{v}\""
31
31
  end.join(" ") + " />"
32
32
  end.join("\n")
@@ -37,7 +37,7 @@ module NoraMark
37
37
  def file_basename=(name)
38
38
  @pages.file_basename = name
39
39
  end
40
-
40
+
41
41
  def chop_last_space
42
42
  @pages.last.sub!(/[[:space:]]+\Z/, '')
43
43
  end
@@ -45,37 +45,38 @@ module NoraMark
45
45
  def paragraph_style=(style)
46
46
  return if style.nil?
47
47
  raise "paragrapy_style accepts only :default or :use_paragraph_group but is #{style}" if style != :default && style != :use_paragraph_group
48
+
48
49
  @paragraph_style = style
49
50
  end
50
-
51
+
51
52
  def paragraph_style
52
53
  if @paragraph_style
53
54
  @paragraph_style
54
- elsif @lang.split('-')[0] == 'ja'
55
+ elsif @lang.split('-')[0] == 'ja'
55
56
  :use_paragraph_group
56
57
  else
57
58
  :default
58
59
  end
59
60
  end
61
+
60
62
  def head_inserter(&block)
61
63
  head_inserters << block
62
64
  end
63
65
 
64
66
  def start_html(title = nil)
65
67
  @title = title if !title.nil?
66
- if @pages.size >0 && !@pages.last.frozen?
68
+ if @pages.size > 0 && !@pages.last.frozen?
67
69
  end_html
68
70
  end
69
71
  page = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
70
72
  page << "<html xmlns=\"http://www.w3.org/1999/xhtml\""
71
- page << @namespaces.map do |k,v|
73
+ page << @namespaces.map do |k, v|
72
74
  " xmlns:#{k}=\"#{v}\""
73
75
  end.join(' ')
74
76
  page << " lang=\"#{@lang}\" xml:lang=\"#{@lang}\">\n"
75
77
  page << "<head>\n"
76
78
  page << "<title>#{@title}</title>\n"
77
- @head_inserters.each {
78
- |f|
79
+ @head_inserters.each { |f|
79
80
  page << f.call
80
81
  }
81
82
  page << "</head>\n"
@@ -84,10 +85,11 @@ module NoraMark
84
85
 
85
86
  def end_html
86
87
  return if @pages.size == 0
88
+
87
89
  page = @pages.last
88
90
  if !page.frozen?
89
91
  page << "</html>\n"
90
- page.freeze
92
+ page.freeze
91
93
  end
92
94
  restore_metas
93
95
  end
@@ -105,10 +107,10 @@ module NoraMark
105
107
  def restore_metas
106
108
  @stylesheets = @default_param[:stylesheets] || @stylesheets
107
109
  @title = @default_param[:title] || @title
108
- @lang = @default_param[:lang] || @lang
110
+ @lang = @default_param[:lang] || @lang
109
111
  @paragraph_style = @default_param[:paragraph_style] || @paragraph_style
110
- @namespaces = @default_param[:namespaces] || @namespaces
111
- @metas = @default_param[:metas] || @metas
112
+ @namespaces = @default_param[:namespaces] || @namespaces
113
+ @metas = @default_param[:metas] || @metas
112
114
  end
113
115
 
114
116
  def <<(text)
@@ -9,7 +9,7 @@ module NoraMark
9
9
  rename 'sect', 'section'
10
10
  rename 'sp', 'span'
11
11
 
12
- modify({type: :Root}) do
12
+ modify({ type: :Root }) do
13
13
  if (@options[:render_parameter] ||= {})[:nonpaged]
14
14
  first_page = @node.first_child.remove
15
15
  @node.children.each do |node|
@@ -28,7 +28,7 @@ module NoraMark
28
28
  end
29
29
  modify(/\A(l|link)\Z/) do
30
30
  @node.name = 'a'
31
- (@node.attrs ||= {}).merge!({href: [@node.params[0].text]})
31
+ (@node.attrs ||= {}).merge!({ href: [@node.params[0].text] })
32
32
  end
33
33
 
34
34
  replace 'noescape' do
@@ -51,21 +51,21 @@ module NoraMark
51
51
  modify 'img' do
52
52
  @node.body_empty = true
53
53
  @node.attrs ||= {}
54
- @node.attrs.merge!({src: [@node.params[0].text ]}) if @node.attrs[:src].nil?
55
- @node.attrs.merge!({alt: [ escape_html(@node.params[1].text.strip)]}) if (@node.attrs[:alt].nil? && @node.p.size > 1 && @node.params[1].text.size > 0)
54
+ @node.attrs.merge!({ src: [@node.params[0].text] }) if @node.attrs[:src].nil?
55
+ @node.attrs.merge!({ alt: [escape_html(@node.params[1].text.strip)] }) if (@node.attrs[:alt].nil? && @node.p.size > 1 && @node.params[1].text.size > 0)
56
56
  end
57
57
 
58
58
  replace 'image' do
59
59
  imagenode = inline('img', nil,
60
60
  body_empty: true,
61
- attrs: {src: [ @node.params[0].text.strip], alt: [ (@node.params[1].text ||'').strip ] })
61
+ attrs: { src: [@node.params[0].text.strip], alt: [(@node.params[1].text || '').strip] })
62
62
  newnode = block('figure',
63
- class_if_empty:'img-wrap',
63
+ class_if_empty: 'img-wrap',
64
64
  ids: @node.ids,
65
- children: [ imagenode],
66
- template: @node)
65
+ children: [imagenode],
66
+ template: @node)
67
67
  if !@node.children_empty?
68
- if @node.n[:caption_before]
68
+ if @node.n[:caption_before]
69
69
  newnode.prepend_child inline('figcaption', @node.children)
70
70
  else
71
71
  newnode.append_child inline('figcaption', @node.children)
@@ -74,92 +74,90 @@ module NoraMark
74
74
  newnode
75
75
  end
76
76
 
77
- replace({type: :OrderedList}) do
77
+ replace({ type: :OrderedList }) do
78
78
  block('ol', template: @node)
79
79
  end
80
80
 
81
- replace({type: :UnorderedList}) do
81
+ replace({ type: :UnorderedList }) do
82
82
  block('ul', template: @node)
83
83
  end
84
84
 
85
- replace({type: :UlItem}) do
85
+ replace({ type: :UlItem }) do
86
86
  block('li', template: @node)
87
87
  end
88
88
 
89
- replace({type: :OlItem}) do
89
+ replace({ type: :OlItem }) do
90
90
  block('li', template: @node)
91
91
  end
92
92
 
93
- replace({type: :DefinitionList}) do
93
+ replace({ type: :DefinitionList }) do
94
94
  block('dl', template: @node)
95
95
  end
96
96
 
97
- replace({type: :DLItem}) do
97
+ replace({ type: :DLItem }) do
98
98
  [
99
- block('dt', @node.p[0], n: {chop_last_space: true}),
100
- block('dd', @node.children)
99
+ block('dt', @node.p[0], n: { chop_last_space: true }),
100
+ block('dd', @node.children)
101
101
  ]
102
102
  end
103
103
 
104
- replace({type: :Breakline}) do
104
+ replace({ type: :Breakline }) do
105
105
  newnode = block('br')
106
106
  newnode.body_empty = true
107
107
  newnode
108
108
  end
109
109
 
110
- replace({type: :HeadedSection}) do
110
+ replace({ type: :HeadedSection }) do
111
111
  if @node.named_params[:without_header]
112
112
  content = @node.children
113
113
  else
114
- content = [ block("h#{@node.level}", @node.heading, ids: @node.n[:heading_id], n: {chop_last_space: true}) ] + @node.children
114
+ content = [block("h#{@node.level}", @node.heading, ids: @node.n[:heading_id], n: { chop_last_space: true })] + @node.children
115
115
  end
116
116
  block('section', content, template: @node)
117
117
  end
118
118
 
119
- replace ({type: :CodeInline}) do
119
+ replace({ type: :CodeInline }) do
120
120
  inline('code', @node.content, line_no: @node.line_no, template: @node)
121
121
  end
122
-
123
- replace ({type: :PreformattedBlock}) do
122
+
123
+ replace({ type: :PreformattedBlock }) do
124
124
  new_node = block('pre')
125
125
  if @node.codelanguage
126
126
  new_node.attrs = @node.attrs
127
127
  new_node.add_attr 'data-code-language' => [@node.codelanguage]
128
- new_node.classes = (@node.classes ||[]) << "code-#{@node.codelanguage}"
128
+ new_node.classes = (@node.classes || []) << "code-#{@node.codelanguage}"
129
129
  end
130
130
  if @node.name == 'code'
131
131
  code = block('code', text(@node.content.join("\n"), raw_text: true))
132
- new_node.children = [ code ]
132
+ new_node.children = [code]
133
133
  else
134
- new_node.children = [ text(@node.content.join("\n"), raw_text: true) ]
134
+ new_node.children = [text(@node.content.join("\n"), raw_text: true)]
135
135
  end
136
- if (@node.p || []).size> 0
136
+ if (@node.p || []).size > 0
137
137
  method = @node.n[:caption_after] ? :prepend : :append
138
- new_node = new_node.wrap block('div', classes: ['pre'], children: [ block('p', children: @node.p.shift, classes: ['caption']) ]), method
138
+ new_node = new_node.wrap block('div', classes: ['pre'], children: [block('p', children: @node.p.shift, classes: ['caption'])]), method
139
139
  end
140
140
  new_node
141
141
  end
142
142
 
143
143
  modify 'video' do
144
144
  @node.attrs ||= {}
145
- @node.attrs.merge!({src: [@node.p.shift.text]})
146
- @node.attrs.merge!({poster: [@node.n[:poster]]}) unless @node.n[:poster].nil?
145
+ @node.attrs.merge!({ src: [@node.p.shift.text] })
146
+ @node.attrs.merge!({ poster: [@node.n[:poster]] }) unless @node.n[:poster].nil?
147
147
 
148
148
  options = @node.p.map { |opt| opt.text.strip }
149
- ['autoplay', 'controls', 'loop', 'muted'].each do
150
- |attr|
151
- @node.attrs.merge!({attr.to_sym => true}) if options.member? attr
149
+ ['autoplay', 'controls', 'loop', 'muted'].each do |attr|
150
+ @node.attrs.merge!({ attr.to_sym => true }) if options.member? attr
152
151
  end
153
152
  end
154
153
 
155
154
  modify 'audio' do
156
155
  @node.attrs ||= {}
157
- @node.attrs.merge!({src: [@node.p.shift.text]})
158
- @node.attrs.merge!({volume: [@node.n[:volume]]}) unless @node.n[:volume].nil?
156
+ @node.attrs.merge!({ src: [@node.p.shift.text] })
157
+ @node.attrs.merge!({ volume: [@node.n[:volume]] }) unless @node.n[:volume].nil?
159
158
  options = @node.p.map { |opt| opt.text.strip }
160
- ['autoplay', 'controls', 'loop', 'muted'].each do
161
- |attr|
162
- @node.attrs.merge!({attr.to_sym => true}) if options.member? attr
159
+ ['autoplay', 'controls', 'loop', 'muted'].each do |attr|
160
+ @node.attrs.merge!({ attr.to_sym => true }) if options.member? attr
163
161
  end
164
162
  end
165
163
  end
@@ -27,6 +27,7 @@ module NoraMark
27
27
  end
28
28
  }
29
29
  end
30
+
30
31
  def write(node)
31
32
  if node.yaml.keys.map(&:to_sym).include? :stylesheets
32
33
  @context.stylesheets = []
@@ -34,8 +35,7 @@ module NoraMark
34
35
  if node.yaml.keys.map(&:to_sym).include? :meta
35
36
  @context.metas = []
36
37
  end
37
- node.yaml.each {
38
- |k,v|
38
+ node.yaml.each { |k, v|
39
39
  writer = @writers[k.to_sym]
40
40
  writer.call(v) unless writer.nil?
41
41
  }
@@ -1,4 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
+
2
3
  require 'nora_mark/html/util'
3
4
  require 'nora_mark/html/pages'
4
5
  require 'nora_mark/html/context'
@@ -35,44 +36,42 @@ module NoraMark
35
36
  end
36
37
  node
37
38
  end);
38
-
39
+
39
40
  @writers = {
40
41
  Text => raw_writer,
41
42
  Paragraph => paragraph_writer,
42
43
  ParagraphGroup => paragraph_writer,
43
- Inline =>TagWriter.create(nil, self, trailer: ''),
44
+ Inline => TagWriter.create(nil, self, trailer: ''),
44
45
  Block => TagWriter.create(nil, self),
45
- Document => abstract_node_writer,
46
- Page => page_writer,
47
- Frontmatter => frontmatter_writer,
48
- }
46
+ Document => abstract_node_writer,
47
+ Page => page_writer,
48
+ Frontmatter => frontmatter_writer,
49
+ }
49
50
  end
50
51
 
51
- def collect_id_and_headings
52
+ def collect_id_and_headings
52
53
  @id_pool = {}
53
54
  @headings = []
54
55
 
55
56
  all_nodes = @parsed_result.all_nodes
56
- all_nodes.each do
57
- |x|
57
+ all_nodes.each do |x|
58
58
  x.ids ||= []
59
- x.ids.each do
60
- |id|
59
+ x.ids.each do |id|
61
60
  if !@id_pool[id].nil?
62
61
  warn "duplicate id #{id}"
63
62
  end
64
63
  @id_pool[id] = x
65
64
  end
66
- @headings << x if (x.kind_of?(Block) && x.name =~ /h[1-6]/)
65
+ @headings << x if (x.kind_of?(Block) && x.name =~ /h[1-6]/)
67
66
  end
68
67
  end
69
- def assign_id_to_headings
68
+
69
+ def assign_id_to_headings
70
70
  collect_id_and_headings
71
71
  count = 1
72
- @headings.each do
73
- |heading|
74
- if heading.ids.size == 0
75
- begin
72
+ @headings.each do |heading|
73
+ if heading.ids.size == 0
74
+ begin
76
75
  id = "heading_index_#{count}"
77
76
  count = count + 1
78
77
  end while @id_pool[id]
@@ -85,13 +84,12 @@ module NoraMark
85
84
  transformer = Html.default_transformer
86
85
  transformer.options[:render_parameter] = render_parameter
87
86
  @parsed_result = transformer.transform parsed_result
88
- assign_id_to_headings
87
+ assign_id_to_headings
89
88
 
90
89
  children = parsed_result.children
91
90
  @context.file_basename = parsed_result.document_name
92
91
  @context.render_parameter = render_parameter
93
- children.each {
94
- |node|
92
+ children.each { |node|
95
93
  to_html(node)
96
94
  }
97
95
  @context.set_toc generate_toc
@@ -99,8 +97,7 @@ module NoraMark
99
97
  end
100
98
 
101
99
  def generate_toc
102
- @headings.map do
103
- |heading|
100
+ @headings.map do |heading|
104
101
  { page: heading.ancestors(type: :Page)[0].page_no }.merge heading.heading_info
105
102
  end
106
103
  end