Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion samples/MudBlazor.Markdown.Core/sample-issues.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# [Unknown language - Razor](https://github.com/MyNihongo/MudBlazor.Markdown/issues/260)
# [Indented code block](https://github.com/MyNihongo/MudBlazor.Markdown/issues/294)
if
{
return;
}

# [Unknown language - Razor](https://github.com/MyNihongo/MudBlazor.Markdown/issues/260)
```razor
@page
@model IndexModel
Expand Down
18 changes: 14 additions & 4 deletions src/MudBlazor.Markdown/MudMarkdown.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ protected virtual void RenderMarkdown(ContainerBlock container, RenderTreeBuilde
}
case FencedCodeBlock code:
{
RenderFencedCodeBlock(builder, code);
RenderCodeBlock(builder, code, code.Info);
break;
}
case CodeBlock code:
{
RenderCodeBlock(builder, code, info: null);
break;
}
case HtmlBlock html:
Expand Down Expand Up @@ -481,7 +486,12 @@ protected virtual void RenderList(ListBlock list, RenderTreeBuilder builder)
}
case FencedCodeBlock x:
{
RenderFencedCodeBlock(builder, x);
RenderCodeBlock(builder, x, x.Info);
break;
}
case CodeBlock x:
{
RenderCodeBlock(builder, x, info: null);
break;
}
default:
Expand Down Expand Up @@ -523,13 +533,13 @@ protected virtual void RenderHtml(in RenderTreeBuilder builder, in StringLineGro
builder.AddContent(ElementIndex, markupString);
}

protected virtual void RenderFencedCodeBlock(in RenderTreeBuilder builder, in FencedCodeBlock code)
protected virtual void RenderCodeBlock(in RenderTreeBuilder builder, in CodeBlock code, in string? info)
{
var text = code.CreateCodeBlockText();

builder.OpenComponent<MudCodeHighlight>(ElementIndex++);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Text), text);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Language), code.Info ?? string.Empty);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Language), info ?? string.Empty);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Theme), CodeBlockTheme);
builder.CloseComponent();
}
Expand Down
4 changes: 2 additions & 2 deletions src/MudBlazor.Markdown/Utils/Extensions/FencedCodeBlockEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MudBlazor;

internal static class FencedCodeBlockEx
{
public static string CreateCodeBlockText(this FencedCodeBlock @this)
public static string CreateCodeBlockText(this CodeBlock @this)
{
if (@this.Lines.Count == 0)
return string.Empty;
Expand All @@ -27,4 +27,4 @@ public static string CreateCodeBlockText(this FencedCodeBlock @this)

return sb.ToString();
}
}
}
Loading
Loading