// epubContentDocuments gets the XHTML content document filenames in the
// provided EPUB OPF package document.
//
// While application/xhtml+xml is the only officially accepted type (as of EPUB
// 2.0.1 - 3.3), some invalid EPUBs use text/html, and others use
// application/xml or text/xml with a .htm, .xhtml, or .html extension.
epubContentDocuments gets the XHTML content document filenames in the
provided EPUB OPF package document.

While application/xhtml+xml is the only officially accepted type (as of EPUB
2.0.1 - 3.3), some invalid EPUBs use text/html, and others use
application/xml or text/xml with a .htm, .xhtml, or .html extension.
// epubContentDocuments gets the XHTML content document filenames in the // provided EPUB OPF package document . // // While application / xhtml + xml is the only officially accepted type ( as of EPUB // 2 . 0 . 1 - 3 . 3 ) some invalid EPUBs use text / html and others use // application / xml or text / xml with a . htm . xhtml or . html extension .
func epubContentDocuments(epub fs.FS, pkg string) ([]string, error) {
	var opf struct {
		XMLName      xml.Name `xml:"http://www.idpf.org/2007/opf package"`
		ManifestItem []struct {
			Href      string `xml:"href,attr"`
			MediaType string `xml:"media-type,attr"`
		} `xml:"http://www.idpf.org/2007/opf manifest>item"`
	}
	f, err := epub.Open(pkg)
	if err != nil {
		return nil, fmt.Errorf("parse OPF package: %w", err)
	}
	defer f.Close()
	if err := xml.NewDecoder(f).Decode(&opf); err != nil {
		f.Close()
		return nil, fmt.Errorf("parse OPF package: %w", err)
	}
	var docs []string
	for _, it := range opf.ManifestItem {
		switch it.MediaType {
		case "application/xhtml+xml", "text/html":
			docs = append(docs, path.Join(path.Dir(pkg), it.Href))
			continue
		}
		switch strings.ToLower(path.Ext(it.Href)) {
		case ".htm", ".html", ".xhtml":
			docs = append(docs, path.Join(path.Dir(pkg), it.Href))
			continue
		}
	}
	return docs, nil
}
func epubContentDocuments ( epub fs . FS , pkg string ) ( [ ] string , error ) { var opf struct { XMLName xml . Name `xml:"http://www.idpf.org/2007/opf package"` ManifestItem [ ] struct { Href string `xml:"href,attr"` MediaType string `xml:"media-type,attr"` } `xml:"http://www.idpf.org/2007/opf manifest>item"` } f , err := epub . Open ( pkg ) if err != nil { return nil , fmt . Errorf ( " " , err ) } defer f . Close ( ) if err := xml . NewDecoder ( f ) . Decode ( & opf ) ; err != nil { f . Close ( ) return nil , fmt . Errorf ( " " , err ) } var docs [ ] string for _ , it := range opf . ManifestItem { switch it . MediaType { case " " , " " : docs = append ( docs , path . Join ( path . Dir ( pkg ) , it . Href ) ) continue } switch strings . ToLower ( path . Ext ( it . Href ) ) { case " " , " " , " " : docs = append ( docs , path . Join ( path . Dir ( pkg ) , it . Href ) ) continue } } return docs , nil }
epubContentDocuments gets the XHTML content document filenames in the
provided EPUB OPF package document.
epubContentDocuments gets the XHTML content document filenames in the provided EPUB OPF package document .