Repository navigation
[AI-3823] app: Make emphasized chat links clickable while working #1639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,35 @@ | ||
| using Markdig; | ||
| using Markdig.Renderers; | ||
| using Markdig.Syntax; | ||
| using Markdig.Syntax.Inlines; | ||
| using MarkView.Avalonia; | ||
|
|
||
| namespace Capacitor.App.GitHubHtml; | ||
|
|
||
| /// Chat markdown is MarkView's supported set, with links hoisted out of emphasis. A bare builder | ||
| /// is CommonMark and drops the tables and autolinks chat already renders. MarkView only activates | ||
| /// a hyperlink that is a direct inline of its text block. | ||
| public static class ChatPipeline { | ||
| public static MarkdownPipeline Instance { get; } = | ||
| new MarkdownPipelineBuilder().UseSupportedExtensions().Use(new Hoist()).Build(); | ||
|
|
||
| sealed class Hoist : IMarkdownExtension { | ||
| public void Setup(MarkdownPipelineBuilder pipeline) => pipeline.DocumentProcessed += Process; | ||
|
|
||
| public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { } | ||
|
|
||
| static void Process(MarkdownDocument document) { | ||
| foreach (var leaf in document.Descendants<LeafBlock>()) | ||
| if (leaf.Inline is { } root) { | ||
| foreach (var auto in root.Descendants<AutolinkInline>().ToArray()) { | ||
| var link = new LinkInline(auto.IsEmail ? "mailto:" + auto.Url : auto.Url, "") { | ||
| IsAutoLink = true, IsClosed = true, | ||
| }; | ||
| link.AppendChild(new LiteralInline(auto.Url)); | ||
| auto.ReplaceBy(link, copyChildren: false); | ||
| } | ||
| LinkHoister.Hoist(root, includeImages: false); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,37 @@ | ||
| using Avalonia.Controls.Documents; | ||
| using Avalonia.Media; | ||
| using MarkView.Avalonia.Rendering.Inlines; | ||
| using static Capacitor.App.Tests.Unit.AvaloniaSession; | ||
| using static Capacitor.App.Tests.Unit.MarkdownViewHarness; | ||
|
|
||
| namespace Capacitor.App.Tests.Unit; | ||
|
|
||
| public class ChatLinkHoistTests { | ||
| [Test] | ||
| [Arguments("See **[docs](https://example.com/docs)** now.")] | ||
| [Arguments("See **<https://example.com/docs>** now.")] | ||
| [Arguments("See **https://example.com/docs** now.")] | ||
| [NotInParallel("AvaloniaSession")] | ||
| public async Task A_bold_markdown_link_is_clickable(string markdown) { | ||
| await RunOnUiAsync(async () => { | ||
| var (window, root, opened) = Show(markdown); | ||
| try { | ||
| var paragraph = Paragraphs(root).Single(); | ||
| var link = paragraph.Inlines!.OfType<MarkdownHyperlink>().Single(); | ||
| await Assert.That(link.NavigateUri?.ToString()).IsEqualTo("https://example.com/docs"); | ||
| Click(window, paragraph, link); | ||
| await Assert.That(opened).IsEquivalentTo(new[] { "https://example.com/docs" }); | ||
| } finally { window.Close(); } | ||
| }); | ||
| } | ||
| [Test] | ||
| [NotInParallel("AvaloniaSession")] | ||
| public Task An_emphasized_image_placeholder_keeps_its_style() => RunOnUiAsync(async () => { | ||
| var (window, root, _) = Show("****"); | ||
| try { | ||
| var bold = Paragraphs(root).Single().Inlines!.OfType<Bold>().Single(); | ||
| await Assert.That(bold.Inlines.Text).IsEqualTo(""); | ||
| await Assert.That(bold.FontWeight).IsEqualTo(FontWeight.Bold); | ||
| } finally { window.Close(); } | ||
| }); | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.