forked from alonrotem/BabylonToHtml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtmlGenerator.cs
57 lines (47 loc) · 2.31 KB
/
HtmlGenerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using BabylonToHtml.BabylonReader;
using System.IO;
namespace BabylonToHtml
{
class HtmlGenerator
{
internal static void GenerateHtml(XDict dict, string outputPath)
{
StreamWriter outFileStream = new StreamWriter(outputPath, false, System.Text.Encoding.UTF8);
int numOfEntries = dict.Entries.Count;
int curEntry = 1;
int top = Console.CursorTop;
int left = Console.CursorLeft;
//header
outFileStream.WriteLine("<html>\n\t<head>\n\t\t<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" />\n\t\t<title>Babylon Dictionary</title>\n\t</head>\n\t<body>");
foreach(XDictEntry entry in dict.Entries)
{
Console.SetCursorPosition(left, top);
Console.Write("Entry #{0}/{1} ({2})...", curEntry.ToString(), numOfEntries.ToString(), (double.Parse(curEntry.ToString()) / double.Parse(numOfEntries.ToString())).ToString("P"));
curEntry++;
outFileStream.WriteLine("\t\t<idx:entry name=\"dic\">");
outFileStream.WriteLine("\t\t\t\t<idx:orth>" + entry.Word.Text);
if (entry.Comments.Count > 0)
{
outFileStream.WriteLine("\t\t\t\t<idx:infl>");
foreach (XWordInfo comment in entry.Comments)
{
if (!string.IsNullOrWhiteSpace(comment.Text))
outFileStream.WriteLine("\t\t\t\t\t<idx:iform value=\"" + comment.Text + "\" />");
}
outFileStream.WriteLine("\t\t\t\t</idx:infl>");
}
outFileStream.WriteLine("\t\t\t</idx:orth>");
foreach (XWordInfo definition in entry.Definitions)
{
outFileStream.WriteLine("\t\t\t<p><ul><li><blockquote>" + definition.Text + "</blockquote></li></ul></p>");
}
outFileStream.WriteLine("\t\t</idx:entry>");
}
outFileStream.WriteLine("\t</body>\n</html>");
outFileStream.Close();
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("\n\nGenerated HTML file \"{0}\".", Path.GetFileName(outputPath), numOfEntries);
}
}
}