Skip to content

Commit

Permalink
Basic Markdown Rendering and Bibliography
Browse files Browse the repository at this point in the history
- Added basic support for markdown rendering.
- Update to the new BookReference.
  • Loading branch information
ShankarBUS committed Nov 13, 2024
1 parent 74fe5db commit 6cdb23e
Show file tree
Hide file tree
Showing 97 changed files with 3,536 additions and 360 deletions.
19 changes: 11 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
-->
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageVersion Include="CommunityToolkit.WinUI.Controls.Primitives" Version="8.1.240916" />
<PackageVersion Include="CsvHelper" Version="33.0.1" />
<PackageVersion Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
<PackageVersion Include="Markdig" Version="0.37.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.24324.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0-3.final" />
<PackageVersion Include="Uno.CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.200" />
<PackageVersion Include="HtmlAgilityPack" Version="1.11.70" />
<PackageVersion Include="Markdig" Version="0.38.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0-3.final" />
<PackageVersion Include="Roman-Numerals" Version="2.0.1" />
<PackageVersion Include="Uno.CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.203" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0-release-24373-02" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageVersion Include="MSTest.TestFramework" Version="3.5.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.2" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.2" />
</ItemGroup>
</Project>
19 changes: 19 additions & 0 deletions Symptum.sln
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Symptum.Core.SourceGenerato
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Symptum.Editor.SourceGenerators", "src\Symptum.Editor.SourceGenerators\Symptum.Editor.SourceGenerators.csproj", "{581A06AB-1776-4673-8104-5E55DC4D77F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Symptum.UI", "src\Symptum.UI\Symptum.UI.csproj", "{A4BC2540-9288-4723-BCC3-485E3C172AAB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -208,6 +210,22 @@ Global
{581A06AB-1776-4673-8104-5E55DC4D77F7}.Release|x64.Build.0 = Release|Any CPU
{581A06AB-1776-4673-8104-5E55DC4D77F7}.Release|x86.ActiveCfg = Release|Any CPU
{581A06AB-1776-4673-8104-5E55DC4D77F7}.Release|x86.Build.0 = Release|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Debug|ARM64.Build.0 = Debug|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Debug|x64.ActiveCfg = Debug|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Debug|x64.Build.0 = Debug|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Debug|x86.ActiveCfg = Debug|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Debug|x86.Build.0 = Debug|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Release|Any CPU.Build.0 = Release|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Release|ARM64.ActiveCfg = Release|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Release|ARM64.Build.0 = Release|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Release|x64.ActiveCfg = Release|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Release|x64.Build.0 = Release|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Release|x86.ActiveCfg = Release|Any CPU
{A4BC2540-9288-4723-BCC3-485E3C172AAB}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -222,6 +240,7 @@ Global
{42B5F44B-A67E-44DF-968F-0E425C6F8BE5} = {106EE3C2-3796-4F0F-B5B9-67569B46AB40}
{8CFD07E1-A509-462A-A568-00E6DEADCF07} = {832124A0-8184-48DC-A66D-E8B6106F68C2}
{581A06AB-1776-4673-8104-5E55DC4D77F7} = {832124A0-8184-48DC-A66D-E8B6106F68C2}
{A4BC2540-9288-4723-BCC3-485E3C172AAB} = {832124A0-8184-48DC-A66D-E8B6106F68C2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {82DC91FF-5CA7-40EF-9E24-FB9538FFEC75}
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
// To update the version of Uno please update the version of the Uno.Sdk here. See https://aka.platform.uno/upgrade-uno-packages for more information.
"msbuild-sdks": {
"Uno.Sdk": "5.4.0-dev.188"
"Uno.Sdk": "5.6.0-dev.144"
}
}
1 change: 0 additions & 1 deletion src/Symptum.Common/Helpers/PackageHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO.Compression;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text.Json;
using CsvHelper;
using Symptum.Core.Management.Deployment;
Expand Down
9 changes: 8 additions & 1 deletion src/Symptum.Common/Symptum.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Project Sdk="Uno.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net8.0-ios;net8.0-maccatalyst;net8.0-android;net8.0-windows10.0.19041;net8.0-browserwasm;net8.0-desktop</TargetFrameworks>
<TargetFrameworks>net9.0;net9.0-ios;net9.0-maccatalyst;net9.0-android;net9.0-windows10.0.22621;<!--net9.0-browserwasm-->;net9.0-desktop</TargetFrameworks>
<UnoSingleProject>true</UnoSingleProject>
<OutputType>Library</OutputType>
<!-- Ensures the .xr.xml files are generated in a proper layout folder -->
<GenerateLibraryLayout>true</GenerateLibraryLayout>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<!--
UnoFeatures let's you quickly add and manage implicit package references based on the features you want to use.
Expand All @@ -30,7 +32,12 @@
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22621.28" /> -->
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Symptum.Core\Symptum.Core.csproj" />
</ItemGroup>

</Project>
87 changes: 83 additions & 4 deletions src/Symptum.Core/Data/Bibliography/BookReference.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,89 @@
using Symptum.Core.Helpers;
using Symptum.Core.Subjects.Books;
using System.Diagnostics.CodeAnalysis;
using System.Web;

namespace Symptum.Core.Data.Bibliography;

internal class BookReference : LiteratureReference
public record BookReference : LiteratureReference
{
public string Section { get; set; }
private static readonly string _bookId = "n";
private static readonly string _bookEdition = "ed";
private static readonly string _bookVolume = "vol";

#region Properties

public string? Section { get; init; }

public int Edition { get; init; }

public int ISBN { get; init; }

#endregion

// @book?n={id}&ed={edition}&vol={volume}#{pages}
public static bool TryParse(string? text, [NotNullWhen(true)] out BookReference? bookReference)
{
bool parsed = false;
bookReference = null;
if (!string.IsNullOrEmpty(text))
{
var values = text.Split(ParserHelper.BookReferenceDelimiter);
if (values.Length == 2)
{
string bookString = values[0][0] == '@' && values[0].Length > 6 ? values[0].Remove(0, 6) : values[0];
(Book? book, int edition, int volume) = ParseBookString(bookString);

bookReference = new()
{
Id = book?.Id,
Title = book?.Title,
Authors = book?.Authors,
Edition = edition,
Volume = volume,
Pages = values[1]
};
parsed = true;
}
}

return parsed;
}

private static (Book? book, int edition, int volume) ParseBookString(string bookString)
{
Book? book = null;
int edition = 0;
int volume = 0;
var col = HttpUtility.ParseQueryString(bookString);
if (col != null && col.Count > 0)
{
string? bookCode = col[_bookId];
string? bookEdition = col[_bookEdition];
string? bookVolume = col[_bookVolume];
if (!string.IsNullOrEmpty(bookCode))
book = BookStore.Books.FirstOrDefault(x => x.Id == bookCode);
if (int.TryParse(bookEdition, out int edNo))
edition = edNo;
if (int.TryParse(bookVolume, out int volNo))
volume = volNo;
}

return (book, edition, volume);
}

public int Edition { get; set; }
public override string ToString()
{
var col = HttpUtility.ParseQueryString(string.Empty);
col.Add(_bookId, Id ?? string.Empty);
col.Add(_bookEdition, Edition.ToString());
col.Add(_bookVolume, Volume.ToString());
return "@book?" + col.ToString() + ParserHelper.BookReferenceDelimiter + Pages;
}

public int ISBN { get; set; }
public override string GetPreviewText()
{
return $"{Title} by {Authors}, " +
$"Edition: {Edition}, Volume: {Volume}, Pages: {Pages}";
}
}
6 changes: 0 additions & 6 deletions src/Symptum.Core/Data/Bibliography/IReference.cs

This file was deleted.

6 changes: 3 additions & 3 deletions src/Symptum.Core/Data/Bibliography/JournalArticleReference.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Symptum.Core.Data.Bibliography;

internal class JournalArticleReference : LiteratureReference
public record JournalArticleReference : LiteratureReference
{
public string JournalName { get; set; }
public string? JournalName { get; init; }

public int Issue { get; set; }
public int Issue { get; init; }
}
2 changes: 1 addition & 1 deletion src/Symptum.Core/Data/Bibliography/LinkReference.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Symptum.Core.Data.Bibliography;

internal class LinkReference : ReferenceBase
public record LinkReference : ReferenceBase
{

}
20 changes: 10 additions & 10 deletions src/Symptum.Core/Data/Bibliography/LiteratureReference.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
namespace Symptum.Core.Data.Bibliography;

public class LiteratureReference : ReferenceBase
public record LiteratureReference : ReferenceBase
{
public string Authors { get; set; }
public string? Authors { get; init; }

public string Title { get; set; }
public string? Title { get; init; }

public string Description { get; set; }
public string? Description { get; init; }

public int Volume { get; set; }
public int Volume { get; init; }

public string Pages { get; set; }
public string? Pages { get; init; }

public int Year { get; set; }
public int Year { get; init; }

public string Editors { get; set; }
public string? Editors { get; init; }

public string Publisher { get; set; }
public string? Publisher { get; init; }

public Uri Url { get; set; }
public Uri? Url { get; init; }
}
30 changes: 28 additions & 2 deletions src/Symptum.Core/Data/Bibliography/ReferenceBase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.Diagnostics.CodeAnalysis;

namespace Symptum.Core.Data.Bibliography;

public class ReferenceBase : ObservableObject
public abstract record ReferenceBase
{
#region Properties

public string? Id { get; init; }

#endregion

public static bool TryParse(string? text, [NotNullWhen(true)] out ReferenceBase? reference)
{
bool parsed = false;
reference = null;

if (!string.IsNullOrEmpty(text))
{
if (text.StartsWith("@book?"))
{
if (BookReference.TryParse(text, out BookReference? bookReference))
{
parsed = true;
reference = bookReference;
}
}
}

return parsed;
}

public virtual string GetPreviewText() => string.Empty;
}
12 changes: 6 additions & 6 deletions src/Symptum.Core/Subjects/Books/Book.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class Book : ObservableObject
{
#region Properties

private string _code = string.Empty;
private string _id = string.Empty;

public string Code
public string Id
{
get => _code;
set => SetProperty(ref _code, value);
get => _id;
set => SetProperty(ref _id, value);
}

private string _title = string.Empty;
Expand Down Expand Up @@ -48,13 +48,13 @@ public Book()

public Book(string code, string title, string author)
{
_code = code;
_id = code;
_title = title;
_authors = author;
}

public override string ToString()
{
return Title + " by " + Authors + " (" + Code + ")";
return Title + " by " + Authors + " (" + Id + ")";
}
}
Loading

0 comments on commit 6cdb23e

Please sign in to comment.