<commit_before>package epub30

import (
	"archive/zip"
	"encoding/xml"
	"fmt"
	"github.com/PuerkitoBio/goquery"
	"github.com/luisfurquim/ugarit"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
	"io"
	"io/ioutil"
	"path/filepath"
	"strings"
	"time"
)

// Create a blank EPub Book
//
// Parameters:
//
// @Target -- where to save the epub contents
//
// @Title -- eBook title
//
// @Language -- eBook language
//
// @identifier -- eBook ID
//
// @Creator -- eBook author(s)
//
// @Publisher -- eBook Publisher(s)
//
// @Date -- Date published
//
// @signature -- Ignored for now :(
//
// @metatag -- Any epub metatags go here
//
// @PageProgression -- PageProgression use "ltr" (left-to-right) or "rtl" (right-to-left)
//
// @bookversion -- provide a versioner interface or use the package provided one which just generate a version string using the current time
func New(
	Target io.WriteCloser, // where to save the epub contents
	Title []string, // eBook title
	Language []string, // eBook language
	identifier []string, // eBook ID
	Creator []Author, // eBook author(s)
	Publisher []string, // eBook Publisher(s)
	Date []Date, // Date published
	signature Signature, // Ignored for now :(
	metatag []Metatag, // Any epub metatags go here
	PageProgression string, // PageProgression use "ltr" (left-to-right) or "rtl" (right-to-left)
	// provide a versioner interface or use the package provided one
	// which just generate a version string using the current time
	bookversion ugarit.Versioner) (*Book, error) {
	var b Book
	var Sig *Signature
	var ids []Identifier

	b.RootFolder = "OEBPS"

	b.index = make([]*TOCContent, 0, 4)
	b.cwd = "/"
	b.fd = Target
	b.zfd = zip.NewWriter(Target)

	header := &zip.FileHeader{
		Name:   "mimetype",
		Method: zip.Store,
	}
	f, err := b.zfd.CreateHeader(header)
	if err != nil {
		return nil, err
	}
	_, err = f.Write([]byte("application/epub+zip"))
	if err != nil {
		return nil, err
	}

	f, err = b.zfd.Create("META-INF/container.xml")
	if err != nil {
		return nil, err
	}
	_, err = f.Write([]byte(fmt.Sprintf(rootfolder, b.RootFolder)))
	if err != nil {
		return nil, err
	}

	ids = make([]Identifier, len(identifier))
	for i, id := range identifier {
		ids[i] = Identifier{
			Data: id,
			ID:   "pub-id",
		}
	}

	if bookversion != nil {
		metatag = append(metatag, Metatag{
			Property: "ibooks:version",
			Data:     bookversion.Next(),
		})
	}

	b.Package = Package{
		Version:      "3.0",
		Xmlns:        "http://www.idpf.org/2007/opf",
		XmlnsDc:      "http://purl.org/dc/elements/1.1/",
		XmlnsDcterms: "http://purl.org/dc/terms/",
		Prefix:       "ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/",
		UID:          "pub-id",
		Metadata: Metadata{
			Xmlns:      "http://purl.org/dc/elements/1.1/",
			Title:      Title,
			Language:   Language,
			Identifier: ids,
			Creator:    Creator,
			Publisher:  Publisher,
			Date:       Date,
			Signature:  Sig,
			Metatag:    metatag,
		},
		Manifest: []Manifest{},
		Spine: Spine{
			Itemref: []SpineItem{},
		},
	}

	if PageProgression != "" {
		b.Package.Spine.PageProgression = PageProgression
	}

	if len(Language) > 0 {
		b.Package.Langattr = Language[0]
		// } else {
		//    b.Package.Langattr = "en"
	}

	b.subSection = ugarit.NewArabicNumbering("Chapter", true)

	return &b, nil<commit_msg>@{minorfix}Changing code for use o default language and using lowercase for local symbols as suggested by github.com/mh-cbon<commit_after>package epub30

import (
	"archive/zip"
	"encoding/xml"
	"fmt"
	"github.com/PuerkitoBio/goquery"
	"github.com/luisfurquim/ugarit"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
	"io"
	"io/ioutil"
	"path/filepath"
	"strings"
	"time"
)

// Create a blank EPub Book
//
// Parameters:
//
// @Target -- where to save the epub contents
//
// @Title -- eBook title
//
// @Language -- eBook language
//
// @identifier -- eBook ID
//
// @Creator -- eBook author(s)
//
// @Publisher -- eBook Publisher(s)
//
// @Date -- Date published
//
// @signature -- Ignored for now :(
//
// @metatag -- Any epub metatags go here
//
// @PageProgression -- PageProgression use "ltr" (left-to-right) or "rtl" (right-to-left)
//
// @bookversion -- provide a versioner interface or use the package provided one which just generate a version string using the current time
func New(
	target io.WriteCloser, // where to save the epub contents
	title []string, // eBook title
	language []string, // eBook language
	identifier []string, // eBook ID
	creator []Author, // eBook author(s)
	publisher []string, // eBook Publisher(s)
	date []Date, // Date published
	signature Signature, // Ignored for now :(
	metatag []Metatag, // Any epub metatags go here
	pageProgression string, // PageProgression use "ltr" (left-to-right) or "rtl" (right-to-left)
	// provide a versioner interface or use the package provided one
	// which just generate a version string using the current time
	bookversion ugarit.Versioner) (*Book, error) {
	var b Book
	var sig *Signature
	var ids []Identifier

	b.RootFolder = "OEBPS"

	b.index = make([]*TOCContent, 0, 4)
	b.cwd = "/"
	b.fd = target
	b.zfd = zip.NewWriter(target)

	header := &zip.FileHeader{
		Name:   "mimetype",
		Method: zip.Store,
	}
	f, err := b.zfd.CreateHeader(header)
	if err != nil {
		return nil, err
	}
	_, err = f.Write([]byte("application/epub+zip"))
	if err != nil {
		return nil, err
	}

	f, err = b.zfd.Create("META-INF/container.xml")
	if err != nil {
		return nil, err
	}
	_, err = f.Write([]byte(fmt.Sprintf(rootfolder, b.RootFolder)))
	if err != nil {
		return nil, err
	}

	ids = make([]Identifier, len(identifier))
	for i, id := range identifier {
		ids[i] = Identifier{
			Data: id,
			ID:   "pub-id",
		}
	}

	if bookversion != nil {
		metatag = append(metatag, Metatag{
			Property: "ibooks:version",
			Data:     bookversion.Next(),
		})
	}

	b.Package = Package{
		Version:      "3.0",
		Xmlns:        "http://www.idpf.org/2007/opf",
		XmlnsDc:      "http://purl.org/dc/elements/1.1/",
		XmlnsDcterms: "http://purl.org/dc/terms/",
		Prefix:       "ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/",
		UID:          "pub-id",
		Metadata: Metadata{
			Xmlns:      "http://purl.org/dc/elements/1.1/",
			Title:      title,
			Language:   language,
			Identifier: ids,
			Creator:    creator,
			Publisher:  publisher,
			Date:       date,
			Signature:  sig,
			Metatag:    metatag,
		},
		//    Spine: Spine{
		//       Itemref: []SpineItem{},
		//    },
	}

	if pageProgression != "" {
		b.Package.Spine.PageProgression = pageProgression
	}

	b.Package.Langattr = "en"
	if len(language) > 0 {
		b.Package.Langattr = language[0]
		// } else {
		//    b.Package.Langattr = "en"
	}

	b.subSection = ugarit.NewArabicNumbering("Chapter", true)

	return &b, nil
{'fraction_non_alphanumeric': 0.1582427270055833, 'fraction_numerical': 0.005289450484866294, 'mean_word_length': 2.8897142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5061237', 'n_tokens_mistral': 2687, 'n_tokens_neox': 2508, 'n_words': 631}