diff --git a/samples/MudBlazor.Markdown.Core/MudBlazor.Markdown.Core.csproj b/samples/MudBlazor.Markdown.Core/MudBlazor.Markdown.Core.csproj index 52f6001b..e35c7a09 100644 --- a/samples/MudBlazor.Markdown.Core/MudBlazor.Markdown.Core.csproj +++ b/samples/MudBlazor.Markdown.Core/MudBlazor.Markdown.Core.csproj @@ -8,7 +8,7 @@ - + diff --git a/samples/MudBlazor.Markdown.Core/sample-issues.md b/samples/MudBlazor.Markdown.Core/sample-issues.md index 505b28c1..b9484933 100644 --- a/samples/MudBlazor.Markdown.Core/sample-issues.md +++ b/samples/MudBlazor.Markdown.Core/sample-issues.md @@ -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 diff --git a/samples/WebAssembly/MudBlazor.Markdown.Wasm.csproj b/samples/WebAssembly/MudBlazor.Markdown.Wasm.csproj index 2fb3701c..1c7a51a1 100644 --- a/samples/WebAssembly/MudBlazor.Markdown.Wasm.csproj +++ b/samples/WebAssembly/MudBlazor.Markdown.Wasm.csproj @@ -7,10 +7,10 @@ - - + + - + diff --git a/src/MudBlazor.Markdown/MudBlazor.Markdown.csproj b/src/MudBlazor.Markdown/MudBlazor.Markdown.csproj index 714a438b..2cb9e29c 100644 --- a/src/MudBlazor.Markdown/MudBlazor.Markdown.csproj +++ b/src/MudBlazor.Markdown/MudBlazor.Markdown.csproj @@ -21,9 +21,9 @@ - - - + + + diff --git a/src/MudBlazor.Markdown/MudMarkdown.razor.cs b/src/MudBlazor.Markdown/MudMarkdown.razor.cs index 85617624..44062f48 100644 --- a/src/MudBlazor.Markdown/MudMarkdown.razor.cs +++ b/src/MudBlazor.Markdown/MudMarkdown.razor.cs @@ -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: @@ -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: @@ -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(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(); } diff --git a/src/MudBlazor.Markdown/Utils/Extensions/FencedCodeBlockEx.cs b/src/MudBlazor.Markdown/Utils/Extensions/FencedCodeBlockEx.cs index 8757bfee..a5f019cd 100644 --- a/src/MudBlazor.Markdown/Utils/Extensions/FencedCodeBlockEx.cs +++ b/src/MudBlazor.Markdown/Utils/Extensions/FencedCodeBlockEx.cs @@ -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; @@ -27,4 +27,4 @@ public static string CreateCodeBlockText(this FencedCodeBlock @this) return sb.ToString(); } -} \ No newline at end of file +} diff --git a/tests/MudBlazor.Markdown.Tests/MarkdownComponentTests/MarkdownComponentShould.cs b/tests/MudBlazor.Markdown.Tests/MarkdownComponentTests/MarkdownComponentShould.cs index 7c56cd19..c3f2db2a 100644 --- a/tests/MudBlazor.Markdown.Tests/MarkdownComponentTests/MarkdownComponentShould.cs +++ b/tests/MudBlazor.Markdown.Tests/MarkdownComponentTests/MarkdownComponentShould.cs @@ -20,13 +20,13 @@ public void RenderEmphasisElements() { const string value = "Some text `code` again text - *italics* text and also **bold** and ~~strikethrough~~ text."; const string expected = -""" -
-

- Some text code again text - italics text and also bold and strikethrough text. -

-
-"""; + """ +
+

+ Some text code again text - italics text and also bold and strikethrough text. +

+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -37,15 +37,15 @@ public void RenderBlockQuotes() { const string value = ">Some text `code` again text - *italics* text and also **bold** and ~~strikethrough~~ text."; const string expected = -""" -
-
-

- Some text code again text - italics text and also bold and strikethrough text. -

-
-
-"""; + """ +
+
+

+ Some text code again text - italics text and also bold and strikethrough text. +

+
+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -61,13 +61,13 @@ public void RenderInvalidEmphasis(string emphasisDelimiter) { var value = $"I expect that {emphasisDelimiter}emphasis{emphasisDelimiter} will be rendered as escaped. {emphasisDelimiter}**Nested markdown is also escaped**{emphasisDelimiter}."; var expected = -$""" -
-

- I expect that {emphasisDelimiter}emphasis{emphasisDelimiter} will be rendered as escaped. {emphasisDelimiter}**Nested markdown is also escaped**{emphasisDelimiter}. -

-
-"""; + $""" +
+

+ I expect that {emphasisDelimiter}emphasis{emphasisDelimiter} will be rendered as escaped. {emphasisDelimiter}**Nested markdown is also escaped**{emphasisDelimiter}. +

+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -80,13 +80,13 @@ public void ReplaceNewLineSymbols(string newLine) { var value = "line1" + newLine + "line2"; const string expected = -""" -
-

- line1
line2 -

-
-"""; + """ +
+

+ line1
line2 +

+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -97,15 +97,15 @@ public void RenderExternalLink() { const string value = "[link display](https://www.google.co.jp/)"; const string expected = -""" - -"""; + """ + + """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -116,15 +116,15 @@ public void RenderInternalLink() { const string value = "[link display](" + TestNavigationManager.TestUrl + ")"; const string expected = -""" - -"""; + """ + + """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -135,15 +135,15 @@ public void RenderLinkAsLink() { const string value = "text before [link display](123) text after"; const string expected = -""" - -"""; + """ + + """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -154,15 +154,15 @@ public void RenderLinkAsButton() { const string value = "text before [link display](123) text after"; const string expected = -""" -
-

- text before - link display - text after -

-
-"""; + """ +
+

+ text before + link display + text after +

+
+ """; using var fixture = CreateFixture(value, new TestCommand()); fixture.MarkupMatches(expected); @@ -173,15 +173,15 @@ public void PreventDefaultIfNavigatesToId() { const string value = "[link](#id)"; const string expected = -""" - -"""; + """ + + """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -192,15 +192,15 @@ public void NotPreventDefaultIfNavigateToAnotherPage() { const string value = "[link](tokyo/#id)"; const string expected = -""" - -"""; + """ + + """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -211,13 +211,13 @@ public void RenderImage() { const string value = "![emw-banner](extra/emw.png)"; const string expectedResult = -""" -
-

- emw-banner -

-
-"""; + """ +
+

+ emw-banner +

+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expectedResult); @@ -228,15 +228,15 @@ public void RenderImageLink() { const string value = "[![emw-banner](extra/emw.png)](https://www.google.co.jp/)"; const string expectedResult = -""" - -"""; + """ + + """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expectedResult); @@ -246,22 +246,22 @@ public void RenderImageLink() public void RenderUnorderedList() { const string value = -""" -some text before -- `item1` - text **bold** -- `item2` - text *italic* -"""; + """ + some text before + - `item1` - text **bold** + - `item2` - text *italic* + """; const string expected = -""" -
-

some text before

-
    -
  • item1- text bold

  • -
  • item2 - text italic

  • -
-
-"""; + """ +
+

some text before

+
    +
  • item1- text bold

  • +
  • item2 - text italic

  • +
+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -271,29 +271,29 @@ some text before public void RenderNestedUnorderedList2() { const string value = -""" -some text before -- `item1` - text *italic* - - `item1-1` - text - - `item1-2` - text -- `item2` - text **bold** -"""; + """ + some text before + - `item1` - text *italic* + - `item1-1` - text + - `item1-2` - text + - `item2` - text **bold** + """; const string expected = -""" -
-

some text before

-
    -
  • item1 - text italic

    -
      -
    • item1-1 - text

    • -
    • item1-2 - text

    • -
    -
  • -
  • item2 - text bold

  • -
-
-"""; + """ +
+

some text before

+
    +
  • item1 - text italic

    +
      +
    • item1-1 - text

    • +
    • item1-2 - text

    • +
    +
  • +
  • item2 - text bold

  • +
+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -303,35 +303,35 @@ some text before public void RenderNestedUnorderedList3() { const string value = -""" -some text before -- `item1` - text *italic* - - `item1-1` - text - - `item1-2` - text - - `item1-2-1` - text -- `item2` - text **bold** -"""; + """ + some text before + - `item1` - text *italic* + - `item1-1` - text + - `item1-2` - text + - `item1-2-1` - text + - `item2` - text **bold** + """; const string expected = -""" -
-

some text before

-
    -
  • -

    item1 - text italic

    -
      -
    • item1-1 - text

    • -
    • item1-2 - text

      -
        -
      • item1-2-1 - text

      • -
      -
    • -
    -
  • -
  • item2 - text bold

  • -
-
-"""; + """ +
+

some text before

+
    +
  • +

    item1 - text italic

    +
      +
    • item1-1 - text

    • +
    • item1-2 - text

      +
        +
      • item1-2-1 - text

      • +
      +
    • +
    +
  • +
  • item2 - text bold

  • +
+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -341,28 +341,28 @@ some text before public void RenderOrderedList() { const string value = -""" -1. Do thing 1 -2. Do next -3. Go to Sapporo -"""; + """ + 1. Do thing 1 + 2. Do next + 3. Go to Sapporo + """; const string expected = -""" -
-
    -
  1. -

    Do thing 1

    -
  2. -
  3. -

    Do next

    -
  4. -
  5. -

    Go to Sapporo

    -
  6. -
-
-"""; + """ +
+
    +
  1. +

    Do thing 1

    +
  2. +
  3. +

    Do next

    +
  4. +
  5. +

    Go to Sapporo

    +
  6. +
+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -372,33 +372,33 @@ 3. Go to Sapporo public void RenderOrderedListWithCodeBlock() { const string value = -""" -1. Connect to your MySQL server using a MySQL client, such as the `mysql` command-line tool: - ```bash - mysql -u username -p - ``` -"""; + """ + 1. Connect to your MySQL server using a MySQL client, such as the `mysql` command-line tool: + ```bash + mysql -u username -p + ``` + """; const string expected = -""" -
-
    -
  1. Connect to your MySQL server using a MySQL client, such as the mysql command-line tool:

  2. -
-
- -
-
-
-"""; - + """ +
+
    +
  1. Connect to your MySQL server using a MySQL client, such as the mysql command-line tool:

  2. +
+
+ +
+
+
+ """; + using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); } @@ -407,43 +407,43 @@ public void RenderOrderedListWithCodeBlock() public void RenderTable() { const string value = -""" -|Column1|Column2|Column3| -|-|-|-| -|cell1-1|cell1-2|cell1-3| -|cell2-1|cell2-2|cell2-3| -"""; + """ + |Column1|Column2|Column3| + |-|-|-| + |cell1-1|cell1-2|cell1-3| + |cell2-1|cell2-2|cell2-3| + """; const string expected = -""" -
-
-
- - - - - - - - - - - - - - - - - - - - -

Column1

Column2

Column3

cell1-1

cell1-2

cell1-3

cell2-1

cell2-2

cell2-3

-
-
-
-"""; + """ +
+
+
+ + + + + + + + + + + + + + + + + + + + +

Column1

Column2

Column3

cell1-1

cell1-2

cell1-3

cell2-1

cell2-2

cell2-3

+
+
+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -459,43 +459,43 @@ public void RenderTable() public void RenderTableWithNewLines(string newLineChar) { var value = -$""" - |1|2| - |-|-| - |a{newLineChar}b|c - """; + $""" + |1|2| + |-|-| + |a{newLineChar}b|c + """; var expected = -$""" -
-
-
- - - - - - - - - - - - - -
-

1

-
-

2

-
-

a{newLineChar}b

-
-

c

-
-
-
-
- """; + $""" +
+
+
+ + + + + + + + + + + + + +
+

1

+
+

2

+
+

a{newLineChar}b

+
+

c

+
+
+
+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -505,43 +505,43 @@ public void RenderTableWithNewLines(string newLineChar) public void RenderTableMinWidth() { const string value = -""" -|col1|col2| -|-|-| -|cell1|cell2| -"""; + """ + |col1|col2| + |-|-| + |cell1|cell2| + """; const string expected = -""" -
-
-
- - - - - - - - - - - - - -
-

col1

-
-

col2

-
-

cell1

-
-

cell2

-
-
-
-
-"""; + """ +
+
+
+ + + + + + + + + + + + + +
+

col1

+
+

col2

+
+

cell1

+
+

cell2

+
+
+
+
+ """; using var fixture = CreateFixture(value, tableCellMinWidth: 200); fixture.MarkupMatches(expected); @@ -551,20 +551,20 @@ public void RenderTableMinWidth() public void RenderLineSeparator() { const string value = -""" -first line -*** -second line -"""; + """ + first line + *** + second line + """; const string expected = -""" -
-

first line

-
-

second line

-
-"""; + """ +
+

first line

+
+

second line

+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -574,31 +574,31 @@ second line public void RenderCodeBlock() { const string value = -""" -```cs -public bool IsMudBlazorCool() -{ - return true; -} -``` -"""; + """ + ```cs + public bool IsMudBlazorCool() + { + return true; + } + ``` + """; const string expected = -""" -
-
- -
-
-
-"""; + """ +
+
+ +
+
+
+ """; using var fixture = CreateFixture(value); fixture.MarkupMatches(expected); @@ -633,4 +633,36 @@ public void PassCustomMarkdownPipeline() .Should() .BeNull(); } + + [Fact] + public void RenderIndentedCodeBlock() + { + const string value = + """ + if (condition) + { + return; + } + """; + + const string expected = + """ +
+
+ +
+
+
+ """; + + using var fixture = CreateFixture(value); + fixture.MarkupMatches(expected); + } } diff --git a/tests/MudBlazor.Markdown.Tests/MarkdownComponentTests/MarkdownComponentSourceShould.cs b/tests/MudBlazor.Markdown.Tests/MarkdownComponentTests/MarkdownComponentSourceShould.cs index 219dfa44..c1300af6 100644 --- a/tests/MudBlazor.Markdown.Tests/MarkdownComponentTests/MarkdownComponentSourceShould.cs +++ b/tests/MudBlazor.Markdown.Tests/MarkdownComponentTests/MarkdownComponentSourceShould.cs @@ -57,7 +57,7 @@ public void ReadValueFromNonExistingFile() [Fact] public void RenderValueFromUrl() { - const string value = "https://raw.githubusercontent.com/MyNihongo/MudBlazor.Markdown/refs/heads/feature/288-markdown-source/tests/MudBlazor.Markdown.Tests/.resources/test.md"; + const string value = "https://raw.githubusercontent.com/MyNihongo/MudBlazor.Markdown/refs/heads/main/tests/MudBlazor.Markdown.Tests/.resources/test.md"; const MarkdownSourceType sourceType = MarkdownSourceType.Url; const string expected = diff --git a/tests/MudBlazor.Markdown.Tests/MudBlazor.Markdown.Tests.csproj b/tests/MudBlazor.Markdown.Tests/MudBlazor.Markdown.Tests.csproj index ee87c87d..aa821fd1 100644 --- a/tests/MudBlazor.Markdown.Tests/MudBlazor.Markdown.Tests.csproj +++ b/tests/MudBlazor.Markdown.Tests/MudBlazor.Markdown.Tests.csproj @@ -8,8 +8,8 @@ - - + +