@@ -539,47 +539,70 @@ protected override void RenderCodeRun(CodeInline element, IRenderContext context
539539 throw new RenderContextIncorrectException ( ) ;
540540 }
541541
542- var text = CreateTextBlock ( localContext ) ;
543- text . Text = CollapseWhitespace ( context , element . Text ) ;
544- text . FontFamily = InlineCodeFontFamily ?? FontFamily ;
545- text . Foreground = InlineCodeForeground ?? Foreground ;
542+ var text = CollapseWhitespace ( context , element . Text ) ;
546543
547- if ( localContext . WithinItalics )
544+ // Avoid a crash if the current inline is inside an hyperline.
545+ // This happens when using inline code blocks like [`SomeCode`](https://www.foo.bar).
546+ if ( localContext . Parent is Hyperlink )
548547 {
549- text . FontStyle = FontStyle . Italic ;
550- }
548+ // Fallback span
549+ Run run = new Run
550+ {
551+ Text = text ,
552+ FontFamily = InlineCodeFontFamily ?? FontFamily ,
553+ Foreground = InlineCodeForeground ?? Foreground
554+ } ;
551555
552- if ( localContext . WithinBold )
553- {
554- text . FontWeight = FontWeights . Bold ;
555- }
556+ // Additional formatting
557+ if ( localContext . WithinItalics )
558+ {
559+ run . FontStyle = FontStyle . Italic ;
560+ }
556561
557- var borderthickness = InlineCodeBorderThickness ;
558- var padding = InlineCodePadding ;
562+ if ( localContext . WithinBold )
563+ {
564+ run . FontWeight = FontWeights . Bold ;
565+ }
559566
560- var border = new Border
567+ // Add the fallback block
568+ localContext . InlineCollection . Add ( run ) ;
569+ }
570+ else
561571 {
562- BorderThickness = borderthickness ,
563- BorderBrush = InlineCodeBorderBrush ,
564- Background = InlineCodeBackground ,
565- Child = text ,
566- Padding = padding ,
567- Margin = InlineCodeMargin
568- } ;
572+ var textBlock = CreateTextBlock ( localContext ) ;
573+ textBlock . Text = text ;
574+ textBlock . FontFamily = InlineCodeFontFamily ?? FontFamily ;
575+ textBlock . Foreground = InlineCodeForeground ?? Foreground ;
569576
570- // 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
571- border . RenderTransform = new TranslateTransform
572- {
573- Y = 4
574- } ;
577+ if ( localContext . WithinItalics )
578+ {
579+ textBlock . FontStyle = FontStyle . Italic ;
580+ }
575581
576- var inlineUIContainer = new InlineUIContainer
577- {
578- Child = border ,
579- } ;
582+ if ( localContext . WithinBold )
583+ {
584+ textBlock . FontWeight = FontWeights . Bold ;
585+ }
580586
581- // Add it to the current inlines
582- localContext . InlineCollection . Add ( inlineUIContainer ) ;
587+ var inlineUIContainer = new InlineUIContainer
588+ {
589+ Child = new Border
590+ {
591+ BorderThickness = InlineCodeBorderThickness ,
592+ BorderBrush = InlineCodeBorderBrush ,
593+ Background = InlineCodeBackground ,
594+ Child = textBlock ,
595+ Padding = InlineCodePadding ,
596+ Margin = InlineCodeMargin ,
597+
598+ // 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
599+ RenderTransform = new TranslateTransform { Y = 4 }
600+ }
601+ } ;
602+
603+ // Add it to the current inlines
604+ localContext . InlineCollection . Add ( inlineUIContainer ) ;
605+ }
583606 }
584607 }
585608}
0 commit comments