nora_mark 0.2beta3 → 0.2beta4

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.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -0
  3. data/Gemfile +2 -0
  4. data/README.md +17 -12
  5. data/example/nora-simple.css +52 -0
  6. data/example/noramark-reference-ja.nora +246 -0
  7. data/example/noramark-reference-ja_00001.xhtml +187 -0
  8. data/lib/nora_mark/html/{abstract_item_writer.rb → abstract_node_writer.rb} +3 -3
  9. data/lib/nora_mark/html/context.rb +3 -21
  10. data/lib/nora_mark/html/frontmatter_writer.rb +33 -0
  11. data/lib/nora_mark/html/generator.rb +122 -100
  12. data/lib/nora_mark/html/pages.rb +3 -9
  13. data/lib/nora_mark/html/paragraph_writer.rb +27 -23
  14. data/lib/nora_mark/html/tag_writer.rb +33 -34
  15. data/lib/nora_mark/html/writer_selector.rb +3 -3
  16. data/lib/nora_mark/node.rb +31 -0
  17. data/lib/nora_mark/parser.kpeg +133 -79
  18. data/lib/nora_mark/parser.kpeg.rb +1822 -1526
  19. data/lib/nora_mark/parser.rb +4 -23
  20. data/lib/nora_mark/version.rb +1 -1
  21. data/lib/nora_mark.rb +7 -2
  22. data/nora_mark.gemspec +1 -0
  23. data/spec/epub30-schemas/epub-nav-30.nvdl +16 -0
  24. data/spec/epub30-schemas/epub-nav-30.rnc +10 -0
  25. data/spec/epub30-schemas/epub-nav-30.sch +72 -0
  26. data/spec/epub30-schemas/epub-svg-30.nvdl +15 -0
  27. data/spec/epub30-schemas/epub-svg-30.rnc +15 -0
  28. data/spec/epub30-schemas/epub-svg-30.sch +10 -0
  29. data/spec/epub30-schemas/epub-xhtml-30.nvdl +15 -0
  30. data/spec/epub30-schemas/epub-xhtml-30.rnc +37 -0
  31. data/spec/epub30-schemas/epub-xhtml-30.sch +377 -0
  32. data/spec/epub30-schemas/epub30-catalog.xml +335 -0
  33. data/spec/epub30-schemas/media-overlay-30.nvdl +14 -0
  34. data/spec/epub30-schemas/media-overlay-30.rnc +46 -0
  35. data/spec/epub30-schemas/media-overlay-30.sch +9 -0
  36. data/spec/epub30-schemas/mod/datatypes.rnc +143 -0
  37. data/spec/epub30-schemas/mod/epub-mathml3-30.rnc +74 -0
  38. data/spec/epub30-schemas/mod/epub-prefix-attr.rnc +8 -0
  39. data/spec/epub30-schemas/mod/epub-ssml-attrs.rnc +11 -0
  40. data/spec/epub30-schemas/mod/epub-svg11-30.rnc +12 -0
  41. data/spec/epub30-schemas/mod/epub-svg11-re.sch +7 -0
  42. data/spec/epub30-schemas/mod/epub-switch.rnc +32 -0
  43. data/spec/epub30-schemas/mod/epub-trigger.rnc +17 -0
  44. data/spec/epub30-schemas/mod/epub-type-attr.rnc +7 -0
  45. data/spec/epub30-schemas/mod/epub-xhtml-mathml3-30.rnc +5 -0
  46. data/spec/epub30-schemas/mod/epub-xhtml-svg11-30.rnc +6 -0
  47. data/spec/epub30-schemas/mod/html5/LICENSE +23 -0
  48. data/spec/epub30-schemas/mod/html5/README +21 -0
  49. data/spec/epub30-schemas/mod/html5/html5-aria-30.rnc +105 -0
  50. data/spec/epub30-schemas/mod/html5/html5-attrib-30.rnc +44 -0
  51. data/spec/epub30-schemas/mod/html5/html5-document-30.rnc +44 -0
  52. data/spec/epub30-schemas/mod/html5/html5-edit-30.rnc +24 -0
  53. data/spec/epub30-schemas/mod/html5/html5-embed-30.rnc +155 -0
  54. data/spec/epub30-schemas/mod/html5/html5-forms-30.rnc +431 -0
  55. data/spec/epub30-schemas/mod/html5/html5-grouping-30.rnc +115 -0
  56. data/spec/epub30-schemas/mod/html5/html5-interactive-30.rnc +86 -0
  57. data/spec/epub30-schemas/mod/html5/html5-models-30.rnc +10 -0
  58. data/spec/epub30-schemas/mod/html5/html5-phrasing-30.rnc +134 -0
  59. data/spec/epub30-schemas/mod/html5/html5-script-30.rnc +164 -0
  60. data/spec/epub30-schemas/mod/html5/html5-sections-30.rnc +58 -0
  61. data/spec/epub30-schemas/mod/html5/html5-style-30.rnc +18 -0
  62. data/spec/epub30-schemas/mod/id-unique.sch +10 -0
  63. data/spec/epub30-schemas/mod/mathml/LICENSE +3 -0
  64. data/spec/epub30-schemas/mod/mathml/mathml3-common.rnc +84 -0
  65. data/spec/epub30-schemas/mod/mathml/mathml3-content.rnc +373 -0
  66. data/spec/epub30-schemas/mod/mathml/mathml3-presentation.rnc +536 -0
  67. data/spec/epub30-schemas/mod/mathml/mathml3-strict-content.rnc +60 -0
  68. data/spec/epub30-schemas/mod/security/LICENSE +4 -0
  69. data/spec/epub30-schemas/mod/security/Lenient-Encryption11-ghc.rnc +41 -0
  70. data/spec/epub30-schemas/mod/security/Lenient-Encryption11.rnc +39 -0
  71. data/spec/epub30-schemas/mod/security/Lenient-Signature-exclusiveC14N.rnc +25 -0
  72. data/spec/epub30-schemas/mod/security/Lenient-Signature11-properties-exclusiveC14N.rnc +32 -0
  73. data/spec/epub30-schemas/mod/security/Lenient-Signature11-properties.rnc +30 -0
  74. data/spec/epub30-schemas/mod/security/Lenient-Signature11.rnc +28 -0
  75. data/spec/epub30-schemas/mod/security/Strict-Encryption.rnc +27 -0
  76. data/spec/epub30-schemas/mod/security/Strict-Signature.rnc +22 -0
  77. data/spec/epub30-schemas/mod/security/exc-c14n.rnc +39 -0
  78. data/spec/epub30-schemas/mod/security/security_any.rnc +15 -0
  79. data/spec/epub30-schemas/mod/security/xenc-allowAnyForeign.rnc +25 -0
  80. data/spec/epub30-schemas/mod/security/xenc-schema-11.rnc +96 -0
  81. data/spec/epub30-schemas/mod/security/xenc-schema.rnc +145 -0
  82. data/spec/epub30-schemas/mod/security/xenc11-allowAnyForeign.rnc +19 -0
  83. data/spec/epub30-schemas/mod/security/xmldsig-allowAnyForeign.rnc +47 -0
  84. data/spec/epub30-schemas/mod/security/xmldsig-core-schema.rnc +276 -0
  85. data/spec/epub30-schemas/mod/security/xmldsig-filter2.rnc +16 -0
  86. data/spec/epub30-schemas/mod/security/xmldsig-properties-schema.rnc +34 -0
  87. data/spec/epub30-schemas/mod/security/xmldsig11-allowAnyForeign.rnc +18 -0
  88. data/spec/epub30-schemas/mod/security/xmldsig11-schema.rnc +133 -0
  89. data/spec/epub30-schemas/mod/security/xmlsec-ghc-allowAnyForeign.rnc +21 -0
  90. data/spec/epub30-schemas/mod/security/xmlsec-ghc-schema.rnc +42 -0
  91. data/spec/epub30-schemas/mod/svg11/LICENSE +1 -0
  92. data/spec/epub30-schemas/mod/svg11/README.txt +8 -0
  93. data/spec/epub30-schemas/mod/svg11/svg11-flat.rnc +3999 -0
  94. data/spec/epub30-schemas/ocf-container-30.rnc +16 -0
  95. data/spec/epub30-schemas/ocf-encryption-30.rnc +12 -0
  96. data/spec/epub30-schemas/ocf-signatures-30.rnc +8 -0
  97. data/spec/epub30-schemas/package-30.nvdl +14 -0
  98. data/spec/epub30-schemas/package-30.rnc +91 -0
  99. data/spec/epub30-schemas/package-30.sch +137 -0
  100. data/spec/jing-20091111/bin/jing.jar +0 -0
  101. data/spec/nora_mark_spec.rb +229 -68
  102. data/spec/spec_helper.rb +16 -0
  103. metadata +179 -6
  104. data/lib/nora_mark/html/header_writer.rb +0 -35
  105. data/spec/fixture/test_src_ja.nora +0 -50
