WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

MarkdownTextBlock doesn't support backticks in Link Text

Open michael-hawker opened this issue 6 years ago • 3 comments

I'm submitting a...

  • Bug report

Current behavior

Trying to render the following valid markdown doesn't work:

[`Windows.UI.Composition` APIs](https://docs.microsoft.com/windows/uwp/composition/visual-layer)

Expected behavior

[`Windows.UI.Composition` APIs](https://docs.microsoft.com/windows/uwp/composition/visual-layer)

Windows.UI.Composition APIs

Minimal reproduction of the problem with instructions

  1. Open Sample App
  2. Open MarkDownTextBlock sample
  3. Add the following markdown to the textbox at the top:
[`Windows.UI.Composition` APIs](https://docs.microsoft.com/windows/uwp/composition/visual-layer)

Exception thrown in last line of RenderCodeRun trying to add inline to collection - System.ArgumentException: 'Value does not fall within the expected range.'

Environment

Nuget Package(s): 5.0.0

Package Version(s): 5.0.0

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [x] October 2018 Update (17763)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [x] October 2018 Update (17763)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x] Desktop
- [ ] Mobile
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [x] 2017 (version: )
- [ ] 2017 Preview (version: )

michael-hawker avatar Feb 12 '19 21:02 michael-hawker

As mentioned in #2806 to @michael-hawker for the related issue, I can confirm that this too can be fixed (at least as a quick workaround) by replacing this line: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/a722f171cac7959d8fb39d732c5951018a2e8c07/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Inlines.cs#L581

With this code:

try
{
    localContext.InlineCollection.Add(inlineUIContainer);
}
catch (ArgumentException)
{
    // Fallback span
    Run run = new Run
    {
        Text = text.Text,
        FontFamily = InlineCodeFontFamily ?? FontFamily,
        Foreground = InlineCodeForeground ?? Foreground
    };

    // Additional formatting
    if (localContext.WithinItalics) run.FontStyle = FontStyle.Italic;
    if (localContext.WithinBold) run.FontWeight = FontWeights.Bold;

    // Add the fallback block
    localContext.InlineCollection.Add(run);
}

This will still render the code with the usual code font/foreground, and will just lack the additional background color (as it's just a Span). Still though, the visual difference is negligible, and at least this will work instead of just crashing and halting the whole rendering process.

Sergio0694 avatar Feb 13 '19 21:02 Sergio0694

This issue seems inactive. It will automatically be closed in 14 days if there is no activity.

windowstoolkitbot avatar Feb 21 '19 17:02 windowstoolkitbot

following valid markdown

Micrsoft does advise against formatting text in a link, though...

Jay-o-Way avatar May 06 '23 13:05 Jay-o-Way