diff --git a/src/MarkdownParser/Writer/ViewFormatter.cs b/src/MarkdownParser/Writer/ViewFormatter.cs index 231528a..4dd5da4 100644 --- a/src/MarkdownParser/Writer/ViewFormatter.cs +++ b/src/MarkdownParser/Writer/ViewFormatter.cs @@ -128,7 +128,7 @@ private void WriteInlineToView(Inline inline, ViewWriter writer) writer.AddEmphasis(inline, inline.SourcePosition, inline.SourceLength); break; case InlineTag.Placeholder: - writer.AddPlaceholder(inline.SourcePosition, inline.SourceLength, inline.TargetUrl, inline.FirstChild.LiteralContent); + writer.AddPlaceholder(inline.SourcePosition, inline.SourceLength, inline.TargetUrl, inline.FirstChild?.LiteralContent); break; case InlineTag.Strikethrough: case InlineTag.Emphasis: diff --git a/src/MarkdownParser/Writer/ViewWriter.cs b/src/MarkdownParser/Writer/ViewWriter.cs index 55a01f4..657efed 100644 --- a/src/MarkdownParser/Writer/ViewWriter.cs +++ b/src/MarkdownParser/Writer/ViewWriter.cs @@ -244,6 +244,11 @@ public void AddLink(int firstCharacterPosition, int length, string url, string u public void AddPlaceholder(int firstCharacterPosition, int length, string url, string title) { + if (string.IsNullOrWhiteSpace(url)) + { + return; + } + GetWorkbenchItem().AddPlaceholder(firstCharacterPosition, length, url, title); } diff --git a/test/MarkdownParser.Test/MarkdownParserSingleComponentSpecs.cs b/test/MarkdownParser.Test/MarkdownParserSingleComponentSpecs.cs index 0a239e4..75d122c 100644 --- a/test/MarkdownParser.Test/MarkdownParserSingleComponentSpecs.cs +++ b/test/MarkdownParser.Test/MarkdownParserSingleComponentSpecs.cs @@ -246,4 +246,30 @@ public void When_parsing_a_placeholder_it_should_output_a_PlaceHolderView() parseResult.Count.Should().Be(1); parseResult.First().Should().Be("textview:my-placeholder"); } + + [TestMethod] + public void When_parsing_a_empty_placeholder_it_should_not_output_placeholder() + { + //----------------------------------------------------------------------------------------------------------- + // Arrange + //----------------------------------------------------------------------------------------------------------- + var markdown = @" +[ ] +[] +"; + + var mockComponentSupplier = new StringComponentSupplier(); + var parser = new MarkdownParser(mockComponentSupplier); + + //----------------------------------------------------------------------------------------------------------- + // Act + //----------------------------------------------------------------------------------------------------------- + var parseResult = parser.Parse(markdown); + + //----------------------------------------------------------------------------------------------------------- + // Assert + //----------------------------------------------------------------------------------------------------------- + parseResult.Count.Should().Be(1); + parseResult.First().Should().Be("textview:"); + } }