Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Noted/Core/ExtractWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private IEnumerable<string> EnumerateDocuments(string sourcePath, IEnumerable<st
return this.fileSystem.GetFiles(sourcePath, supportedExtensions);
}

return new[] { sourcePath };
return [sourcePath];
}

private async Task ParseAnnotationsInDocument(Configuration configuration, DocumentReference docRef, IDocumentReader reader, List<Annotation> annotations)
Expand Down
4 changes: 2 additions & 2 deletions src/Noted/Core/Models/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class Document : DocumentReference
{
public Document()
{
this.Annotations = new List<Annotation>();
this.Sections = new List<DocumentSection>();
this.Annotations = [];
this.Sections = [];
}

public string? Subject { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public IEnumerable<Annotation> GetAnnotations(string sourcePath)
{
if (!this.IsAvailable(sourcePath))
{
return Enumerable.Empty<Annotation>();
return [];
}

var annotationFile = Path.Combine(sourcePath, ClippingsFile);
Expand Down
2 changes: 1 addition & 1 deletion src/Noted/Extensions/Readers/EpubReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class EpubReader(ILogger logger) : IDocumentReader
{
private readonly ILogger logger = logger;

public List<string> SupportedExtensions => new() { "epub" };
public List<string> SupportedExtensions => ["epub"];

public async Task<DocumentReference> GetMetadata(Stream stream)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Noted/Extensions/Readers/KfxReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class KfxReader(ILogger logger) : IDocumentReader
{
private readonly ILogger logger = logger;

public List<string> SupportedExtensions => new() { "kfx" };
public List<string> SupportedExtensions => ["kfx"];

public Task<DocumentReference> GetMetadata(Stream stream)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Noted/Extensions/Readers/MobiReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MobiReader(ILogger logger) : IDocumentReader
private readonly ILogger logger = logger;

// TODO add support for azw3
public List<string> SupportedExtensions => new() { "mobi" };
public List<string> SupportedExtensions => ["mobi"];

public Task<DocumentReference> GetMetadata(Stream stream)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Noted/Extensions/Readers/PdfReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public partial class PdfReader(ILogger logger) : IDocumentReader
private readonly ILogger logger = logger;
private readonly IWordExtractor wordExtractor = new NearestNeighbourWordExtractor(GetWordExtractOptions());

public List<string> SupportedExtensions => new() { "pdf" };
public List<string> SupportedExtensions => ["pdf"];

public Task<DocumentReference> GetMetadata(Stream stream)
{
var doc = PdfDocument.Open(stream);
var docReference = new DocumentReference
{
Title = doc.Information.Title,
Author = doc.Information.Author,
Title = doc.Information.Title ?? "Title unknown",
Author = doc.Information.Author ?? "Author unknown",
SupportsEmbeddedAnnotation = true
};

Expand All @@ -62,8 +62,8 @@ public Task<Document> Read(
var doc = PdfDocument.Open(stream);
var docReference = new DocumentReference
{
Title = doc.Information.Title,
Author = doc.Information.Author
Title = doc.Information.Title ?? "Title unknown",
Author = doc.Information.Author ?? "Author unknown",
};

// TODO add support for external annotations in pdf
Expand All @@ -73,7 +73,7 @@ public Task<Document> Read(
var words = this.wordExtractor
.GetWords(letters)
.ToList();
foreach (var annotation in page.ExperimentalAccess.GetAnnotations().Where(a => a.Type.Equals(AnnotationType.Highlight)))
foreach (var annotation in page.GetAnnotations().Where(a => a.Type.Equals(AnnotationType.Highlight)))
{
// Find highlighted words
var highlightedWords = new StringBuilder();
Expand Down
6 changes: 3 additions & 3 deletions src/Noted/Infra/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class ConfigurationProvider

public ConfigurationProvider()
{
this.annotationReaders = _ => Enumerable.Empty<IAnnotationProvider>();
this.documentReaders = _ => Enumerable.Empty<IDocumentReader>();
this.documentWriters = _ => Enumerable.Empty<IDocumentWriter>();
this.annotationReaders = _ => [];
this.documentReaders = _ => [];
this.documentWriters = _ => [];
this.commandLineConfig = new Configuration();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Noted/Noted.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="JTForks.MiscUtil" Version="1.285.0" />
<PackageReference Include="Markdig" Version="0.42.0" />
<PackageReference Include="nlua" Version="1.7.5" />
<PackageReference Include="PdfPig" Version="0.1.8" />
<PackageReference Include="PdfPig" Version="0.1.11" />
<PackageReference Include="Spectre.Console" Version="0.50.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/Noted/Platform/IO/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public IEnumerable<string> GetFiles(string path, string searchPattern)
{
if (!this.IsDirectory(path))
{
return new[] { path };
return [path];
}

var extRegex = new Regex(searchPattern, RegexOptions.Compiled);
Expand Down
19 changes: 10 additions & 9 deletions src/Noted/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ public static class Program
public static async Task<int> Main(string[] args)
{
var configurationProvider = new ConfigurationProvider()
.WithAnnotationProviders(config => new List<IAnnotationProvider>
{
.WithAnnotationProviders(config =>
[
new ClippingAnnotationProvider(config.FileSystem, config.Logger),
new KOReaderAnnotationProvider(config.FileSystem, config.Logger)
})
.WithReaders(config => new List<IDocumentReader>
{
])
.WithReaders(config =>
[

// new KfxReader(config.Logger),
new EpubReader(config.Logger),
new PdfReader(config.Logger),
new MobiReader(config.Logger)
})
.WithWriters(config => new List<IDocumentWriter>
{
])
.WithWriters(config =>
[
new MarkdownWriter(config.Logger)
});
]);

var workflows = new Dictionary<string, Func<Configuration, IWorkflow>>
{ { "extract", config => new ExtractWorkflow(config.FileSystem, config.Logger) } };
Expand Down
2 changes: 1 addition & 1 deletion test/Noted.Tests/Core/Models/LineLocationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class LineLocationTests
[TestMethod]
public void LineLocationCompareShouldThrowExceptionForInvalidObject()
{
Assert.ThrowsException<ArgumentException>(() =>
Assert.ThrowsExactly<ArgumentException>(() =>
{
new LineLocation(1, 2).CompareTo(string.Empty);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void ParseShouldThrowIfStreamIsClosed()
{
this.stream.Close();

Assert.ThrowsException<ArgumentException>(() => ClippingParser.Parse(this.stream).ToList());
Assert.ThrowsExactly<ArgumentException>(() => ClippingParser.Parse(this.stream).ToList());
}

[TestMethod]
Expand Down Expand Up @@ -98,7 +98,7 @@ public void ParseBookInfoShouldThrowIfBookInformationIsMalformed()
{
var line = "\ufeffSample Book";

Assert.ThrowsException<InvalidClippingException>(() => this.clipping.ParseBookInfo(line));
Assert.ThrowsExactly<InvalidClippingException>(() => this.clipping.ParseBookInfo(line));
}

[TestMethod]
Expand All @@ -123,7 +123,7 @@ public void ParseBookInfoShouldStoreBookNameAndAuthorInClipping(string line, str
[DataRow("- Your Highlight on page 12 | Location 100-120 | Added on Thursday, August, 2019 10:17:58 AM")]
public void ParseAnnotationInfoShouldThrowIfAnnotationInfoIsMissingOrInvalid(string line)
{
Assert.ThrowsException<InvalidClippingException>(
Assert.ThrowsExactly<InvalidClippingException>(
() => this.clipping.ParseAnnotationInfo(line));
}

Expand All @@ -144,7 +144,7 @@ public void ParseAnnotationInfoShouldCaptureAnnotationMetadata(ClippingType type
[TestMethod]
public void SkipBlankLineShouldThrowIfNonBlankLineIsProvided()
{
Assert.ThrowsException<InvalidClippingException>(() =>
Assert.ThrowsExactly<InvalidClippingException>(() =>
this.clipping.SkipBlankLine("xx"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task HtmlContextParserShouldAddContextToAnnotations()
var (a, _, _) = await HtmlContextParser.AddContext(
this.sampleContentStream,
SampleSections,
new[] { (new LineLocation(1, 2), this.annotations[0]) });
[(new LineLocation(1, 2), this.annotations[0])]);

Assert.AreEqual(1, a.Count);
Assert.IsTrue(a[0].Context.Content.StartsWith("Never"));
Expand All @@ -68,7 +68,7 @@ public async Task HtmlContextParserShouldAddContextWhenAnnotationSpansOverElemen
var (a, _, _) = await HtmlContextParser.AddContext(
this.sampleContentStream,
SampleSections,
new[] { (new LineLocation(1, 2), this.annotations[1]) });
[(new LineLocation(1, 2), this.annotations[1])]);

Assert.AreEqual(1, a.Count);
Assert.IsTrue(a[0].Context.Content.StartsWith("Thus, "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public async Task ParseShouldCreateDocumentSectionRelationships()
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(TocFragment));
var toc = await HtmlSectionParser.Parse(stream).ToListAsync();

Assert.AreEqual(null, toc[3].Parent); // 1 -> null
Assert.IsNull(toc[3].Parent); // 1 -> null
Assert.AreEqual("Section 1.1", toc[4].Title);
Assert.AreEqual(toc[3], toc[4].Parent); // 1.1 -> 1
Assert.AreEqual(toc[4], toc[5].Parent); // 1.1.1 -> 1.1
Assert.AreEqual(toc[3], toc[6].Parent); // 1.2 -> 1
Assert.AreEqual(null, toc[7].Parent); // 2 -> null
Assert.IsNull(toc[7].Parent); // 2 -> null
}
}
}
4 changes: 2 additions & 2 deletions test/Noted.Tests/Extensions/Readers/PdfReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void PdfReaderShouldSupportOnlyPdfFileExtension()
[TestMethod]
public void PdfReaderShouldThrowIfStreamIsInvalid()
{
Assert.ThrowsException<ArgumentNullException>(() =>
Assert.ThrowsExactly<ArgumentNullException>(() =>
this.reader.Read(null, new ReaderOptions(), this.emptyExternalAnnotations));
}

Expand All @@ -55,7 +55,7 @@ public void PdfReaderShouldThrowIfStreamIsUnreadable()
using var stream = new MemoryStream();
stream.Close();

Assert.ThrowsException<ArgumentException>(() =>
Assert.ThrowsExactly<ArgumentException>(() =>
this.reader.Read(stream, new ReaderOptions(), this.emptyExternalAnnotations));
}

Expand Down
6 changes: 3 additions & 3 deletions test/Noted.Tests/Extensions/Writers/MarkdownWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public async Task MarkdownWriterShouldNotCrashForDocumentWithoutSections()
var stream = new MemoryStream();
var writer = new MarkdownWriter(new NullLogger());

document.Annotations = new List<Annotation>
{
document.Annotations =
[
new(
"dummy annotation",
document,
AnnotationType.Highlight,
new AnnotationContext(),
DateTime.Now)
};
];

await writer.Write(config, document, stream);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Noted.Tests/Noted.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PdfPig" Version="0.1.8" />
<PackageReference Include="PdfPig" Version="0.1.11" />
<PackageReference Include="Ephemerality.Unpack" Version="0.0.5" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
Expand Down