BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

fix Markdown output to escape pipe character

Open bakermo opened this issue 2 years ago • 6 comments

Hello! Looking to get my feet wet contributing to open source. I've made changes here that should fix #1839.

This will escape the pipe | character in markdown table cells by replacing it with \| so that the tables render properly. Example before escaping: image

And after: image

bakermo avatar Jan 28 '22 06:01 bakermo

CLA assistant check
All CLA requirements met.

dnfadmin avatar Jan 28 '22 06:01 dnfadmin

BTW are there any other characters that should be escaped?

adamsitnik avatar Jan 28 '22 07:01 adamsitnik

@adamsitnik Appreciate the feedback!

BTW are there any other characters that should be escaped?

From what I've seen from testing, the pipe character is the only one that breaks output, but I will make another pass to confirm this after addressing your other comments later today.

bakermo avatar Jan 28 '22 13:01 bakermo

@bakermo I think there should be EscapeSpecialCharacters too. Is it should escape all characters? \t too?

Try run this (\a is a sound character, and it makes sounds!):

public class Benchmarks
{
    [Params("Shou\nld|Esca\ape")] public string Param;

    [Benchmark] public bool Method() => Param is null;
}

image

YegorStepanov avatar Jan 29 '22 23:01 YegorStepanov

@YegorStepanov Ah, good catch. Yes, I agree.

Do you think it would be best to have a single flag EscapeSpecialCharacters that includes the pipe, or keep them separate (EscapeSpecialCharacters and EscapePipe)?

My inclination is to keep them separate, as EscapeSpecialCharacters could handle all characters that we probably want escaped across multiple (or all) outputs, and leave EscapePipe specific to the outputs that care about it. That, or each export dialect defines its own character set that it needs escaped. Thoughts?

bakermo avatar Feb 01 '22 01:02 bakermo

@bakermo My opinion is exactly the same as yours. Separate them.

I don't remember any other markdown-specific mistakes in the output, escapePipe is enough currently.

By implementing it you will close one or few other issues. You may find them and link to the PR.

YegorStepanov avatar Feb 02 '22 05:02 YegorStepanov

The big refactoring will also fix raw markdown alignment when using bold text:

(the PR correctly escapes '|', the screenshots below from master branch)

Current: image

Should be: image

YegorStepanov avatar Oct 05 '22 19:10 YegorStepanov