@@ -1,31 +1,12 @@
1
+ require 'nora_mark/node'
1
2
  require 'nora_mark/parser.kpeg'
2
3
 
3
4
  module NoraMark
4
5
  class Parser
5
- def create_item(type, command, children = [], raw: nil)
6
- children[0].sub!(/^[[:space:]]+/, '') if !children.nil? && children[0].is_a?(String)
7
- item = {:type => type, :children => children, :raw_text => raw }.merge command || {}
8
- item[:args] ||= []
9
- item[:named_args] = Hash[*(item[:args].select { |x| x.include?(':') }.map { |x| v = x.split(':', 2); [v[0].strip.to_sym, v[1]]}.flatten)]
10
- item
11
- end
12
-
13
- def parse_text(content)
14
- content.inject([]) do
15
- |result, item|
16
- if item.is_a? String
17
- s = result.last
18
- if s.is_a? String
19
- result.pop
20
- else
21
- s = ''
22
- end
23
- result.push s + item
24
- else
25
- result.push item
26
- end
27
- end
6
+ def initialize(src)
7
+ super src
28
8
  end
9
+
29
10
  end
30
11
  end
31
12
 
@@ -1,3 +1,3 @@
1
1
  module NoraMark
2
- VERSION = "0.2beta3"
2
+ VERSION = "0.2beta4"
3
3
  end
