fixes for epub validation re issue #4

This commit is contained in:
Rudis Muiznieks 2017-04-13 11:50:07 -05:00
parent 52c8768ac2
commit dbfd02ff96
No known key found for this signature in database
GPG key ID: 1C290B51E05090F8
6 changed files with 36 additions and 13 deletions

View file

@ -27,6 +27,8 @@
string tempdir = null;
string format = null;
string author = null;
string bookid = null;
string language = "en";
string images = null;
var debug = false;
@ -59,6 +61,12 @@
case "--author":
author = args[i + 1];
break;
case "--bookid":
bookid = args[i + 1];
break;
case "--language":
language = args[i + 1];
break;
case "--images":
images = args[i + 1];
break;
@ -140,7 +148,7 @@
{
case "html":
Directory.CreateDirectory(output);
rend = new HtmlRenderer();
rend = new HtmlRenderer(language);
break;
case "epub":
if (string.IsNullOrWhiteSpace(author))
@ -148,7 +156,7 @@
Console.WriteLine(@"Epub format requires the --author argument.");
return 1;
}
rend = new EpubRenderer(author);
rend = new EpubRenderer(author, bookid, language);
break;
default:
ShowHelp();
@ -183,6 +191,8 @@
[--template ""/path/to/template/dir""]
[--images ""/path/to/images/dir""]
[--author ""Author Name""]
[--bookid ""ePub Book ID""]
[--language ""language""]
[--debug]");
}
}

View file

@ -21,7 +21,7 @@
{
File.Delete(file);
}
var rend = new HtmlRenderer();
var rend = new HtmlRenderer("en");
rend.Render(story, path, true);
}
}

View file

@ -90,10 +90,14 @@
public class EpubRenderer : HtmlRenderer
{
private readonly string _author;
private readonly string _bookId;
private readonly string _language;
public EpubRenderer(string author) : base()
public EpubRenderer(string author, string bookId, string language) : base(language)
{
_author = author;
_bookId = bookId ?? Guid.NewGuid().ToString("D");
_language = language ?? "en";
}
public override void Render(Model.Parser.ResolvedStory story, string outPath, bool debug = false)
@ -113,6 +117,8 @@
select new Chapter(Path.Combine(temppath, fname), fname, fname.Replace(".html", string.Empty)));
var epub = new Epub(Story.Name, _author, chapters);
epub.BookId = _bookId;
epub.Language = _language;
epub.AddResourceFile(new ResourceFile("styles.css", Path.Combine(temppath, "styles.css"), "text/css"));
if (!string.IsNullOrWhiteSpace(ImageDir))

View file

@ -9,6 +9,8 @@
public class HtmlRenderer : IRenderer
{
private readonly string _language;
protected readonly Markdown Markdown;
public string IndexTemplate { get; set; }
@ -18,8 +20,9 @@
protected ResolvedStory Story { get; set; }
public HtmlRenderer()
public HtmlRenderer(string language)
{
_language = language;
Markdown = new Markdown();
}
@ -39,6 +42,7 @@
{
var index = FillTemplate(IndexTemplate ?? Template.Index, new Dictionary<string, string>
{
{"Language", _language},
{"Title", story.Name},
{"Description", Markdown.Transform(story.Description)},
{"FirstScene", string.Format("{0}.html", story.FirstPage)}
@ -64,6 +68,7 @@
var scene = FillTemplate(SceneTemplate ?? Template.Scene, new Dictionary<string, string>
{
{"Language", _language},
{"Title", story.Name},
{"Content", Markdown.Transform(content)}
});

View file

@ -1,8 +1,9 @@
<!DOCTYPE html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<html lang="@Language" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>@Title</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
@ -11,4 +12,4 @@
@Description
<p><a href="@FirstScene">Begin reading...</a></p>
</body>
</html>
</html>

View file

@ -1,12 +1,13 @@
<!DOCTYPE html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<html lang="@Language" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>@Title</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
@Content
</body>
</html>
</html>