|
@@ -1,5 +1,16 @@
|
|
-using HanumanInstitute.MvvmDialogs;
|
|
|
|
|
|
+using AngleSharp.Dom;
|
|
|
|
+using AngleSharp.Html.Dom;
|
|
|
|
+using AngleSharp.Html.Parser;
|
|
|
|
+using DynamicData;
|
|
|
|
+using HanumanInstitute.MvvmDialogs;
|
|
|
|
+using System;
|
|
|
|
+using System.Collections;
|
|
|
|
+using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
|
|
+using System.Diagnostics;
|
|
|
|
+using System.IO;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Security.Cryptography;
|
|
using System.Text.RegularExpressions;
|
|
using System.Text.RegularExpressions;
|
|
using VeloeAvaloniaKemonoPartyApp.Models;
|
|
using VeloeAvaloniaKemonoPartyApp.Models;
|
|
|
|
|
|
@@ -10,6 +21,7 @@ namespace VeloeAvaloniaKemonoPartyApp.ViewModels
|
|
private readonly Post _post;
|
|
private readonly Post _post;
|
|
private readonly IDialogService _dialogService;
|
|
private readonly IDialogService _dialogService;
|
|
private readonly ViewModelBase _parent;
|
|
private readonly ViewModelBase _parent;
|
|
|
|
+ private readonly IHtmlDocument _postContent;
|
|
|
|
|
|
public PostViewModel(IDialogService dialogService,ViewModelBase parent, Post post)
|
|
public PostViewModel(IDialogService dialogService,ViewModelBase parent, Post post)
|
|
{
|
|
{
|
|
@@ -30,17 +42,65 @@ namespace VeloeAvaloniaKemonoPartyApp.ViewModels
|
|
|
|
|
|
Attachments.Add(new AttachmentViewModel(attachment));
|
|
Attachments.Add(new AttachmentViewModel(attachment));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ _postContent = new HtmlParser().ParseDocument(post.Content);
|
|
|
|
+
|
|
|
|
+ foreach (var element in _postContent.Children)
|
|
|
|
+ SetUpViewModels(element, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void SetUpViewModels(IElement element, object vm)
|
|
|
|
+ {
|
|
|
|
+ var added = false;
|
|
|
|
+ if (element.TagName.Equals("p",StringComparison.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ if (vm is string text)
|
|
|
|
+ {
|
|
|
|
+ text = text + (element.TextContent);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ vm = element.TextContent;
|
|
|
|
+ }
|
|
|
|
+ added = true;
|
|
|
|
+ }
|
|
|
|
+ else if (element.TagName.Equals("img", StringComparison.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ var attachment = new ExternalAttachment() { Url = element.Attributes.First(x => x.Name == "src").Value };
|
|
|
|
+ attachment.Path = Path.GetFileName(attachment.Url);
|
|
|
|
+ attachment.Name = Path.GetFileNameWithoutExtension(attachment.Path);
|
|
|
|
+
|
|
|
|
+ vm = new PostImageViewModel(_dialogService, _parent, attachment);
|
|
|
|
+ added = true;
|
|
|
|
+ }
|
|
|
|
+ else if (element.TagName.Equals("table",StringComparison.OrdinalIgnoreCase))
|
|
|
|
+ {
|
|
|
|
+ Debug.Assert(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //ContentViewModels.Add();
|
|
|
|
+ foreach (var child in element.Children)
|
|
|
|
+ SetUpViewModels(child, vm);
|
|
|
|
+
|
|
|
|
+ if (vm is not null && added)
|
|
|
|
+ {
|
|
|
|
+ ContentViewModels.Add(vm);
|
|
|
|
+ vm = null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public ObservableCollection<PostImageViewModel> Images { get; } = new();
|
|
public ObservableCollection<PostImageViewModel> Images { get; } = new();
|
|
|
|
|
|
public ObservableCollection<AttachmentViewModel> Attachments { get; } = new();
|
|
public ObservableCollection<AttachmentViewModel> Attachments { get; } = new();
|
|
|
|
|
|
|
|
+ public ObservableCollection<object> ContentViewModels { get; } = new();
|
|
|
|
+
|
|
public AttachmentViewModel SelectedAttachment { get; set; }
|
|
public AttachmentViewModel SelectedAttachment { get; set; }
|
|
|
|
|
|
public bool IsImagesEmpty => Images.Count == 0;
|
|
public bool IsImagesEmpty => Images.Count == 0;
|
|
|
|
|
|
- public string Content => Regex.Replace(_post.Content, "<[^>]*>|<|>|&apos|&|"", (Match m) =>
|
|
|
|
|
|
+ public string Content => _postContent.FirstChild?.TextContent;
|
|
|
|
+ /*Regex.Replace(_post.Content, "<[^>]*>|<|>|&apos|&|"", (Match m) =>
|
|
m.Value switch
|
|
m.Value switch
|
|
{
|
|
{
|
|
"<" => "<",
|
|
"<" => "<",
|
|
@@ -51,11 +111,11 @@ namespace VeloeAvaloniaKemonoPartyApp.ViewModels
|
|
"</p>" => "\n",
|
|
"</p>" => "\n",
|
|
_ => ""
|
|
_ => ""
|
|
}
|
|
}
|
|
- );
|
|
|
|
|
|
+ );*/
|
|
|
|
|
|
public string Title => _post.Title;
|
|
public string Title => _post.Title;
|
|
|
|
|
|
public string Date => _post.Published;
|
|
public string Date => _post.Published;
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|