Skip to content

Conversation

@bakermo
Copy link

@bakermo bakermo commented Jan 28, 2022

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

@dnfadmin
Copy link

dnfadmin commented Jan 28, 2022

CLA assistant check
All CLA requirements met.

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bakermo big thanks for your contribution! PTAL at my comments

[PublicAPI] protected bool ColumnsStartWithSeparator;
[PublicAPI] protected string BoldMarkupFormat = "**{0}**";
[PublicAPI] protected bool EscapeHtml;
[PublicAPI] protected bool EscapePipe;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that you are not setting the value of this property to true for StackOverflow, but for some reason the SO exporter is escaping it:

[MarkdownExporterAttribute.Default]
[MarkdownExporterAttribute.GitHub]
[MarkdownExporterAttribute.StackOverflow]
[MarkdownExporterAttribute.Atlassian]
public class Intro_MethodsParamsEscaped
{
    [Params("Should|Escape", "ShouldNotEscape")] public string Param;

    [Benchmark] public bool Method() => Param is null;
}
dotnet run -c Release -f net5.0 --filter *Intro_MethodsParamsEscaped* --job dry

image

Could you please ensure that it does not get escaped for the SO exporter?

Copy link
Author

@bakermo bakermo Jan 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this should be fixed now.

Do we want to apply this escaping to console output? It would render as \| in the console, which is probably not desired, however there are comments in the code indicating that we want to support copy-paste from the console into Github:

ColumnsStartWithSeparator = true // we want to be able to copy-paste the console output to GH #1062

}

[RankColumn, LogicalGroupColumn, BaselineColumn]
public class MethodBaseline_MethodsParamsEscaped
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

big thanks for adding a new approval test! 👍

@adamsitnik
Copy link
Member

BTW are there any other characters that should be escaped?

@bakermo
Copy link
Author

bakermo commented Jan 28, 2022

@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.

@YegorStepanov
Copy link
Contributor

@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

@bakermo
Copy link
Author

bakermo commented Feb 1, 2022

@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?

@YegorStepanov
Copy link
Contributor

@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.

Copy link
Contributor

@YegorStepanov YegorStepanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Have you corrected all Adam's comments?

It's not so easy to escape | in the console, because the table alignment will be broken. To fix it the big refactoring of the markdown exporter is required.

We will need to calculate the max column width and only after it, print the table.

In #2135 I've escaped the control characters (like '\0', '\a' - it's still making sound :))

@adamsitnik

@YegorStepanov
Copy link
Contributor

YegorStepanov commented Oct 5, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown output should escape the output

4 participants