Permalink
Browse files

Properly parse top level TOC items from NCX

  • Loading branch information...
1 parent 7094707 commit 8f048b1c2b8292f238e4c6cf0c5eee90348b0435 @neror neror committed Nov 9, 2012
Showing with 65 additions and 14 deletions.
  1. +18 −13 EPUB3.c
  2. +47 −1 TestEPUB3Processor/check_EPUB3_parsing.c
View
31 EPUB3.c
@@ -1298,23 +1298,28 @@ EPUB3Error EPUB3ProcessXMLReaderNodeForNavMapInNCX(EPUB3Ref epub, xmlTextReaderP
EPUB3TocItemRef newTocItem = EPUB3TocItemCreate();
(void)EPUB3SaveParseContext(context, kEPUB3NCXStateNavMap, name, 0, NULL, kEPUB3_NO, newTocItem);
}
+ else if(xmlStrcmp(name, BAD_CAST "text") == 0 && xmlStrcmp((*context)->tagName, BAD_CAST "navLabel") == 0) {
+ void * userInfo = (*context)->userInfo;
+ (void)EPUB3SaveParseContext(context, kEPUB3NCXStateNavMap, name, 0, NULL, kEPUB3_YES, userInfo);
+ }
+ else {
+ void * userInfo = (*context)->userInfo;
+ (void)EPUB3SaveParseContext(context, kEPUB3NCXStateNavMap, name, 0, NULL, kEPUB3_NO, userInfo);
+ }
}
break;
}
case XML_READER_TYPE_TEXT:
{
-// const xmlChar *value = xmlTextReaderValue(reader);
-// if(value != NULL && (*context)->shouldParseTextNode) {
-// if(xmlStrcmp((*context)->tagName, BAD_CAST "title") == 0) {
-// (void)EPUB3MetadataSetTitle(epub->metadata, (const char *)value);
-// }
-// else if(xmlStrcmp((*context)->tagName, BAD_CAST "identifier") == 0) {
-// (void)EPUB3MetadataSetIdentifier(epub->metadata, (const char *)value);
-// }
-// else if(xmlStrcmp((*context)->tagName, BAD_CAST "language") == 0) {
-// (void)EPUB3MetadataSetLanguage(epub->metadata, (const char *)value);
-// }
-// }
+ if((*context)->shouldParseTextNode) {
+ const xmlChar *value = xmlTextReaderValue(reader);
+ if(value != NULL) {
+ if(xmlStrcmp((*context)->tagName, BAD_CAST "text") == 0) {
+ EPUB3TocItemRef tocItem = (*context)->userInfo;
+ tocItem->title = strdup((const char *)value);
+ }
+ }
+ }
break;
}
case XML_READER_TYPE_END_ELEMENT:
@@ -1325,8 +1330,8 @@ EPUB3Error EPUB3ProcessXMLReaderNodeForNavMapInNCX(EPUB3Ref epub, xmlTextReaderP
EPUB3TocAddRootItem(epub->toc, newTocItem);
EPUB3TocItemRelease(newTocItem);
}
- (void)EPUB3PopAndFreeParseContext(context);
}
+ (void)EPUB3PopAndFreeParseContext(context);
break;
}
default: break;
View
48 TestEPUB3Processor/check_EPUB3_parsing.c
@@ -462,6 +462,44 @@ START_TEST(test_epub3_parse_manifest_from_medallion_opf_data)
}
END_TEST
+const char * kMedallionTOCTitles[] = {
+ "Cover",
+ "Title Page",
+ "Dedication",
+ "Copyright",
+ "Acknowledgments",
+ "Table of Contents",
+ "Chapter 1",
+ "Chapter 2",
+ "Chapter 3",
+ "Chapter 4",
+ "Chapter 5",
+ "Chapter 6",
+ "Chapter 7",
+ "Chapter 8",
+ "Chapter 9",
+ "Chapter 10",
+ "Chapter 11",
+ "Chapter 12",
+ "Chapter 13",
+ "Chapter 14",
+ "Chapter 15",
+ "Chapter 16",
+ "Chapter 17",
+ "Chapter 18",
+ "Chapter 19",
+ "Chapter 20",
+ "Chapter 21",
+ "Chapter 22",
+ "Chapter 23",
+ "Chapter 24",
+ "Chapter 25",
+ "Chapter 26",
+ "Chapter 27",
+ "Chapter 28",
+ "Epilogue"
+};
+
#pragma mark test_epub3_parse_ncx_from_medallion
START_TEST(test_epub3_parse_ncx_from_medallion)
{
@@ -485,7 +523,15 @@ START_TEST(test_epub3_parse_ncx_from_medallion)
EPUB3Error error = EPUB3ParseNCXFromData(blankEPUB, newBuf, (int32_t)bytesRead);
fail_unless(error == kEPUB3Success);
- ck_assert_int_eq(toc->rootItemCount, 35);
+ int32_t rootItemCount = EPUB3CountOfTocRootItems(blankEPUB);
+ ck_assert_int_eq(rootItemCount, 35);
+ EPUB3TocItemRef rootItems[rootItemCount];
+ error = EPUB3GetTocRootItems(blankEPUB, rootItems);
+ fail_unless(error == kEPUB3Success);
+
+ for (int i = 0; i < rootItemCount; i++) {
+ ck_assert_str_eq(rootItems[i]->title, kMedallionTOCTitles[i]);
+ }
EPUB3Release(blankEPUB);
}

0 comments on commit 8f048b1

Please sign in to comment.