data/lib/nora_mark.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  require "nora_mark/version"
2
2
  require 'nora_mark/html/generator'
3
+ require 'nora_mark/node'
3
4
  require 'nora_mark/parser'
5
+ require 'securerandom'
4
6
 
5
7
  module NoraMark
6
- class Document
8
+ class Document < Node
9
+ attr_accessor :document_name
7
10
  private_class_method :new
8
11
 
9
12
  def self.parse(string_or_io, param = {})
@@ -19,6 +22,7 @@ module NoraMark
19
22
  if (!@parser.parse)
20
23
  raise @parser.raise_error
21
24
  end
25
+ @content = @parser.result
22
26
  end
23
27
  instance
24
28
  end
@@ -29,7 +33,7 @@ module NoraMark
29
33
 
30
34
  def html
31
35
  if @html.nil?
32
- @html = @html_generator.convert(@parser.result)
36
+ @html = @html_generator.convert(self)
33
37
  end
34
38
  @html
35
39
  end
@@ -39,6 +43,7 @@ module NoraMark
39
43
  Proc.new { |text| text.gsub(/\r?\n(\r?\n)+/, "\n\n") },
40
44
  ]
41
45
  @html_generator = Html::Generator.new(param)
46
+ @document_name = param[:document_name] || "noramark_#{SecureRandom.uuid}"
42
47
  end
43
48
 
44
49
 
data/nora_mark.gemspec CHANGED
@@ -18,5 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.required_ruby_version = '>= 2.0.0'
19
19
  gem.add_dependency "kpeg"
20
20
  gem.add_development_dependency "rspec", "~> 2.14"
21
+ gem.add_development_dependency "rake"
21
22
  gem.add_development_dependency "nokogiri", "~> 1.6.0"
