Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
fixes for epub validation re issue #4
Browse files Browse the repository at this point in the history
  • Loading branch information
rudism committed Apr 13, 2017
1 parent 52c8768 commit dbfd02f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
14 changes: 12 additions & 2 deletions Ficdown.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ private static int Main(string[] args)
string tempdir = null;
string format = null;
string author = null;
string bookid = null;
string language = "en";
string images = null;
var debug = false;

Expand Down Expand Up @@ -59,6 +61,12 @@ private static int Main(string[] args)
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;
Expand Down Expand Up @@ -140,15 +148,15 @@ private static int Main(string[] args)
{
case "html":
Directory.CreateDirectory(output);
rend = new HtmlRenderer();
rend = new HtmlRenderer(language);
break;
case "epub":
if (string.IsNullOrWhiteSpace(author))
{
Console.WriteLine(@"Epub format requires the --author argument.");
return 1;
}
rend = new EpubRenderer(author);
rend = new EpubRenderer(author, bookid, language);
break;
default:
ShowHelp();
Expand Down Expand Up @@ -183,6 +191,8 @@ private static void ShowHelp()
[--template ""/path/to/template/dir""]
[--images ""/path/to/images/dir""]
[--author ""Author Name""]
[--bookid ""ePub Book ID""]
[--language ""language""]
[--debug]");
}
}
Expand Down
2 changes: 1 addition & 1 deletion Ficdown.Parser.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void CanParseValidStoryFile()
{
File.Delete(file);
}
var rend = new HtmlRenderer();
var rend = new HtmlRenderer("en");
rend.Render(story, path, true);
}
}
Expand Down
8 changes: 7 additions & 1 deletion Ficdown.Parser/Render/EpubRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ public void DeleteBuildDir()
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)
Expand All @@ -113,6 +117,8 @@ into fname
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))
Expand Down
7 changes: 6 additions & 1 deletion Ficdown.Parser/Render/HtmlRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

public class HtmlRenderer : IRenderer
{
private readonly string _language;

protected readonly Markdown Markdown;

public string IndexTemplate { get; set; }
Expand All @@ -18,8 +20,9 @@ public class HtmlRenderer : IRenderer

protected ResolvedStory Story { get; set; }

public HtmlRenderer()
public HtmlRenderer(string language)
{
_language = language;
Markdown = new Markdown();
}

Expand All @@ -39,6 +42,7 @@ protected void GenerateHtml(ResolvedStory story, string outPath, bool debug)
{
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)}
Expand All @@ -64,6 +68,7 @@ protected void GenerateHtml(ResolvedStory story, string outPath, bool debug)

var scene = FillTemplate(SceneTemplate ?? Template.Scene, new Dictionary<string, string>
{
{"Language", _language},
{"Title", story.Name},
{"Content", Markdown.Transform(content)}
});
Expand Down
9 changes: 5 additions & 4 deletions Ficdown.Parser/Render/Views/index.html
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -11,4 +12,4 @@ <h1 class="title">@Title</h1>
@Description
<p><a href="@FirstScene">Begin reading...</a></p>
</body>
</html>
</html>
9 changes: 5 additions & 4 deletions Ficdown.Parser/Render/Views/scene.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit dbfd02f

Please sign in to comment.