nora_mark 0.2beta3 → 0.2beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/README.md +17 -12
- data/example/nora-simple.css +52 -0
- data/example/noramark-reference-ja.nora +246 -0
- data/example/noramark-reference-ja_00001.xhtml +187 -0
- data/lib/nora_mark/html/{abstract_item_writer.rb → abstract_node_writer.rb} +3 -3
- data/lib/nora_mark/html/context.rb +3 -21
- data/lib/nora_mark/html/frontmatter_writer.rb +33 -0
- data/lib/nora_mark/html/generator.rb +122 -100
- data/lib/nora_mark/html/pages.rb +3 -9
- data/lib/nora_mark/html/paragraph_writer.rb +27 -23
- data/lib/nora_mark/html/tag_writer.rb +33 -34
- data/lib/nora_mark/html/writer_selector.rb +3 -3
- data/lib/nora_mark/node.rb +31 -0
- data/lib/nora_mark/parser.kpeg +133 -79
- data/lib/nora_mark/parser.kpeg.rb +1822 -1526
- data/lib/nora_mark/parser.rb +4 -23
- data/lib/nora_mark/version.rb +1 -1
- data/lib/nora_mark.rb +7 -2
- data/nora_mark.gemspec +1 -0
- data/spec/epub30-schemas/epub-nav-30.nvdl +16 -0
- data/spec/epub30-schemas/epub-nav-30.rnc +10 -0
- data/spec/epub30-schemas/epub-nav-30.sch +72 -0
- data/spec/epub30-schemas/epub-svg-30.nvdl +15 -0
- data/spec/epub30-schemas/epub-svg-30.rnc +15 -0
- data/spec/epub30-schemas/epub-svg-30.sch +10 -0
- data/spec/epub30-schemas/epub-xhtml-30.nvdl +15 -0
- data/spec/epub30-schemas/epub-xhtml-30.rnc +37 -0
- data/spec/epub30-schemas/epub-xhtml-30.sch +377 -0
- data/spec/epub30-schemas/epub30-catalog.xml +335 -0
- data/spec/epub30-schemas/media-overlay-30.nvdl +14 -0
- data/spec/epub30-schemas/media-overlay-30.rnc +46 -0
- data/spec/epub30-schemas/media-overlay-30.sch +9 -0
- data/spec/epub30-schemas/mod/datatypes.rnc +143 -0
- data/spec/epub30-schemas/mod/epub-mathml3-30.rnc +74 -0
- data/spec/epub30-schemas/mod/epub-prefix-attr.rnc +8 -0
- data/spec/epub30-schemas/mod/epub-ssml-attrs.rnc +11 -0
- data/spec/epub30-schemas/mod/epub-svg11-30.rnc +12 -0
- data/spec/epub30-schemas/mod/epub-svg11-re.sch +7 -0
- data/spec/epub30-schemas/mod/epub-switch.rnc +32 -0
- data/spec/epub30-schemas/mod/epub-trigger.rnc +17 -0
- data/spec/epub30-schemas/mod/epub-type-attr.rnc +7 -0
- data/spec/epub30-schemas/mod/epub-xhtml-mathml3-30.rnc +5 -0
- data/spec/epub30-schemas/mod/epub-xhtml-svg11-30.rnc +6 -0
- data/spec/epub30-schemas/mod/html5/LICENSE +23 -0
- data/spec/epub30-schemas/mod/html5/README +21 -0
- data/spec/epub30-schemas/mod/html5/html5-aria-30.rnc +105 -0
- data/spec/epub30-schemas/mod/html5/html5-attrib-30.rnc +44 -0
- data/spec/epub30-schemas/mod/html5/html5-document-30.rnc +44 -0
- data/spec/epub30-schemas/mod/html5/html5-edit-30.rnc +24 -0
- data/spec/epub30-schemas/mod/html5/html5-embed-30.rnc +155 -0
- data/spec/epub30-schemas/mod/html5/html5-forms-30.rnc +431 -0
- data/spec/epub30-schemas/mod/html5/html5-grouping-30.rnc +115 -0
- data/spec/epub30-schemas/mod/html5/html5-interactive-30.rnc +86 -0
- data/spec/epub30-schemas/mod/html5/html5-models-30.rnc +10 -0
- data/spec/epub30-schemas/mod/html5/html5-phrasing-30.rnc +134 -0
- data/spec/epub30-schemas/mod/html5/html5-script-30.rnc +164 -0
- data/spec/epub30-schemas/mod/html5/html5-sections-30.rnc +58 -0
- data/spec/epub30-schemas/mod/html5/html5-style-30.rnc +18 -0
- data/spec/epub30-schemas/mod/id-unique.sch +10 -0
- data/spec/epub30-schemas/mod/mathml/LICENSE +3 -0
- data/spec/epub30-schemas/mod/mathml/mathml3-common.rnc +84 -0
- data/spec/epub30-schemas/mod/mathml/mathml3-content.rnc +373 -0
- data/spec/epub30-schemas/mod/mathml/mathml3-presentation.rnc +536 -0
- data/spec/epub30-schemas/mod/mathml/mathml3-strict-content.rnc +60 -0
- data/spec/epub30-schemas/mod/security/LICENSE +4 -0
- data/spec/epub30-schemas/mod/security/Lenient-Encryption11-ghc.rnc +41 -0
- data/spec/epub30-schemas/mod/security/Lenient-Encryption11.rnc +39 -0
- data/spec/epub30-schemas/mod/security/Lenient-Signature-exclusiveC14N.rnc +25 -0
- data/spec/epub30-schemas/mod/security/Lenient-Signature11-properties-exclusiveC14N.rnc +32 -0
- data/spec/epub30-schemas/mod/security/Lenient-Signature11-properties.rnc +30 -0
- data/spec/epub30-schemas/mod/security/Lenient-Signature11.rnc +28 -0
- data/spec/epub30-schemas/mod/security/Strict-Encryption.rnc +27 -0
- data/spec/epub30-schemas/mod/security/Strict-Signature.rnc +22 -0
- data/spec/epub30-schemas/mod/security/exc-c14n.rnc +39 -0
- data/spec/epub30-schemas/mod/security/security_any.rnc +15 -0
- data/spec/epub30-schemas/mod/security/xenc-allowAnyForeign.rnc +25 -0
- data/spec/epub30-schemas/mod/security/xenc-schema-11.rnc +96 -0
- data/spec/epub30-schemas/mod/security/xenc-schema.rnc +145 -0
- data/spec/epub30-schemas/mod/security/xenc11-allowAnyForeign.rnc +19 -0
- data/spec/epub30-schemas/mod/security/xmldsig-allowAnyForeign.rnc +47 -0
- data/spec/epub30-schemas/mod/security/xmldsig-core-schema.rnc +276 -0
- data/spec/epub30-schemas/mod/security/xmldsig-filter2.rnc +16 -0
- data/spec/epub30-schemas/mod/security/xmldsig-properties-schema.rnc +34 -0
- data/spec/epub30-schemas/mod/security/xmldsig11-allowAnyForeign.rnc +18 -0
- data/spec/epub30-schemas/mod/security/xmldsig11-schema.rnc +133 -0
- data/spec/epub30-schemas/mod/security/xmlsec-ghc-allowAnyForeign.rnc +21 -0
- data/spec/epub30-schemas/mod/security/xmlsec-ghc-schema.rnc +42 -0
- data/spec/epub30-schemas/mod/svg11/LICENSE +1 -0
- data/spec/epub30-schemas/mod/svg11/README.txt +8 -0
- data/spec/epub30-schemas/mod/svg11/svg11-flat.rnc +3999 -0
- data/spec/epub30-schemas/ocf-container-30.rnc +16 -0
- data/spec/epub30-schemas/ocf-encryption-30.rnc +12 -0
- data/spec/epub30-schemas/ocf-signatures-30.rnc +8 -0
- data/spec/epub30-schemas/package-30.nvdl +14 -0
- data/spec/epub30-schemas/package-30.rnc +91 -0
- data/spec/epub30-schemas/package-30.sch +137 -0
- data/spec/jing-20091111/bin/jing.jar +0 -0
- data/spec/nora_mark_spec.rb +229 -68
- data/spec/spec_helper.rb +16 -0
- metadata +179 -6
- data/lib/nora_mark/html/header_writer.rb +0 -35
- data/spec/fixture/test_src_ja.nora +0 -50
data/lib/nora_mark/parser.rb
CHANGED
@@ -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
|
6
|
-
|
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
|
|
data/lib/nora_mark/version.rb
CHANGED
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(
|
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
@@ -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']) < 2">Multiple occurrences of
|
12
|
+
the 'page-list' nav element</assert>
|
13
|
+
<assert test="count(.//html:nav[@epub:type='landmarks']) < 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,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
|
+
|