Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #64 from Monirzadeh/RTL-support
Browse files Browse the repository at this point in the history
RTL support
  • Loading branch information
owulveryck committed Aug 16, 2023
2 parents c8df5da + b8a0c47 commit 45f45a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
12 changes: 6 additions & 6 deletions epub_test.go
Expand Up @@ -37,10 +37,10 @@ const (
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>%s</title>
<title dir="auto">%s</title>
<link rel="stylesheet" type="text/css" href="%s"></link>
</head>
<body>
<body dir="auto">
<img src="%s" alt="Cover Image" />
</body>
</html>`
Expand Down Expand Up @@ -96,11 +96,11 @@ const (
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>%s</title>
<title dir="auto">%s</title>
</head>
<body>
%s
</body>
<body dir="auto">
%s
</body>
</html>`
testSectionFilename = "section0001.xhtml"
testSectionTitle = "Section 1"
Expand Down
25 changes: 19 additions & 6 deletions xhtml.go
Expand Up @@ -13,9 +13,9 @@ const (
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<title dir="auto"></title>
</head>
<body></body>
<body dir="auto"></body>
</html>
`
)
Expand All @@ -34,10 +34,16 @@ type xhtmlRoot struct {
}

type xhtmlHead struct {
Title string `xml:"title"`
Title xhtmlTitle `xml:"title"`
Link *xhtmlLink
}

type xhtmlTitle struct {
XMLName xml.Name `xml:"title,omitempty"`
Dir string `xml:"dir,attr,omitempty"`
Value string `xml:",chardata"`
}

// The <link> element, used to link to stylesheets
// Ex: <link rel="stylesheet" type="text/css" href="../css/epub.css" />
type xhtmlLink struct {
Expand All @@ -52,6 +58,7 @@ type xhtmlLink struct {
// leave it up to the user of the package to validate the content
type xhtmlInnerxml struct {
XML string `xml:",innerxml"`
Dir string `xml:"dir,attr,omitempty"`
}

// Constructor for xhtml
Expand All @@ -66,7 +73,9 @@ func newXhtml(body string) *xhtml {

// Constructor for xhtmlRoot
func newXhtmlRoot() *xhtmlRoot {
r := &xhtmlRoot{}
r := &xhtmlRoot{
Body: xhtmlInnerxml{Dir: "auto"},
}
err := xml.Unmarshal([]byte(xhtmlTemplate), &r)
if err != nil {
panic(fmt.Sprintf(
Expand All @@ -83,6 +92,7 @@ func newXhtmlRoot() *xhtmlRoot {

func (x *xhtml) setBody(body string) {
x.xml.Body.XML = "\n" + body + "\n"
x.xml.Body.Dir = "auto"
}

func (x *xhtml) setCSS(path string) {
Expand All @@ -94,15 +104,18 @@ func (x *xhtml) setCSS(path string) {
}

func (x *xhtml) setTitle(title string) {
x.xml.Head.Title = title
x.xml.Head.Title = xhtmlTitle{
Dir: "auto",
Value: title,
}
}

func (x *xhtml) setXmlnsEpub(xmlns string) {
x.xml.XmlnsEpub = xmlns
}

func (x *xhtml) Title() string {
return x.xml.Head.Title
return x.xml.Head.Title.Value
}

// Write the XHTML file to the specified path
Expand Down

0 comments on commit 45f45a4

Please sign in to comment.