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
5 changes: 4 additions & 1 deletion src/ReverseMarkdown.Test/ConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,10 @@ private static IEnumerable<CaseData> ApplyTagFilter(IEnumerable<CaseData> cases)
private static string LoadExpected(CaseData testCase)
{
if (!string.IsNullOrWhiteSpace(testCase.Expected)) {
return testCase.Expected;
// Inline expectations are authored with "\n"; the converter emits the platform
// line ending, so normalize before comparing (file-based expectations get this
// from the checkout).
return testCase.Expected.ReplaceLineEndings();
}

if (string.IsNullOrWhiteSpace(testCase.ExpectedFile)) {
Expand Down
20 changes: 20 additions & 0 deletions src/ReverseMarkdown.Test/TestData/cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,26 @@
"ListBulletChar": "*"
}
},
{
"id": "Bug432_AdjacentEmptyBlockquotes",
"html": "<div>\n <blockquote>\n <p></p>\n </blockquote>\n <blockquote>\n <p></p>\n </blockquote>\n</div>",
"expected": ">\n\n>"
},
{
"id": "Bug432_EmptyBlockquoteBetweenParagraphs",
"html": "<p>before</p><blockquote><p></p></blockquote><p>after</p>",
"expected": "before\n\n>\n\nafter"
},
{
"id": "Bug432_EmptyParagraphInNestedBlockquote",
"html": "<blockquote><p>a</p><blockquote><p></p></blockquote></blockquote>",
"expected": "> a\n>\n> >"
},
{
"id": "Bug432_AdjacentEmptyParagraphListItems",
"html": "<ul><li><p></p></li><li><p></p></li></ul>",
"expected": "- \n\n- "
},
{
"id": "SlackFlavored_Bold",
"html": "<b>test</b> | <strong>test</strong>",
Expand Down
21 changes: 19 additions & 2 deletions src/ReverseMarkdown/Writers/MarkdownWriterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@
Buffer.Append("](").Append(EncodeLinkDestination(node.Url));
if (!string.IsNullOrEmpty(node.Title))
{
Buffer.Append(" \"").Append(EncodeTitle(node.Title)).Append('"');

Check warning on line 542 in src/ReverseMarkdown/Writers/MarkdownWriterBase.cs

View workflow job for this annotation

GitHub Actions / job (ubuntu-latest, Linux)

Possible null reference argument for parameter 'title' in 'string MarkdownWriterBase.EncodeTitle(string title)'.

Check warning on line 542 in src/ReverseMarkdown/Writers/MarkdownWriterBase.cs

View workflow job for this annotation

GitHub Actions / job (windows-latest, Win64)

Possible null reference argument for parameter 'title' in 'string MarkdownWriterBase.EncodeTitle(string title)'.
}

Buffer.Append(')');
Expand All @@ -560,7 +560,7 @@
Buffer.Append("![").Append(alt).Append("](").Append(EncodeLinkDestination(node.Url));
if (!string.IsNullOrEmpty(node.Title))
{
Buffer.Append(" \"").Append(EncodeTitle(node.Title)).Append('"');

Check warning on line 563 in src/ReverseMarkdown/Writers/MarkdownWriterBase.cs

View workflow job for this annotation

GitHub Actions / job (ubuntu-latest, Linux)

Possible null reference argument for parameter 'title' in 'string MarkdownWriterBase.EncodeTitle(string title)'.

Check warning on line 563 in src/ReverseMarkdown/Writers/MarkdownWriterBase.cs

View workflow job for this annotation

GitHub Actions / job (windows-latest, Win64)

Possible null reference argument for parameter 'title' in 'string MarkdownWriterBase.EncodeTitle(string title)'.
}

Buffer.Append(')');
Expand Down Expand Up @@ -814,7 +814,10 @@

private protected void TrimTrailingSpaces()
{
while (Buffer.Length > 0 && (Buffer[^1] == ' ' || Buffer[^1] == '\n'))
// Never trim below the current capture's start: whitespace before it (such as the
// blank line separating sibling blocks) belongs to the enclosing render, not to
// this node, and removing it would leave the capture with a negative length.
while (Buffer.Length > _captureFloor && (Buffer[^1] == ' ' || Buffer[^1] == '\n'))
{
Buffer.Length--;
}
Expand Down Expand Up @@ -900,12 +903,26 @@
return sb.ToString();
}

// Offset in Buffer where the innermost active Capture began; text below it is off limits
// to trimming while that capture renders. Zero when no capture is in progress.
private int _captureFloor;

/// <summary>Render via <paramref name="render"/> and return the produced text without
/// leaving it in the buffer — used for post-processing (e.g. blockquote line prefixes).</summary>
protected string Capture(System.Action render)
{
var start = Buffer.Length;
render();
var outerFloor = _captureFloor;
_captureFloor = start;
try
{
render();
}
finally
{
_captureFloor = outerFloor;
}

var text = Buffer.ToString(start, Buffer.Length - start);
Buffer.Length = start;
return text;
Expand Down
Loading