Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inline code in left navigation and h1 rendering #290

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

reakaleek
Copy link
Member

@reakaleek reakaleek commented Jan 22, 2025

Closes #235
Closes #311

image

@reakaleek reakaleek added the fix label Jan 22, 2025
@reakaleek reakaleek self-assigned this Jan 22, 2025
@reakaleek reakaleek requested a review from a team January 22, 2025 10:09
@reakaleek reakaleek requested a review from Mpdreamz January 23, 2025 09:40
Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

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

Small nitpicks other than that it LGTM!

{
var title = !string.IsNullOrEmpty(_navigationTitle) ? _navigationTitle : Title;
return string.IsNullOrEmpty(title) ? null : Helpers.Markdown.StripMarkdown(title);
}
private set => _navigationTitle = value;
Copy link
Member

Choose a reason for hiding this comment

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

Strip once when setting instead of each time we get the property.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines 7 to 9
public static class Markdown
{
public static string StripMarkdown(string markdown)
Copy link
Member

@Mpdreamz Mpdreamz Jan 23, 2025

Choose a reason for hiding this comment

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

I'm partial to making these extension methods.

Suggested change
public static class Markdown
{
public static string StripMarkdown(string markdown)
public static string class MarkdownStringExtensions
{
public static string StripMarkdown(this string markdown)

Copy link
Member Author

Choose a reason for hiding this comment

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

get
{
var title = !string.IsNullOrEmpty(_navigationTitle) ? _navigationTitle : Title;
return string.IsNullOrEmpty(title) ? null : Helpers.Markdown.StripMarkdown(title);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return string.IsNullOrEmpty(title) ? null : Helpers.Markdown.StripMarkdown(title);
return string.IsNullOrEmpty(title) ? null : title.StripMarkdown();

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -46,7 +46,11 @@ public DocumentationGroup? Parent
public string? Title { get; private set; }
Copy link
Member

Choose a reason for hiding this comment

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

Maybe introduce a TitleRaw property thats the markdown so that we can assume Title and NavigationTitle are sanitized.

Then when rendering we can use TitleRaw

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

@reakaleek reakaleek Jan 23, 2025

Choose a reason for hiding this comment

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

I'm a bit unsure about this. This caused changes in various places, where it's not entirely clear to me if it expects a raw markdown string or sanitized title.

Was the assumption that it's only a sanitized title during the first implementations?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

{
public static string StripMarkdown(string markdown)
{
using var writer = new StringWriter();
Copy link
Member

Choose a reason for hiding this comment

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

For funsies tried to see if pooling the StringBuilder() this instantatiates each time had an impact but its very minimal:

private static readonly ObjectPool<StringBuilder> StringBuilderPool = new DefaultObjectPool<StringBuilder>(new StringBuilderPooledObjectPolicy());
public static string StripMarkdownPooled(string markdown)
{
   	var sb = StringBuilderPool.Get();
	try
	{
		using var writer = new StringWriter(sb, CultureInfo.InvariantCulture);
		Markdig.Markdown.ToPlainText(markdown, writer);
		return writer.ToString().TrimEnd('\n');
	}
	finally
	{
		StringBuilderPool.Return(sb);
	}
}
Method Mean Error Gen0 Gen1 Allocated
StripMarkdown 1.963 us NA 0.4829 0.0029 3.95 KB
StripMarkdownPooled 1.706 us NA 0.4435 0.0027 3.63 KB

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh interesting, thank you!

How did you actually measure this?

Copy link
Member

Choose a reason for hiding this comment

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

Benchmark dot Will add a general benchmarking project at some point in the next week so we can utilize this more.

and: https://www.elastic.co/guide/en/ecs-logging/dotnet/current/benchmark-dotnet-data-shipper.html on CI 😄

@reakaleek reakaleek requested a review from Mpdreamz January 23, 2025 12:13
get => _titleRaw;
private set
{
Title = value?.StripMarkdown();
Copy link
Member

@Mpdreamz Mpdreamz Jan 23, 2025

Choose a reason for hiding this comment

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

I meant it reverse e.g:

Title is the sanitized version.

public string TitleRaw { get; private set; }

public string? Title
{
    get => _title;
    private set
    {
        _title = value?.StripMarkdown();
        TitleRaw = value;
    }
}

That way the change is not that pervasive, the only place we need access to the markdown is in the rendering slice.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I think I got it right now.

e00d555

@reakaleek reakaleek force-pushed the feature/fix-inline-code-in-left-navigation branch from 35719a0 to e00d555 Compare January 23, 2025 15:17
@reakaleek reakaleek requested a review from Mpdreamz January 23, 2025 15:19
Copy link
Member

@bmorelli25 bmorelli25 left a comment

Choose a reason for hiding this comment

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

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Links in headings render incorrectly in OTP Inline code in left side navigation not rendered
3 participants