Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disallow epub:type on head and metadata content #1459

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace local = ""
namespace x = "http://www.w3.org/1999/xhtml"
namespace ev = "http://www.w3.org/2001/xml-events"
namespace ssml = "http://www.w3.org/2001/10/synthesis"
namespace epub = "http://www.idpf.org/2007/ops"

# #####################################################################
#
Expand All @@ -19,7 +20,7 @@ include "mathml/mathml3-inc.rnc" {

# extend to circumvent datatype collisions
NonMathMLAtt =
attribute * - (local:* | m:* | xml:* | x:* | ev:* | ssml:*) {
attribute * - (local:* | m:* | xml:* | x:* | ev:* | ssml:* | epub:*) {
datatype.string
}

Expand All @@ -30,6 +31,8 @@ include "mathml/mathml3-inc.rnc" {
annotation-xml = epub.annotation-xml
}
# Common attribute extensions
# - epub:type
CommonAtt &= epub.type.attr?
# - SSML attributes
CommonAtt &= epub.ssml.ph.attr?
# - xml:base
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,141 @@

## combine `epub:type`

# Allow `epub:type` on the `body` element (even though
# it is not defined as palpable content)
body.attrs &= epub.type.attr?

# Allow `epub:type` on palpable content
# Allow `epub:type` on all elements except:
# - the `head` element
# - metadata content (base, link, meta, noscript, script, style, template, title)
#
# Note:
# We can't use a common category since none is defined
# for palpable content. So we add it for each element.
#
# Some elements are only considered palpable under some
# conditions; we do not support that at the moment.
#
a.attrs &= epub.type.attr?
abbr.attrs &= epub.type.attr?
address.attrs &= epub.type.attr?
article.attrs &= epub.type.attr?
aside.attrs &= epub.type.attr?
audio.attrs &= epub.type.attr?
b.attrs &= epub.type.attr?
bdi.attrs &= epub.type.attr?
bdo.attrs &= epub.type.attr?
blockquote.attrs &= epub.type.attr?
button.attrs &= epub.type.attr?
# for non-metadata content. So we add it for each element.

# from applications.rnc
progress.attrs &= epub.type.attr?
dialog.attrs &= epub.type.attr?
menu.attrs &= epub.type.attr?
mli.attrs &= epub.type.attr?
canvas.attrs &= epub.type.attr?
cite.attrs &= epub.type.attr?
code.attrs &= epub.type.attr?
data.attrs &= epub.type.attr?
details.attrs &= epub.type.attr?
dfn.attrs &= epub.type.attr?
div.attrs &= epub.type.attr?
summary.attrs &= epub.type.attr?

# from block.rnc
p.attrs &= epub.type.attr?
hr.attrs &= epub.type.attr?
pre.attrs &= epub.type.attr?
ul.attrs &= epub.type.attr?
li.attrs &= epub.type.attr?
ol.attrs &= epub.type.attr?
oli.attrs &= epub.type.attr?
dl.attrs &= epub.type.attr?
emembed.attrs &= epub.type.attr?
fieldset.attrs &= epub.type.attr?
dt.attrs &= epub.type.attr?
dd.attrs &= epub.type.attr?
div.attrs &= epub.type.attr?
legend.attrs &= epub.type.attr?

# from data.rnc
time.attrs &= epub.type.attr?
time.datetime.attrs &= epub.type.attr?
data.attrs &= epub.type.attr?
meter.attrs &= epub.type.attr?

# from embed.rnc
img.attrs &= epub.type.attr?
picture.attrs &= epub.type.attr?
embed.attrs &= epub.type.attr?
object.attrs &= epub.type.attr?
param.attrs &= epub.type.attr?
iframe.attrs &= epub.type.attr?
map.attrs &= epub.type.attr?
area.attrs &= epub.type.attr?

# from media.rnc
source.attrs &= epub.type.attr?
video.attrs &= epub.type.attr?
audio.attrs &= epub.type.attr?
track.attrs &= epub.type.attr?
figure.attrs &= epub.type.attr?
footer.attrs &= epub.type.attr?
form.attrs &= epub.type.attr?
figcaption.attrs &= epub.type.attr?

# from meta.rnc
html.attrs &= epub.type.attr?
body.attrs &= epub.type.attr?

# from phrase.rnc
a.href.attrs &= epub.type.attr?
a.nohref.attrs &= epub.type.attr?
em.attrs &= epub.type.attr?
strong.attrs &= epub.type.attr?
small.attrs &= epub.type.attr?
mark.attrs &= epub.type.attr?
abbr.attrs &= epub.type.attr?
dfn.attrs &= epub.type.attr?
i.attrs &= epub.type.attr?
b.attrs &= epub.type.attr?
s.attrs &= epub.type.attr?
u.attrs &= epub.type.attr?
code.attrs &= epub.type.attr?
var.attrs &= epub.type.attr?
samp.attrs &= epub.type.attr?
kbd.attrs &= epub.type.attr?
sup.attrs &= epub.type.attr?
sub.attrs &= epub.type.attr?
q.attrs &= epub.type.attr?
cite.attrs &= epub.type.attr?
span.attrs &= epub.type.attr?
bdo.attrs &= epub.type.attr?
bdi.attrs &= epub.type.attr?
br.attrs &= epub.type.attr?
wbr.attrs &= epub.type.attr?

# from revision.rnc
ins.attrs &= epub.type.attr?
del.attrs &= epub.type.attr?

# from ruby.rnc
ruby.attrs &= epub.type.attr?
rt.attrs &= epub.type.attr?
rp.attrs &= epub.type.attr?

# from sectional.rnc
h1.attrs &= epub.type.attr?
h2.attrs &= epub.type.attr?
h3.attrs &= epub.type.attr?
h4.attrs &= epub.type.attr?
h5.attrs &= epub.type.attr?
h6.attrs &= epub.type.attr?
header.attrs &= epub.type.attr?
hgroup.attrs &= epub.type.attr?
i.attrs &= epub.type.attr?
iframe.attrs &= epub.type.attr?
img.attrs &= epub.type.attr?
input.attrs &= epub.type.attr?
ins.attrs &= epub.type.attr?
kbd.attrs &= epub.type.attr?
label.attrs &= epub.type.attr?
main.attrs &= epub.type.attr?
map.attrs &= epub.type.attr?
mark.attrs &= epub.type.attr?
menu.attrs &= epub.type.attr?
meter.attrs &= epub.type.attr?
nav.attrs &= epub.type.attr?
object.attrs &= epub.type.attr?
ol.attrs &= epub.type.attr?
output.attrs &= epub.type.attr?
p.attrs &= epub.type.attr?
pre.attrs &= epub.type.attr?
progress.attrs &= epub.type.attr?
q.attrs &= epub.type.attr?
ruby.attrs &= epub.type.attr?
s.attrs &= epub.type.attr?
samp.attrs &= epub.type.attr?
address.attrs &= epub.type.attr?
blockquote.attrs &= epub.type.attr?

# from structural.rnc
section.attrs &= epub.type.attr?
select.attrs &= epub.type.attr?
small.attrs &= epub.type.attr?
span.attrs &= epub.type.attr?
strong.attrs &= epub.type.attr?
sub.attrs &= epub.type.attr?
sup.attrs &= epub.type.attr?
nav.attrs &= epub.type.attr?
article.attrs &= epub.type.attr?
aside.attrs &= epub.type.attr?
header.attrs &= epub.type.attr?
footer.attrs &= epub.type.attr?
main.attrs &= epub.type.attr?

# from tables.rnc
table.attrs &= epub.type.attr?
text.attrs &= epub.type.attr?
area.attrs &= epub.type.attr?
time.attrs &= epub.type.attr?
u.attrs &= epub.type.attr?
ul.attrs &= epub.type.attr?
var.attrs &= epub.type.attr?
video.attrs &= epub.type.attr?
caption.attrs &= epub.type.attr?
colgroup.attrs &= epub.type.attr?
thead.attrs &= epub.type.attr?
tfoot.attrs &= epub.type.attr?
tbody.attrs &= epub.type.attr?
tr.attrs &= epub.type.attr?
td.attrs &= epub.type.attr?
th.attrs &= epub.type.attr?

# from web-forms.rnc and web-forms2.rnc
common-form.attrs &= epub.type.attr?
option.attrs &= epub.type.attr?
optgroup.attrs &= epub.type.attr?
form.attrs &= epub.type.attr?
label.attrs &= epub.type.attr?
output.attrs &= epub.type.attr?
datalist.attrs &= epub.type.attr?


## combine prefix attributes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,4 @@ Feature: EPUB Region-Based Navigation ▸ Full Publication Checks

Scenario: Verify subregion navigation using comics semantics
When checking EPUB 'region-based-nav-comics-valid'
Then error RSC-005 is reported 4 times (non-palpable content)
Then no errors or warnings are reported
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,15 @@ Feature: EPUB 3 — Content Documents — XHTML

#### 6.1.3.1 Structural semantics

Scenario: Verify `epub:type` attribute with valid semantic
@spec @xref:sec-xhtml-structural-semantics
Scenario: Verify `epub:type` attribute on allowed content
When checking document 'epubtype-valid.xhtml'
Then no errors or warnings are reported

@spec @xref:sec-xhtml-structural-semantics
Scenario: Report `epub:type` attribute on non-palpable content
When checking document 'epubtype-on-non-palpable-content-error.xhtml'
Then error RSC-005 is reported 2 times
Scenario: Report `epub:type` attribute on 'head' or metadata content
When checking document 'epubtype-disallowed-error.xhtml'
Then error RSC-005 is reported 8 times
And no other errors or warnings are reported

Scenario: Verify `epub:type` attribute with reserved vocabulary
Expand All @@ -678,8 +679,7 @@ Feature: EPUB 3 — Content Documents — XHTML

Scenario: Verify `epub:type` attribute that does not follow usage suggestions
Given the reporting level set to usage
When checking document 'epubtype-disallowed-usage.xhtml'
Then error RSC-005 is reported 3 times (non-palpable content)
When checking document 'epubtype-misuse-usage.xhtml'
Then usage OPF-087 is reported 7 times
And no other errors or warnings are reported

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"
epub:prefix="test: https://example.org/vocab/#" xml:lang="en" lang="en">
<head epub:type="test:invalid">
<meta epub:type="test:invalid" charset="utf-8" />
<title epub:type="test:invalid">epub:type in head element</title>
<meta epub:type="test:invalid" name="creator" content="Herman Melville" />
<style epub:type="test:invalid"></style>
<link epub:type="test:invalid" type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<script epub:type="test:invalid" src="script.js"></script>
<noscript epub:type="test:invalid">text</noscript>
<h1>Test</h1>
<div></div>
</body>
</html>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
<h2>endnotes</h2>
<div epub:type="endnote">endnote</div>
</section>
<a href="link.xhtml" epub:type="tip">link</a>
<a epub:type="glossref">anchor</a>
</body>
</html>