22
23
  end
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="html">
3
+ <mode name="html">
4
+ <namespace ns="http://www.w3.org/1999/xhtml">
5
+ <validate schema="epub-nav-30.rnc" schemaType="application/relax-ng-compact-syntax"
6
+ useMode="attach"/>
7
+ <validate schema="epub-xhtml-30.sch" useMode="attach"/>
8
+ <validate schema="epub-nav-30.sch" useMode="attach"/>
9
+ </namespace>
10
+ </mode>
11
+ <mode name="attach">
12
+ <anyNamespace>
13
+ <attach/>
14
+ </anyNamespace>
15
+ </mode>
16
+ </rules>
@@ -0,0 +1,10 @@
1
+
2
+
3
+ default namespace = "http://www.w3.org/1999/xhtml"
4
+ namespace epub = "http://www.idpf.org/2007/ops"
5
+
6
+ include "epub-xhtml-30.rnc" {
7
+ html5.nav.content = html5.headings.class?, html5.ol
8
+ html5.oli.content = html5.a.phrasing | ((html5.a.phrasing | html5.span), html5.ol)
9
+ }
10
+
@@ -0,0 +1,72 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <schema xmlns="http://purl.oclc.org/dsdl/schematron">
3
+
4
+ <ns uri="http://www.w3.org/1999/xhtml" prefix="html"/>
5
+ <ns uri="http://www.idpf.org/2007/ops" prefix="epub"/>
6
+
7
+ <pattern id="nav-ocurrence">
8
+ <rule context="html:body">
9
+ <assert test="count(.//html:nav[@epub:type='toc']) = 1">Exactly one 'toc' nav element
10
+ must be present</assert>
11
+ <assert test="count(.//html:nav[@epub:type='page-list']) &lt; 2">Multiple occurrences of
12
+ the 'page-list' nav element</assert>
13
+ <assert test="count(.//html:nav[@epub:type='landmarks']) &lt; 2">Multiple occurrences of
14
+ the 'landmarks' nav element</assert>
15
+ </rule>
16
+ </pattern>
17
+
18
+ <pattern id="span-no-sublist">
19
+ <rule context="html:body//html:nav//html:span">
20
+ <assert test="count(.//ol) = 0"> The span element must only be used as heading for flat
21
+ sublists (not hierarchical navigation structures) </assert>
22
+ </rule>
23
+ </pattern>
24
+
25
+ <pattern id="landmarks">
26
+ <rule context="html:nav[@epub:type='landmarks']//html:ol//html:a">
27
+ <assert test="@epub:type">Missing epub:type attribute on anchor inside 'landmarks' nav
28
+ element</assert>
29
+ </rule>
30
+ </pattern>
31
+
32
+ <pattern id="link-labels">
33
+ <rule context="html:nav//html:ol//html:a">
34
+ <assert test="string-length(normalize-space(string(.))) > 0">Anchors within nav elements
35
+ must contain text</assert>
36
+ </rule>
37
+ </pattern>
38
+
39
+ <pattern id="span-labels">
40
+ <rule context="html:nav//html:ol//html:span">
41
+ <assert test="string-length(normalize-space(string(.))) > 0">Spans within nav elements
42
+ must contain text</assert>
43
+ </rule>
44
+ </pattern>
45
+
46
+ <pattern id="req-heading">
47
+ <rule
48
+ context="html:nav[not(@epub:type = 'toc') and not (@epub:type = 'page-list') and not (@epub:type = 'landmarks')]">
49
+ <let name="fc" value="local-name(./*[1])"/>
50
+ <assert test="(starts-with($fc,'h') and string-length($fc) = 2) or ($fc = 'hgroup')">nav
51
+ elements other than 'toc', 'page-list' and 'landmarks' must contain a heading as the
52
+ first child</assert>
53
+ </rule>
54
+ </pattern>
55
+
56
+ <pattern id="heading-content">
57
+ <rule context="html:h1|html:h2|html:h3|html:h4|html:h5|html:h6|html:hgroup">
58
+ <assert test="string-length(normalize-space(string(.))) > 0">Heading elements must
59
+ contain text</assert>
60
+ </rule>
61
+ </pattern>
62
+
63
+
64
+ <!-- warnings mode <pattern id="page-list-flat">
65
+ <rule context="html:body//html:nav[@epub:type='page-list']">
66
+ <assert test="count(.//html:ol) = 1">The page-list navigation structure should be a
67
+ list, not a nested hierarchy</assert>
68
+ </rule>
69
+ </pattern>
70
+ -->
71
+
72
+ </schema>
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="svg">
3
+ <mode name="svg">
4
+ <namespace ns="http://www.w3.org/2000/svg">
5
+ <validate schema="epub-svg-30.rnc" schemaType="application/relax-ng-compact-syntax"
6
+ useMode="attach"/>
7
+ <validate schema="epub-svg-30.sch" useMode="attach"/>
8
+ </namespace>
9
+ </mode>
10
+ <mode name="attach">
11
+ <anyNamespace>
12
+ <attach/>
13
+ </anyNamespace>
14
+ </mode>
15
+ </rules>
@@ -0,0 +1,15 @@
1
+
2
+ namespace x = "http://www.w3.org/1999/xhtml"
3
+
4
+ include "./mod/html5/html5-grouping-30.rnc" inherit = x
5
+ include "./mod/html5/html5-phrasing-30.rnc" inherit = x
6
+ include "./mod/html5/html5-sections-30.rnc" inherit = x
7
+ include "./mod/html5/html5-style-30.rnc" inherit = x
8
+ include "./mod/epub-ssml-attrs.rnc"
9
+
10
+ include "./mod/html5/html5-attrib-30.rnc"
11
+
12
+ include "./mod/datatypes.rnc"
13
+ include "./mod/html5/html5-models-30.rnc"
14
+
15
+ start = external "mod/epub-svg11-30.rnc"
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <schema xmlns="http://purl.oclc.org/dsdl/schematron">
3
+
4
+ <ns uri="http://www.w3.org/2000/svg" prefix="svg" />
5
+
6
+ <include href="./mod/id-unique.sch"/>
7
+ <include href="./mod/epub-svg11-re.sch"/>
8
+
9
+ </schema>
10
+
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0" startMode="html">
3
+ <mode name="html">
4
+ <namespace ns="http://www.w3.org/1999/xhtml">
5
+ <validate schema="epub-xhtml-30.rnc" schemaType="application/relax-ng-compact-syntax"
6
+ useMode="attach"/>
7
+ <validate schema="epub-xhtml-30.sch" useMode="attach"/>
8
+ </namespace>
9
+ </mode>
10
+ <mode name="attach">
11
+ <anyNamespace>
12
+ <attach/>
13
+ </anyNamespace>
14
+ </mode>
15
+ </rules>
@@ -0,0 +1,37 @@
1
+
2
+
3
+
4
+ default namespace = "http://www.w3.org/1999/xhtml"
5
+
6
+ include "./mod/html5/html5-document-30.rnc"
7
+
8
+ include "./mod/html5/html5-sections-30.rnc"
9
+ include "./mod/html5/html5-grouping-30.rnc"
10
+ include "./mod/html5/html5-phrasing-30.rnc"
11
+ include "./mod/html5/html5-embed-30.rnc"
12
+
13
+ include "./mod/html5/html5-edit-30.rnc"
14
+ include "./mod/html5/html5-style-30.rnc"
15
+ include "./mod/html5/html5-script-30.rnc"
16
+ include "./mod/html5/html5-interactive-30.rnc"
17
+ include "./mod/html5/html5-forms-30.rnc"
18
+
19
+ include "./mod/html5/html5-attrib-30.rnc"
20
+ include "./mod/html5/html5-aria-30.rnc"
21
+
22
+ include "./mod/datatypes.rnc"
23
+ include "./mod/html5/html5-models-30.rnc"
24
+
25
+ include "./mod/epub-xhtml-mathml3-30.rnc"
26
+ include "./mod/epub-xhtml-svg11-30.rnc"
27
+
28
+ include "./mod/epub-trigger.rnc"
29
+ include "./mod/epub-switch.rnc"
30
+
31
+ include "./mod/epub-type-attr.rnc"
32
+ include "./mod/epub-prefix-attr.rnc"
33
+ include "./mod/epub-ssml-attrs.rnc"
34
+
35
+ start = html5.html
36
+
37
+