Skip to content
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
2 changes: 1 addition & 1 deletion src/MarkdownParser/Writer/ViewFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private void WriteInlineToView(Inline inline, ViewWriter<T> 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:
Expand Down
5 changes: 5 additions & 0 deletions src/MarkdownParser/Writer/ViewWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
26 changes: 26 additions & 0 deletions test/MarkdownParser.Test/MarkdownParserSingleComponentSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(mockComponentSupplier);

//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
var parseResult = parser.Parse(markdown);

//-----------------------------------------------------------------------------------------------------------
// Assert
//-----------------------------------------------------------------------------------------------------------
parseResult.Count.Should().Be(1);
parseResult.First().Should().Be("textview:");
}
}
Loading