forked from kc3hack/2024_H
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into herring/claudia
- Loading branch information
Showing
7 changed files
with
349 additions
and
428 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace KoeBook.Epub | ||
namespace KoeBook.Epub | ||
{ | ||
internal static class TagNames | ||
{ | ||
public const string Anchor = "A"; | ||
public const string A = "A"; | ||
public const string Br = "BR"; | ||
public const string Div = "Div"; | ||
public const string Img = "IMG"; | ||
public const string Ruby = "RUBY"; | ||
public const string BreakRow = "BR"; | ||
public const string Span = "SPAN"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Runtime.CompilerServices; | ||
using AngleSharp; | ||
using AngleSharp.Dom; | ||
using KoeBook.Epub.Models; | ||
using KoeBook.Epub.Services; | ||
|
||
namespace KoeBook.Test.Epub; | ||
|
||
public class ScrapingAozoraServiceTest | ||
{ | ||
//[Theory] | ||
//[InlineData("", "")] | ||
public async Task TextProcess(string input, string expected) | ||
{ | ||
using var context = BrowsingContext.New(Configuration.Default); | ||
using var doc = await context.OpenAsync(req => req.Content(input)); | ||
Assert.NotNull(doc.ParentElement); | ||
|
||
var result = ScrapingAozora.TextProcess(null, doc.ParentElement!); | ||
|
||
Assert.Equal(expected, result); | ||
} | ||
|
||
//[Theory] | ||
//[InlineData("", new[] { "" })] | ||
public async Task AddParagraphs1(string input, string[] expected) | ||
{ | ||
using var context = BrowsingContext.New(Configuration.Default); | ||
using var doc = await context.OpenAsync(req => req.Content(input)); | ||
Assert.NotNull(doc.ParentElement); | ||
var epubDocument = new EpubDocument("title", "author", "", default) | ||
{ | ||
Chapters = [new() { Sections = [new("section title") { Elements = [new Paragraph() { Text = "test" }] }] }] | ||
}; | ||
|
||
Assert.Equal(expected.Length, epubDocument.Chapters[0].Sections[0].Elements.Count); | ||
Assert.All(epubDocument.Chapters[0].Sections[0].Elements.Zip(expected), v => | ||
{ | ||
var (element, expected) = v; | ||
var paragraph = Assert.IsType<Paragraph>(element); | ||
Assert.Equal(expected, paragraph.Text); | ||
}); | ||
} | ||
} | ||
|
||
file static class ScrapingAozora | ||
{ | ||
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] | ||
public static extern string TextProcess(ScrapingAozoraService? _, IElement element); | ||
|
||
[UnsafeAccessor(UnsafeAccessorKind.Method)] | ||
public static extern void AddParagraphs(ScrapingAozoraService service, List<KoeBook.Epub.Models.Element> focusElements, IElement element, bool lastEmpty); | ||
|
||
[UnsafeAccessor(UnsafeAccessorKind.Method)] | ||
public static extern void AddParagraphs(ScrapingAozoraService service, List<KoeBook.Epub.Models.Element> focusElements, string input, bool lastEmpty); | ||
|
||
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] | ||
public static extern string TextReplace(ScrapingAozoraService? _, string text); | ||
|
||
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)] | ||
public static extern (List<int> contentsIds, bool hasChapter, bool hasSection) LoadToc(ScrapingAozoraService? _, IDocument doc, EpubDocument epubDocument); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters