nora_mark 0.2beta16 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) 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/.gitignore +1 -0
  6. data/.rubocop.yml +3 -0
  7. data/.travis.yml +2 -2
  8. data/CHANGELOG.md +5 -0
  9. data/Gemfile +0 -1
  10. data/README.md +1 -2
  11. data/Rakefile +1 -4
  12. data/lib/nora_mark/document.rb +14 -14
  13. data/lib/nora_mark/extensions.rb +6 -6
  14. data/lib/nora_mark/html/abstract_node_writer.rb +2 -1
  15. data/lib/nora_mark/html/context.rb +18 -16
  16. data/lib/nora_mark/html/default_transformer.rb +41 -38
  17. data/lib/nora_mark/html/frontmatter_writer.rb +2 -2
  18. data/lib/nora_mark/html/generator.rb +22 -22
  19. data/lib/nora_mark/html/pages.rb +13 -14
  20. data/lib/nora_mark/html/paragraph_writer.rb +24 -26
  21. data/lib/nora_mark/html/raw_text_block_writer.rb +13 -0
  22. data/lib/nora_mark/html/tag_writer.rb +14 -13
  23. data/lib/nora_mark/html/util.rb +5 -5
  24. data/lib/nora_mark/node.rb +46 -56
  25. data/lib/nora_mark/node_set.rb +1 -1
  26. data/lib/nora_mark/node_util.rb +7 -8
  27. data/lib/nora_mark/parser.kpeg.rb +16 -16
  28. data/lib/nora_mark/parser.rb +1 -3
  29. data/lib/nora_mark/rake_task.rb +23 -23
  30. data/lib/nora_mark/transformer.rb +13 -15
  31. data/lib/nora_mark/version.rb +1 -1
  32. data/lib/nora_mark.rb +0 -4
  33. data/lib/tilt/nora_mark.rb +1 -1
  34. data/nora_mark.gemspec +7 -6
  35. data/spec/extensions_spec.rb +1 -2
  36. data/spec/fixtures/test-plugins/nora_mark_tester.rb +3 -1
  37. data/spec/node_spec.rb +69 -49
  38. data/spec/nokogiri_test_helper.rb +9 -7
  39. data/spec/nora_mark_spec.rb +467 -491
  40. data/spec/spec_helper.rb +2 -6
  41. data/spec/tilt_spec.rb +1 -1
  42. data/spec/transformer_spec.rb +16 -18
  43. metadata +39 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d90789f0a20df993346e159dd0b37cdd1f664f9c
4
- data.tar.gz: 4c373042623881fcc820041c5454219d12c2f2ca
2
+ SHA256:
3
+ metadata.gz: a401d3cef71e3eec2bebbfbd6b552a9df37972cb7796949ce76ba3dc1e4fde67
4
+ data.tar.gz: d6c6e6e6a345c97e73992bd270a8669e34d9fa2654af324b9a214cacedd9d43a
5
5
  SHA512:
6
- metadata.gz: eb21f8791bccb24784e2761a4aa3bbe92c77723f83643acf5a60a33e84db5715b99b824b0b77e331c91d83600286d7b87198fff6fce101ca1fbe34d01367e0e5
7
- data.tar.gz: 8797e08d2c24486f596028f6b65f036c4097f5126ae058b29feae8dc7a859c4267a250ebeab02b6dc86f4930256f41363e620b1d600a02a94cdbb894533e3068
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/.gitignore CHANGED
@@ -17,3 +17,4 @@ spec/reports
17
17
  test/tmp
18
18
  test/version_tmp
19
19
  tmp
20
+ o
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.1.0
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,17 +85,18 @@ 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
94
96
 
95
97
  # save metadata written with Frontmatter Writer
96
98
  def save_default_metas
97
- @default_param[:styleheets] ||= @stylesheets if !@stylesheets.nil? && @stylesheets.size > 0
99
+ @default_param[:stylesheets] ||= @stylesheets if !@stylesheets.nil? && @stylesheets.size > 0
98
100
  @default_param[:title] ||= @title
99
101
  @default_param[:lang] ||= @lang
100
102
  @default_param[:paragraph_style] ||= @paragraph_style
@@ -103,12 +105,12 @@ module NoraMark
103
105
  end
104
106
 
105
107
  def restore_metas
106
- @stylesheets = @default_param[:styleheets] || @stylesheets
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,87 +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
111
- block('section', [ block("h#{@node.level}", @node.heading, ids: @node.n[:heading_id], n: {chop_last_space: true}) ] + @node.children, template: @node)
110
+ replace({ type: :HeadedSection }) do
111
+ if @node.named_params[:without_header]
112
+ content = @node.children
113
+ else
114
+ content = [block("h#{@node.level}", @node.heading, ids: @node.n[:heading_id], n: { chop_last_space: true })] + @node.children
115
+ end
116
+ block('section', content, template: @node)
112
117
  end
113
118
 
114
- replace ({type: :CodeInline}) do
119
+ replace({ type: :CodeInline }) do
115
120
  inline('code', @node.content, line_no: @node.line_no, template: @node)
116
121
  end
117
-
118
- replace ({type: :PreformattedBlock}) do
122
+
123
+ replace({ type: :PreformattedBlock }) do
119
124
  new_node = block('pre')
120
125
  if @node.codelanguage
121
126
  new_node.attrs = @node.attrs
122
127
  new_node.add_attr 'data-code-language' => [@node.codelanguage]
