2014-08-10 11:10:21 -05:00
|
|
|
|
namespace Ficdown.Parser.Render
|
|
|
|
|
{
|
|
|
|
|
using System.IO;
|
2014-08-10 15:25:20 -05:00
|
|
|
|
using System.Linq;
|
2014-08-10 11:10:21 -05:00
|
|
|
|
using MarkdownSharp;
|
|
|
|
|
using Model.Parser;
|
|
|
|
|
using Parser;
|
|
|
|
|
|
|
|
|
|
internal class HtmlRenderer : IRenderer
|
|
|
|
|
{
|
|
|
|
|
private readonly Markdown _md;
|
|
|
|
|
|
|
|
|
|
public HtmlRenderer()
|
|
|
|
|
{
|
|
|
|
|
_md = new Markdown();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-10 17:32:13 -05:00
|
|
|
|
public void Render(ResolvedStory story, string outPath, bool debug = false)
|
2014-08-10 11:10:21 -05:00
|
|
|
|
{
|
2014-08-10 17:32:13 -05:00
|
|
|
|
var index = string.Format("# {0}\n\n{1}\n\n[Click here]({2}.html) to start!", story.Name, story.Description,
|
|
|
|
|
story.FirstPage);
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(Path.Combine(outPath, "index.html"), _md.Transform(index));
|
|
|
|
|
|
|
|
|
|
foreach (var page in story.Pages)
|
2014-08-10 11:10:21 -05:00
|
|
|
|
{
|
|
|
|
|
var content = page.Content;
|
|
|
|
|
foreach (var anchor in Utilities.ParseAnchors(page.Content))
|
|
|
|
|
{
|
|
|
|
|
var newAnchor = string.Format("[{0}]({1}.html)", anchor.Text, anchor.Href.Target);
|
|
|
|
|
content = content.Replace(anchor.Original, newAnchor);
|
|
|
|
|
}
|
2014-08-10 15:25:20 -05:00
|
|
|
|
if (debug)
|
|
|
|
|
{
|
|
|
|
|
content += string.Format("\n\n### State Debug\n\n{0}",
|
|
|
|
|
string.Join("\n", page.ActiveToggles.Select(t => string.Format("- {0}", t)).ToArray()));
|
|
|
|
|
}
|
2014-08-10 11:10:21 -05:00
|
|
|
|
File.WriteAllText(Path.Combine(outPath, string.Format("{0}.html", page.Name)), _md.Transform(content));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|