-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add markdown renderer component (#1230)
* Add MarkdownRenderer component * FirstOrDefault -> FirstOrOptional * Update DiagnosticDetails
- Loading branch information
Showing
14 changed files
with
252 additions
and
89 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
src/NexusMods.App.UI/Controls/MarkdownRenderer/IMarkdownRendererViewModel.cs
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,17 @@ | ||
using System.Reactive; | ||
using ReactiveUI; | ||
|
||
namespace NexusMods.App.UI.Controls.MarkdownRenderer; | ||
|
||
public interface IMarkdownRendererViewModel : IViewModelInterface | ||
{ | ||
/// <summary> | ||
/// Gets or sets the contents of the renderer. | ||
/// </summary> | ||
public string Contents { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the command used for opening links from Markdown. | ||
/// </summary> | ||
public ReactiveCommand<string, Unit> OpenLinkCommand { get; } | ||
} |
81 changes: 81 additions & 0 deletions
81
src/NexusMods.App.UI/Controls/MarkdownRenderer/MarkdownRendererDesignViewModel.cs
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,81 @@ | ||
using System.Reactive; | ||
using JetBrains.Annotations; | ||
using ReactiveUI; | ||
|
||
namespace NexusMods.App.UI.Controls.MarkdownRenderer; | ||
|
||
public class MarkdownRendererDesignViewModel : AViewModel<IMarkdownRendererViewModel>, IMarkdownRendererViewModel | ||
{ | ||
public string Contents { get; set; } | ||
|
||
public ReactiveCommand<string, Unit> OpenLinkCommand { get; } = ReactiveCommand.Create<string>(_ => { }); | ||
|
||
public MarkdownRendererDesignViewModel() : this(DefaultContents) { } | ||
|
||
public MarkdownRendererDesignViewModel(string contents) | ||
{ | ||
Contents = contents; | ||
} | ||
|
||
// From https://jaspervdj.be/lorem-markdownum/ | ||
[LanguageInjection("markdown")] | ||
private const string DefaultContents = | ||
""" | ||
# Quid nostro | ||
## Velox tot frugum accipe | ||
Lorem markdownum sacros si Iovis aquarum, oreris bene inmurmurat arborei | ||
propulsa labori invidiosa, sic tibi sic: tumulis. Pectoris ait plectrum fregit | ||
aegram. Cum *legit urit* nec solet corpora loquebatur cur, in vivaque quasque | ||
corpus **sagittas Numam** Lucifer mentesque, **falsa**. Vult plagis sospite | ||
veneni prodiga ratione, currus malus! Et sinat mersaeque fletque cycnus | ||
auxiliaris, sum **quid frondentis** sensit. | ||
1. Moneo ora equos per monstro o foedera | ||
2. Confusura veneni lacertis pisce inmedicabile quid tenuaverat | ||
3. Ardere una quam paciscor alimenta liber | ||
4. Captivarum Venus | ||
5. Nunc iphis Orion aethera genitore doleas pro | ||
Insula illa optime in admonita exigit, clausit sua aut paelicis potiunda ipsius | ||
canes falsisque esset donare. In mea ima loquor, superest vocas densa cognoscere | ||
trepidum inque, restagnantis. Auras est accipiunt erant init turpi tenet isto | ||
voce teretesque facta, quae dederat vultus milite primo. Adspicit ignare | ||
saxumque, tenet fuga male tabuerint umbram *pariterque* nuda vinctumque pugna, | ||
exercita. | ||
## Et tumida | ||
Ut abolere turba dignus, pone respondere comis credo moenia et Cragon nondum | ||
pallenti. Urbem Thracum medii praeclusaque vocanti et senemque per? Deo | ||
genuumque pater, in mihi ruborem: aut mutavit terris removi refert atque | ||
indignave veros, in, promittet! Foeda tempora lux Pholus sit Ligurum quis | ||
[cacumen tamen](http://et.io/cepit.html): hanc. | ||
- Fuisti aptas | ||
- Furibunda arbore passus vulnera quinque Nox menti | ||
- Et gerebat praedae ut duxerat memoranda per | ||
- Nuper Vidi non crines non munusque accusasse | ||
- Trahit opibus vellet rudis | ||
## Habendi ignibus | ||
Ille artus, alma deus est vetus, totidem deprensum arbor lacrimaeque? Illis | ||
Canopo subit lucis tradit [ab](http://www.et-flore.com/pars-spirat.php) certis | ||
mortemque seraque in, **o** vestris omine. *Validum* Lapithaeae, ita orbem dum | ||
praesagaque, dictis, iam disci errore coercuit sit modo Hylactor! Rogat | ||
*iacentes et quaeque* fulva, sertis unguibus quoque possis. Suo Rhodopeius | ||
madefient, mitissima despectus diversa stratis. | ||
1. Diomede aquis | ||
2. Regna mea mota sic usae tu maior | ||
3. Nec hic adunci | ||
Sed esse, prima picum omnes nam patrii do resedit; petebat sed. Amores auras, | ||
potentia subsidunt auras nec: dicar cum dimotis. Fuit Thestias: quam sed hunc | ||
querella erat in inposita. Patuit nomen multi possum quosque erratica patefecit | ||
laudemur: umbrae praedae locus caecis siquidem et cuncti. | ||
"""; | ||
} |
67 changes: 67 additions & 0 deletions
67
src/NexusMods.App.UI/Controls/MarkdownRenderer/MarkdownRendererView.axaml
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,67 @@ | ||
<reactive:ReactiveUserControl | ||
x:TypeArguments="local:IMarkdownRendererViewModel" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:reactive="http://reactiveui.net" | ||
xmlns:local="clr-namespace:NexusMods.App.UI.Controls.MarkdownRenderer" | ||
xmlns:md="clr-namespace:Markdown.Avalonia;assembly=Markdown.Avalonia" | ||
xmlns:ctxt="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="NexusMods.App.UI.Controls.MarkdownRenderer.MarkdownRendererView"> | ||
|
||
<Design.DataContext> | ||
<local:MarkdownRendererDesignViewModel /> | ||
</Design.DataContext> | ||
|
||
<!-- | ||
NOTE(erri120): This control can only be styled directly, not through classes. | ||
https://github.com/whistyun/Markdown.Avalonia/wiki/How-to-customise-style | ||
--> | ||
<md:MarkdownScrollViewer x:Name="MarkdownScrollViewer"> | ||
<md:MarkdownScrollViewer.Styles> | ||
<Style Selector="ctxt|CTextBlock"> | ||
<Setter Property="FontFamily" Value="{StaticResource FontBodyRegular}" /> | ||
<Setter Property="Foreground" Value="{StaticResource NeutralSubduedBrush}" /> | ||
</Style> | ||
|
||
<Style Selector="ctxt|CHyperlink"> | ||
<Setter Property="FontFamily" Value="{StaticResource FontBodyRegular}" /> | ||
<Setter Property="Foreground" Value="{StaticResource NeutralModerateBrush}" /> | ||
</Style> | ||
|
||
<Style Selector="ctxt|CTextBlock.Heading1"> | ||
<Setter Property="FontFamily" Value="{StaticResource FontHeadlinesSemiBold}" /> | ||
<Setter Property="Foreground" Value="{StaticResource NeutralModerateBrush}" /> | ||
</Style> | ||
|
||
<Style Selector="ctxt|CTextBlock.Heading2"> | ||
<Setter Property="FontFamily" Value="{StaticResource FontHeadlinesSemiBold}" /> | ||
<Setter Property="Foreground" Value="{StaticResource NeutralModerateBrush}" /> | ||
</Style> | ||
|
||
<Style Selector="ctxt|CTextBlock.Heading3"> | ||
<Setter Property="FontFamily" Value="{StaticResource FontHeadlinesSemiBold}" /> | ||
<Setter Property="Foreground" Value="{StaticResource NeutralModerateBrush}" /> | ||
</Style> | ||
|
||
<Style Selector="ctxt|CTextBlock.Heading4"> | ||
<Setter Property="FontFamily" Value="{StaticResource FontHeadlinesSemiBold}" /> | ||
<Setter Property="Foreground" Value="{StaticResource NeutralModerateBrush}" /> | ||
</Style> | ||
|
||
<Style Selector="ctxt|CTextBlock.Heading5"> | ||
<Setter Property="FontFamily" Value="{StaticResource FontHeadlinesSemiBold}" /> | ||
<Setter Property="Foreground" Value="{StaticResource NeutralModerateBrush}" /> | ||
</Style> | ||
|
||
<Style Selector="ctxt|CTextBlock.Heading6"> | ||
<Setter Property="FontFamily" Value="{StaticResource FontHeadlinesSemiBold}" /> | ||
<Setter Property="Foreground" Value="{StaticResource NeutralModerateBrush}" /> | ||
</Style> | ||
</md:MarkdownScrollViewer.Styles> | ||
</md:MarkdownScrollViewer> | ||
|
||
</reactive:ReactiveUserControl> | ||
|
23 changes: 23 additions & 0 deletions
23
src/NexusMods.App.UI/Controls/MarkdownRenderer/MarkdownRendererView.axaml.cs
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,23 @@ | ||
using System.Reactive.Disposables; | ||
using Avalonia.ReactiveUI; | ||
using ReactiveUI; | ||
|
||
namespace NexusMods.App.UI.Controls.MarkdownRenderer; | ||
|
||
public partial class MarkdownRendererView : ReactiveUserControl<IMarkdownRendererViewModel> | ||
{ | ||
public MarkdownRendererView() | ||
{ | ||
InitializeComponent(); | ||
|
||
this.WhenActivated(disposables => | ||
{ | ||
this.OneWayBind(ViewModel, vm => vm.Contents, view => view.MarkdownScrollViewer.Markdown) | ||
.DisposeWith(disposables); | ||
|
||
this.OneWayBind(ViewModel, vm => vm.OpenLinkCommand, view => view.MarkdownScrollViewer.Engine.HyperlinkCommand) | ||
.DisposeWith(disposables); | ||
}); | ||
} | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
src/NexusMods.App.UI/Controls/MarkdownRenderer/MarkdownRendererViewModel.cs
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,27 @@ | ||
using System.Reactive; | ||
using JetBrains.Annotations; | ||
using NexusMods.CrossPlatform.Process; | ||
using ReactiveUI; | ||
using ReactiveUI.Fody.Helpers; | ||
|
||
namespace NexusMods.App.UI.Controls.MarkdownRenderer; | ||
|
||
[UsedImplicitly] | ||
public class MarkdownRendererViewModel : AViewModel<IMarkdownRendererViewModel>, IMarkdownRendererViewModel | ||
{ | ||
[Reactive] public string Contents { get; set; } = string.Empty; | ||
|
||
public ReactiveCommand<string, Unit> OpenLinkCommand { get; } | ||
|
||
public MarkdownRendererViewModel(IOSInterop osInterop) | ||
{ | ||
OpenLinkCommand = ReactiveCommand.CreateFromTask<string>(async url => | ||
{ | ||
if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) return; | ||
await Task.Run(() => | ||
{ | ||
osInterop.OpenUrl(uri); | ||
}); | ||
}); | ||
} | ||
} |
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
12 changes: 6 additions & 6 deletions
12
src/NexusMods.App.UI/Pages/Diagnostics/Details/DiagnosticDetailsDesignViewModel.cs
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,17 +1,17 @@ | ||
using System.Reactive; | ||
using NexusMods.Abstractions.Diagnostics; | ||
using NexusMods.App.UI.Controls.MarkdownRenderer; | ||
using NexusMods.App.UI.Windows; | ||
using NexusMods.App.UI.WorkspaceSystem; | ||
using ReactiveUI; | ||
|
||
namespace NexusMods.App.UI.Pages.Diagnostics; | ||
|
||
public class DiagnosticDetailsDesignViewModel : APageViewModel<IDiagnosticDetailsViewModel>, IDiagnosticDetailsViewModel | ||
{ | ||
public string Details { get; } = "This is an example diagnostic details, lots of stuff here."; | ||
public DiagnosticSeverity Severity { get; } = DiagnosticSeverity.Critical; | ||
|
||
private const string Details = "This is an example diagnostic details, lots of stuff here."; | ||
public DiagnosticSeverity Severity => DiagnosticSeverity.Critical; | ||
|
||
public IMarkdownRendererViewModel MarkdownRendererViewModel => new MarkdownRendererDesignViewModel(Details); | ||
|
||
public DiagnosticDetailsDesignViewModel() : base(new DesignWindowManager()) { } | ||
|
||
public ReactiveCommand<string, Unit> MarkdownOpenLinkCommand { get; } = ReactiveCommand.Create<string>(_ => { }); | ||
} |
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
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
Oops, something went wrong.