1
0
Fork 0
mirror of https://github.com/Nioux/AideDeJeu.git synced 2025-10-30 23:16:09 +00:00
This commit is contained in:
Yan Maniez 2019-06-15 01:37:00 +02:00
parent 921baf66cb
commit 5b3251ab59

View file

@ -381,10 +381,13 @@ namespace AideDeJeuCmd
static async Task ExtractHtmlAsync() static async Task ExtractHtmlAsync()
{ {
var parser = new HtmlParser(); for (int i = 1; i <= 434; i++)
var doc = new HtmlAgilityPack.HtmlDocument(); {
doc.Load(@"..\..\..\..\..\Ignore\tome_of_beasts\page30.html"); var parser = new HtmlParser();
parser.OutputMarkdown(parser.Parse(doc)); var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load($@"..\..\..\..\..\Ignore\tome_of_beasts\page{i}.html");
parser.OutputMarkdown(parser.Parse(doc));
}
} }
class HtmlParser class HtmlParser
@ -425,50 +428,53 @@ namespace AideDeJeuCmd
var txtDivs = doc.DocumentNode.SelectNodes("//div[@class='txt']"); var txtDivs = doc.DocumentNode.SelectNodes("//div[@class='txt']");
var fullText = new FullText(); var fullText = new FullText();
var fullLine = new FullLine(); var fullLine = new FullLine();
foreach (var txtDiv in txtDivs) if (txtDivs != null)
{ {
var spans = txtDiv.Elements("span"); foreach (var txtDiv in txtDivs)
for (var i = 0; i < spans.Count(); i++)
{ {
var span = spans.ToArray()[i]; var spans = txtDiv.Elements("span");
var spanId = span.GetAttributeValue("id", ""); for (var i = 0; i < spans.Count(); i++)
var spanStyle = span.GetAttributeValue("style", "");
var spanIdStyle = new string(styles.SingleOrDefault(s => s.StartsWith($"#{spanId} ")).SkipWhile(c => c != '{').ToArray());
var parsedSpan = new ParsedSpan()
{ {
Text = span.InnerText, var span = spans.ToArray()[i];
Style = spanStyle, var spanId = span.GetAttributeValue("id", "");
IdStyle = spanIdStyle, var spanStyle = span.GetAttributeValue("style", "");
}; var spanIdStyle = new string(styles.SingleOrDefault(s => s.StartsWith($"#{spanId} ")).SkipWhile(c => c != '{').ToArray());
if (span.InnerText.Contains("Forme immuable")) var parsedSpan = new ParsedSpan()
{
Debug.WriteLine("");
}
if (i == 0)
{
var previousParsedSpan = fullLine.LastOrDefault();
if (previousParsedSpan == null)
{ {
var previousFullLine = fullText.LastOrDefault(); Text = span.InnerText,
if (previousFullLine != null) Style = spanStyle,
{ IdStyle = spanIdStyle,
previousParsedSpan = previousFullLine.LastOrDefault(); };
} if (span.InnerText.Contains("Forme immuable"))
{
Debug.WriteLine("");
} }
if (i == 0)
{
var previousParsedSpan = fullLine.LastOrDefault();
if (previousParsedSpan == null)
{
var previousFullLine = fullText.LastOrDefault();
if (previousFullLine != null)
{
previousParsedSpan = previousFullLine.LastOrDefault();
}
}
if (previousParsedSpan != null) if (previousParsedSpan != null)
{
if (previousParsedSpan.Style != parsedSpan.Style || previousParsedSpan.IdStyle != parsedSpan.IdStyle)
{ {
fullText.Add(fullLine); if (previousParsedSpan.Style != parsedSpan.Style || previousParsedSpan.IdStyle != parsedSpan.IdStyle)
fullLine = new FullLine(); {
fullText.Add(fullLine);
fullLine = new FullLine();
}
} }
} }
fullLine.Add(parsedSpan);
} }
fullLine.Add(parsedSpan);
} }
fullText.Add(fullLine);
} }
fullText.Add(fullLine);
return fullText; return fullText;
} }
@ -509,17 +515,19 @@ namespace AideDeJeuCmd
} }
else if (keySpan.IdStyle.Contains("font-family:sans-serif; font-weight:normal; font-style:normal;")) else if (keySpan.IdStyle.Contains("font-family:sans-serif; font-weight:normal; font-style:normal;"))
{ {
Console.Write($"{keySpan.Text} {value}"); Console.ForegroundColor = ConsoleColor.Red;
Console.Write($"{keySpan.Text}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($" {value}");
} }
else else
{ {
//Console.Write($"{spanStyle} => {span.InnerText} "); Console.ForegroundColor = ConsoleColor.Red;
Console.Write($"{keySpan.Text} {value}"); Console.Write($"{keySpan.Text}");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($" {value}");
} }
//Console.Write(spa.Text);
} }
Console.WriteLine();
//Console.WriteLine();
} }
} }