Skip to content

Fixed rendering of markdown links with inline code #3407

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@
<Setter Property="CodeBackground" Value="{ThemeResource MarkdownBackgroundBrush}" />
<Setter Property="CodeBorderBrush" Value="{ThemeResource MarkdownBorderBrush}" />
<Setter Property="CodeBorderThickness" Value="0" />
<Setter Property="CodeFontFamily" Value="Consolas" />
<Setter Property="CodeMargin" Value="0, 7, 0, 7" />
<Setter Property="CodePadding" Value="10, 6, 10, 6" />
<Setter Property="InlineCodeBorderThickness" Value="0" />
<Setter Property="InlineCodePadding" Value="4, 2, 4, 2" />
<Setter Property="InlineCodeMargin" Value="2,0,2,-4"/>
<Setter Property="InlineCodeBackground" Value="{ThemeResource MarkdownInlineCodeBackgroundBrush}" />
<Setter Property="InlineCodeBorderBrush" Value="{ThemeResource MarkdownBorderBrush}" />
<Setter Property="InlineCodeForeground" Value="{ThemeResource MarkdownInlineCodeForegroundBrush}" />
<Setter Property="CodeFontFamily" Value="Consolas" />
<Setter Property="CodeMargin" Value="0, 7, 0, 7" />
<Setter Property="CodePadding" Value="10, 6, 10, 6" />
<Setter Property="InlineCodeFontFamily" Value="Consolas" />
<Setter Property="EmojiFontFamily" Value="Segoe UI Emoji" />
<Setter Property="Header1FontWeight" Value="Bold" />
<Setter Property="Header1FontSize" Value="20" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,47 +539,70 @@ protected override void RenderCodeRun(CodeInline element, IRenderContext context
throw new RenderContextIncorrectException();
}

var text = CreateTextBlock(localContext);
text.Text = CollapseWhitespace(context, element.Text);
text.FontFamily = InlineCodeFontFamily ?? FontFamily;
text.Foreground = InlineCodeForeground ?? Foreground;
var text = CollapseWhitespace(context, element.Text);

if (localContext.WithinItalics)
// Avoid a crash if the current inline is inside an hyperline.
// This happens when using inline code blocks like [`SomeCode`](https://www.foo.bar).
if (localContext.Parent is Hyperlink)
{
text.FontStyle = FontStyle.Italic;
}
// Fallback span
Run run = new Run
{
Text = text,
FontFamily = InlineCodeFontFamily ?? FontFamily,
Foreground = InlineCodeForeground ?? Foreground
};

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

var borderthickness = InlineCodeBorderThickness;
var padding = InlineCodePadding;
if (localContext.WithinBold)
{
run.FontWeight = FontWeights.Bold;
}

var border = new Border
// Add the fallback block
localContext.InlineCollection.Add(run);
}
else
{
BorderThickness = borderthickness,
BorderBrush = InlineCodeBorderBrush,
Background = InlineCodeBackground,
Child = text,
Padding = padding,
Margin = InlineCodeMargin
};
var textBlock = CreateTextBlock(localContext);
textBlock.Text = text;
textBlock.FontFamily = InlineCodeFontFamily ?? FontFamily;
textBlock.Foreground = InlineCodeForeground ?? Foreground;

// Aligns content in InlineUI, see https://social.msdn.microsoft.com/Forums/silverlight/en-US/48b5e91e-efc5-4768-8eaf-f897849fcf0b/richtextbox-inlineuicontainer-vertical-alignment-issue?forum=silverlightarchieve
border.RenderTransform = new TranslateTransform
{
Y = 4
};
if (localContext.WithinItalics)
{
textBlock.FontStyle = FontStyle.Italic;
}

var inlineUIContainer = new InlineUIContainer
{
Child = border,
};
if (localContext.WithinBold)
{
textBlock.FontWeight = FontWeights.Bold;
}

// Add it to the current inlines
localContext.InlineCollection.Add(inlineUIContainer);
var inlineUIContainer = new InlineUIContainer
{
Child = new Border
{
BorderThickness = InlineCodeBorderThickness,
BorderBrush = InlineCodeBorderBrush,
Background = InlineCodeBackground,
Child = textBlock,
Padding = InlineCodePadding,
Margin = InlineCodeMargin,

// Aligns content in InlineUI, see https://social.msdn.microsoft.com/Forums/silverlight/en-US/48b5e91e-efc5-4768-8eaf-f897849fcf0b/richtextbox-inlineuicontainer-vertical-alignment-issue?forum=silverlightarchieve
RenderTransform = new TranslateTransform { Y = 4 }
}
};

// Add it to the current inlines
localContext.InlineCollection.Add(inlineUIContainer);
}
}
}
}