Skip to content

Commit

Permalink
Fix auto trimming of spaces for inline tags - fixes GH-353
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticmind committed Jan 3, 2024
1 parent 16396cf commit c6026f9
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
... example html *code *block
7 changes: 7 additions & 0 deletions src/ReverseMarkdown.Test/ConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,5 +1334,12 @@ public Task When_Strikethrough_And_Nested_Strikethrough()
var html = $"This is the 1<s>st</s> sentence to t<del>e<strike>s</strike></strike>t the strikethrough tag conversion";
return CheckConversion(html);
}

[Fact]
public Task When_Spaces_In_Inline_Tags_Should_Be_Retained()
{
var html = $"... example html <i>code </i>block";
return CheckConversion(html);
}
}
}
3 changes: 3 additions & 0 deletions src/ReverseMarkdown.Test/ReverseMarkdown.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
<None Update="ConverterTests.When_Strikethrough_And_Nested_Strikethrough.verified.md">
<DependentUpon>ConverterTests.WhenThereIsUnorderedListAndBulletIsAsterisk_ThenConvertToMarkdownList.verified.md</DependentUpon>
</None>
<None Update="ConverterTests.When_Spaces_In_Inline_Tags_Should_Be_Retained.verified.md">
<DependentUpon>ConverterTests.WhenThereIsUnorderedListWithNestedOrderedList_ThenConvertToMarkdownListWithNestedList.verified.md</DependentUpon>
</None>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/ReverseMarkdown/Converters/Aside.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Aside(Converter converter)

public override string Convert(HtmlNode node)
{
return $"{Environment.NewLine}{TreatChildren(node).Trim()}{Environment.NewLine}";
return $"{Environment.NewLine}{TreatChildren(node)}{Environment.NewLine}";
}
}
}
2 changes: 1 addition & 1 deletion src/ReverseMarkdown/Converters/Blockquote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Blockquote(Converter converter) : base(converter)

public override string Convert(HtmlNode node)
{
var content = TreatChildren(node).Trim();
var content = TreatChildren(node);

// get the lines based on carriage return and prefix "> " to each line
var lines = content.ReadLines().Select(item => "> " + item + Environment.NewLine);
Expand Down
2 changes: 1 addition & 1 deletion src/ReverseMarkdown/Converters/Em.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override string Convert(HtmlNode node)
? " "
: "";

return $"*{content.Trim().Chomp(all:true)}*{spaceSuffix}";
return $"*{content.Chomp(all:true)}*{spaceSuffix}";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ReverseMarkdown/Converters/P.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override string Convert(HtmlNode node)
var indentation = IndentationFor(node);
var newlineAfter = NewlineAfter(node);

return $"{indentation}{TreatChildren(node).Trim()}{newlineAfter}";
return $"{indentation}{TreatChildren(node)}{newlineAfter}";
}

private static string IndentationFor(HtmlNode node)
Expand Down
2 changes: 1 addition & 1 deletion src/ReverseMarkdown/Converters/S.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override string Convert(HtmlNode node)
}
else
{
return $"~~{content.Trim().Chomp(all:true)}~~";
return $"~~{content.Chomp(all:true)}~~";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ReverseMarkdown/Converters/Strong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override string Convert(HtmlNode node)
? " "
: "";

return $"**{content.Trim().Chomp(all:true)}**{spaceSuffix}";
return $"**{content.Chomp(all:true)}**{spaceSuffix}";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ReverseMarkdown/Converters/Sup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override string Convert(HtmlNode node)
}
else
{
return $"^{content.Trim().Chomp(all:true)}^";
return $"^{content.Chomp(all:true)}^";
}
}

Expand Down

0 comments on commit c6026f9

Please sign in to comment.