123
- new_node.classes = (@node.classes ||[]) << "code-#{@node.codelanguage}"
128
+ new_node.classes = (@node.classes || []) << "code-#{@node.codelanguage}"
124
129
  end
125
130
  if @node.name == 'code'
126
131
  code = block('code', text(@node.content.join("\n"), raw_text: true))
127
- new_node.children = [ code ]
132
+ new_node.children = [code]
128
133
  else
129
- new_node.children = [ text(@node.content.join("\n"), raw_text: true) ]
134
+ new_node.children = [text(@node.content.join("\n"), raw_text: true)]
130
135
  end
131
- if (@node.p || []).size> 0
136
+ if (@node.p || []).size > 0
132
137
  method = @node.n[:caption_after] ? :prepend : :append
133
- 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
134
139
  end
135
140
  new_node
136
141
  end
137
142
 
138
143
  modify 'video' do
139
144
  @node.attrs ||= {}
140
- @node.attrs.merge!({src: [@node.p.shift.text]})
141
- @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?
142
147
 
143
148
  options = @node.p.map { |opt| opt.text.strip }
144
- ['autoplay', 'controls', 'loop', 'muted'].each do
145
- |attr|
146
- @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
147
151
  end
148
152
  end
149
153
 
150
154
  modify 'audio' do
151
155
  @node.attrs ||= {}
152
- @node.attrs.merge!({src: [@node.p.shift.text]})
153
- @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?
154
158
  options = @node.p.map { |opt| opt.text.strip }
155
- ['autoplay', 'controls', 'loop', 'muted'].each do
156
- |attr|
157
- @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
158
161
  end
159
162
  end
160
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'
@@ -6,6 +7,7 @@ require 'nora_mark/html/tag_writer'
6
7
  require 'nora_mark/html/frontmatter_writer'
7
8
  require 'nora_mark/html/paragraph_writer'
8
9
  require 'nora_mark/html/abstract_node_writer'
10
+ require 'nora_mark/html/raw_text_block_writer'
9
11
  require 'nora_mark/html/default_transformer'
10
12
 
11
13
  module NoraMark
@@ -22,6 +24,7 @@ module NoraMark
22
24
  frontmatter_writer = FrontmatterWriter.new self
23
25
  paragraph_writer = ParagraphWriter.new self
24
26
  abstract_node_writer = AbstractNodeWriter.new self
27
+ raw_writer = RawTextBlockWriter.new self
25
28
  page_writer = TagWriter.create('body', self,
26
29
  node_preprocessor: proc do |node|
27
30
  @context.end_html
@@ -33,43 +36,42 @@ module NoraMark
33
36
  end
34
37
  node
35
38
  end);
36
-
39
+
37
40
  @writers = {
41
+ Text => raw_writer,
38
42
  Paragraph => paragraph_writer,
39
43
  ParagraphGroup => paragraph_writer,
40
- Inline =>TagWriter.create(nil, self, trailer: ''),
44
+ Inline => TagWriter.create(nil, self, trailer: ''),
41
45
  Block => TagWriter.create(nil, self),
42
- Document => abstract_node_writer,
43
- Page => page_writer,
44
- Frontmatter => frontmatter_writer,
45
- }
46
+ Document => abstract_node_writer,
47
+ Page => page_writer,
48
+ Frontmatter => frontmatter_writer,
49
+ }
46
50
  end
47
51
 
48
- def collect_id_and_headings
52
+ def collect_id_and_headings
49
53
  @id_pool = {}
50
54
  @headings = []
51
55
 
52
56
  all_nodes = @parsed_result.all_nodes
53
- all_nodes.each do
54
- |x|
57
+ all_nodes.each do |x|
55
58
  x.ids ||= []
56
- x.ids.each do
57
- |id|
59
+ x.ids.each do |id|
58
60
  if !@id_pool[id].nil?
59
61
  warn "duplicate id #{id}"
60
62
  end
61
63
  @id_pool[id] = x
62
64
  end
63
- @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]/)
64
66
  end
65
67
  end
66
- def assign_id_to_headings
68
+
69
+ def assign_id_to_headings
67
70
  collect_id_and_headings
68
71
  count = 1
69
- @headings.each do
70
- |heading|
71
- if heading.ids.size == 0
72
- begin
72
+ @headings.each do |heading|
73
+ if heading.ids.size == 0
74
+ begin
73
75
  id = "heading_index_#{count}"
74
76
  count = count + 1
75
77
  end while @id_pool[id]
@@ -82,13 +84,12 @@ module NoraMark
82
84
  transformer = Html.default_transformer
83
85
  transformer.options[:render_parameter] = render_parameter
84
86
  @parsed_result = transformer.transform parsed_result
85
- assign_id_to_headings
87
+ assign_id_to_headings
86
88
 
87
89
  children = parsed_result.children
88
90
  @context.file_basename = parsed_result.document_name
89
91
  @context.render_parameter = render_parameter
90
- children.each {
91
- |node|
92
+ children.each { |node|
92
93
  to_html(node)
93
94
  }
94
95
  @context.set_toc generate_toc
@@ -96,8 +97,7 @@ module NoraMark
96
97
  end
97
98
 
98
99
  def generate_toc
99
- @headings.map do
100
- |heading|
100
+ @headings.map do |heading|
101
101
  { page: heading.ancestors(type: :Page)[0].page_no }.merge heading.heading_info
102
102
  end
103
103
  end