Skip to content

Commit

Permalink
feat(data): report the presence of SVG Content Documents
Browse files Browse the repository at this point in the history
When an EPUB has SVG Content Documents, Ace will report them in the
`hasSVGContentDocuments` field of the `properties` section, and will
log a warning saying these documents will be ignored.

Fixes #94.
  • Loading branch information
rdeltour committed Jan 22, 2018
1 parent a8a3c18 commit 659e189
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/ace-core/src/checker/checker-epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function check(epub, report) {
report.addProperties({
hasManifestFallbacks: epub.hasManifestFallbacks,
hasBindings: epub.hasBindings,
hasSVGContentDocuments: epub.hasSVGContentDocuments,
});

winston.info(`- ${epub.packageDoc.src}: ${
Expand Down
20 changes: 13 additions & 7 deletions packages/epub-utils/src/epub-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,20 @@ EpubParser.prototype.parseData = function(packageDocPath, epubDir) {

const spineItemIdrefs = select('//opf:itemref/@idref', doc);
spineItemIdrefs.forEach((idref) => {
const manifestItem = select(`//opf:item[@id='${idref.nodeValue}'][@media-type='${this.contentDocMediaType}']/@href`, doc);
const manifestItem = select(`//opf:item[@id='${idref.nodeValue}']`, doc);
if (manifestItem.length > 0) {
var spineItem = new SpineItem();
spineItem.relpath = manifestItem[0].nodeValue;
spineItem.filepath = path.join(path.dirname(packageDocPath), spineItem.relpath);
spineItem.title = this.parseContentDocTitle(spineItem.filepath);
spineItem.url = "file://" + spineItem.filepath;
this.contentDocs.push(spineItem);
const contentType = (manifestItem[0].getAttribute('media-type')||'').trim();
if (this.contentDocMediaType === contentType) {
var spineItem = new SpineItem();
spineItem.relpath = manifestItem[0].getAttribute('href');
spineItem.filepath = path.join(path.dirname(packageDocPath), spineItem.relpath);
spineItem.title = this.parseContentDocTitle(spineItem.filepath);
spineItem.url = "file://" + spineItem.filepath;
this.contentDocs.push(spineItem);
} else if (!this.hasSVGContentDocuments && 'image/svg+xml' === contentType) {
winston.warn('The SVG Content Documents in this EPUB will be ignored.');
this.hasSVGContentDocuments = true;
}
}
});

Expand Down
8 changes: 8 additions & 0 deletions tests/__tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ describe('Running the CLI', () => {
const log = stripAnsi(stdout);
expect(/^warn:\s+Copying document with extension/m.test(log)).toBe(true);
});

test('when the EPUB contains SVG Content Documents', () => {
const { stdout, stderr, status } = ace(['feat-svg'], {
cwd: path.resolve(__dirname, '../data'),
});
const log = stripAnsi(stdout);
expect(/^warn:\s+The SVG Content Documents in this EPUB will be ignored\./m.test(log)).toBe(true);
});
});

/*test('with return-2-on-validation-error set to true should exit with return code 2', () => {
Expand Down
8 changes: 8 additions & 0 deletions tests/__tests__/report_json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe('check properties', () => {
hasMathML: false,
hasPageBreaks: false,
hasFormElements: false,
hasSVGContentDocuments: false,
});
});

Expand Down Expand Up @@ -131,6 +132,13 @@ describe('check properties', () => {
hasPageBreaks: true,
});
});

test('with svg content docs', async () => {
const report = await ace(path.join(__dirname, '../data/feat-svg'));
expect(report.properties).toMatchObject({
hasSVGContentDocuments: true,
});
});
});

describe('check data', () => {
Expand Down
5 changes: 5 additions & 0 deletions tests/data/feat-svg/EPUB/content_001.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/data/feat-svg/EPUB/content_002.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/data/feat-svg/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.svg">content 001</a></li>
</ol>
</nav>
</body>
</html>
25 changes: 25 additions & 0 deletions tests/data/feat-svg/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.svg" media-type="image/svg+xml"/>
<item id="content_002" href="content_002.svg" media-type="image/svg+xml"/>
</manifest>
<spine>
<itemref idref="content_001" />
<itemref idref="content_002" />
</spine>
</package>
6 changes: 6 additions & 0 deletions tests/data/feat-svg/META-INF/container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions tests/data/feat-svg/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip

0 comments on commit 659e189

Please sign in to comment.