Skip to content

Commit

Permalink
fix: remove restrictions on MathML annotation-xml
Browse files Browse the repository at this point in the history
- Content MathML is still restricted by the rules in the spec:
  https://w3c.github.io/publ-epub-revision/epub32/spec/epub-contentdocs.html#sec-xhtml-mathml-conf-content
- Presentation MathML is allowed
- SVG is allowed
- MathML descendants are allowed in HTML annotations

Fix #1024
See also w3c/epub-specs#1212 and w3c/epub-specs#1249
  • Loading branch information
rdeltour committed Mar 29, 2019
1 parent 73b0ee8 commit 8a1b650
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@
<param name="descendant" value="h:label"/>
</pattern>

<pattern id="descendant-annotation-xml-math" is-a="disallowed-descendants">
<param name="ancestor"
value="math:annotation-xml[@encoding='application/xhtml+xml' and @name='alternate-representation']"/>
<param name="descendant" value="math:*"/>
</pattern>

<pattern id="descendant-svgtitle-svg" is-a="disallowed-descendants">
<param name="ancestor" value="svg:title"/>
<param name="descendant" value="svg:*"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CommonAtt &= epub.ssml.ph.attr?
CommonAtt &= common.attrs.xmlbase?

annotation-xml.model.xhtml |= common.inner.flow
annotation-xml.model.mathml |= common.inner.flow
annotation-xml.model.svg |= svg

# The following comes from validator.nu’s xhtml5-svg-mathml.rnc driver:
# in our integration, <mtext> is the only MathML "token element" that can
Expand All @@ -48,26 +48,12 @@ mtext.content |= common.elem.phrasing

# EPUB very specific annotation-xml restrictions:
epub.annotation-xml =
( epub.annotation-xml.xhtml
( annotation-xml.xhtml
| annotation-xml.svg
| epub.annotation-xml.mathml.content
| epub.annotation-xml.mathml.presentation
)
epub.annotation-xml.attributes = CommonAtt, cd?, src?
epub.annotation-xml.xhtml =
element annotation-xml {
epub.annotation-xml.model.xhtml, epub.annotation-xml.attributes,
epub.att-encoding.xhtml, epub.att-name.xhtml
}
epub.annotation-xml.model.xhtml =
common.inner.flow
epub.att-encoding.xhtml =
attribute encoding {
string "application/xhtml+xml"
}
epub.att-name.xhtml =
attribute name {
string "alternate-representation"
}
epub.annotation-xml.mathml.content =
element annotation-xml {
epub.annotation-xml.model.mathml.content, epub.annotation-xml.attributes,
Expand All @@ -86,7 +72,7 @@ epub.annotation-xml =
epub.annotation-xml.mathml.presentation =
element annotation-xml {
epub.annotation-xml.model.mathml.presentation, epub.annotation-xml.attributes,
epub.att-encoding.mathml.presentation, epub.att-name.mathml.presentation
epub.att-encoding.mathml.presentation, epub.att-name.mathml.presentation?
}
epub.annotation-xml.model.mathml.presentation =
MathExpression*
Expand All @@ -96,6 +82,6 @@ epub.annotation-xml =
}
epub.att-name.mathml.presentation =
attribute name {
string "contentequiv"
xsd:NCName
}

27 changes: 14 additions & 13 deletions src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1137,12 +1137,9 @@ public void testMathMLAnnotationXMLWithMathMLPresentation()
}

@Test
public void testMathMLAnnotationXMLWithMathMLAsXHTML()
public void testMathMLAnnotationXMLWithMathMLDescendant()
{
// one error for mtext not allowed in annotation-xml
// one side-effect error for the annotation mtext not being in math
Collections.addAll(expectedErrors, MessageId.RSC_005, MessageId.RSC_005);
testValidateDocument("xhtml/invalid/mathml-annotationxml-mathml-in-xhtml.xhtml", "application/xhtml+xml",
testValidateDocument("xhtml/valid/mathml-annotationxml-xhtml-with-mathml-descendants.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}

Expand Down Expand Up @@ -1180,24 +1177,28 @@ public void testMathMLAnnotationXMLWithXHTML()
@Test
public void testMathMLAnnotationXMLWithXHTMLAndNoNameAttr()
{
Collections.addAll(expectedErrors, MessageId.RSC_005);
testValidateDocument("xhtml/invalid/mathml-annotationxml-xhtml-noname.xhtml", "application/xhtml+xml",
testValidateDocument("xhtml/valid/mathml-annotationxml-xhtml-noname.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}

@Test
public void testMathMLAnnotationXMLWithXHTMLAndInvalidNameAttr()
public void testMathMLAnnotationXMLWithXHTMLAndNameAttr()
{
Collections.addAll(expectedErrors, MessageId.RSC_005);
testValidateDocument("xhtml/invalid/mathml-annotationxml-xhtml-invalidname.xhtml", "application/xhtml+xml",
testValidateDocument("xhtml/valid/mathml-annotationxml-xhtml-contentequiv.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}

@Test
public void testMathMLAnnotationXMLWithXHTMLAndInvalidEncodingAttr()
public void testMathMLAnnotationXMLWithXHTMLAndEncodingAttr()
{
Collections.addAll(expectedErrors, MessageId.RSC_005);
testValidateDocument("xhtml/invalid/mathml-annotationxml-xhtml-invalidencoding.xhtml", "application/xhtml+xml",
testValidateDocument("xhtml/valid/mathml-annotationxml-xhtml-html-encoding.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}

@Test
public void testMathMLAnnotationXMLWithSVG()
{
testValidateDocument("xhtml/valid/mathml-annotationxml-svg.xhtml", "application/xhtml+xml",
EPUBVersion.VERSION_3);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<meta charset="UTF-8"/>
</head>
<body>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<semantics>
<mfrac>
<msqrt>
<mtext>a</mtext>
</msqrt>
<mi>b</mi>
</mfrac>
<annotation-xml encoding="SVG1.1" name="alternate-representation">
<svg viewBox="0 0 1200 400" xmlns="http://www.w3.org/2000/svg" version="1.1">
<title>Test</title>
<desc>Rectangle</desc>
<rect x="10" y="20" width="75" height="30" style="stroke: #333366; fill: #6666cc"/>
</svg>

</annotation-xml>
</semantics>
</math>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
</mrow>
<annotation-xml encoding="application/xhtml+xml" name="alternate-representation">
<x:p>This annotation cannot contain math (sch test)</x:p>
<mtext>sin(x)+5</mtext>
<math alttext="sin(x)+5">
<mtext>sin(x)+5</mtext>
</math>
</annotation-xml>
</semantics>
</math>
Expand Down

0 comments on commit 8a1b650

Please sign in to comment.