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

Allow parsing of fenced code blocks inside lists #232

Closed
wants to merge 2 commits into from

Conversation

Jeffcole1
Copy link

@Jeffcole1 Jeffcole1 commented Dec 28, 2023

While working with the Mudblazor.Markdown package, I discovered that, if a block of Markdown text being parsed included a fenced code block within a list, the code block would not be rendered in the output. This pull request is designed to correct this issue.

The following Markdown can be used as an example:

To prevent the warning message regarding the deprecation of the mysql_native_password plugin from being logged, you have a couple of options:

Option 1: Update User Authentication Method:

  1. Connect to your MySQL server using a MySQL client, such as the mysql command-line tool:

    mysql -u username -p
  2. Once connected, run the following command to alter the user's authentication method:

    ALTER USER 'username'@'hostname' IDENTIFIED WITH caching_sha2_password;

    Replace 'username' with the actual username and 'hostname' with the appropriate hostname or IP address. If you want to update for all users, replace 'username'@'hostname' with '*'@'%'.

  3. Repeat this process for each user on your MySQL server.

@Jeffcole1 Jeffcole1 marked this pull request as ready for review January 1, 2024 19:52
@MihailsKuzmins MihailsKuzmins self-assigned this Jan 6, 2024
@MihailsKuzmins MihailsKuzmins self-requested a review January 6, 2024 04:57
Copy link
Member

@MihailsKuzmins MihailsKuzmins left a comment

Choose a reason for hiding this comment

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

Also please add a unit test for your code sample (mentioned in the description:

To prevent the warning message regarding the deprecation of the mysql_native_password plugin from being logged, you have a couple of options:

Option 1: Update User Authentication Method:

  1. Connect to your MySQL server using a MySQL client, such as the mysql command-line tool:

    mysql -u username -p
  2. Once connected, run the following command to alter the user's authentication method:

    ALTER USER 'username'@'hostname' IDENTIFIED WITH caching_sha2_password;

    Replace 'username' with the actual username and 'hostname' with the appropriate hostname or IP address. If you want to update for all users, replace 'username'@'hostname' with '*'@'%'.

  3. Repeat this process for each user on your MySQL server.

Comment on lines +435 to +447
case FencedCodeBlock code:
{
builder.OpenElement(ElementIndex++, "li");
var text = code.CreateCodeBlockText();

builder.OpenComponent<MudCodeHighlight>(ElementIndex++);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Text), text);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Language), code.Info ?? string.Empty);
builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Theme), CodeBlockTheme);
builder.CloseComponent();
builder.CloseElement();
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

First of all thank you for making the PR.

But sorry. this implementation is just copy paste from lines 178-182 and it cannot be accepted. Please do the following:

  1. create a function RenderFencedCodeBlock(RenderTreeBuilder, FencedCodeBlock) and use it on the line 176
// 176
case FencedCodeBlock code:
{
	RenderFencedCodeBlock(builder, code);
	break;
}

// 464 (or somewhere else at the end)
protected virtual void RenderFencedCodeBlock(in RenderTreeBuilder builder, in FencedCodeBlock code)
{
	var text = code.CreateCodeBlockText();

	builder.OpenComponent<MudCodeHighlight>(ElementIndex++);
	builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Text), text);
	builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Language), code.Info ?? string.Empty);
	builder.AddAttribute(ElementIndex++, nameof(MudCodeHighlight.Theme), CodeBlockTheme);
	builder.CloseComponent();
}
  1. Instead of your code please use this (there is no need to create a new li element for the code block, at least this is how it should work in your example):
case FencedCodeBlock x:
{
	RenderFencedCodeBlock(builder, x);
	break;
}

Then it will look a bit similar to what is rendered on GitHub. However, the line "Replace username .." should not have the "li" tag, so if you can also fix this problem it would be nice. If you do not want to do it, then I can do it in a separate PR. To give you a hint - it can be determined by "Parent.Order" properties of ParagraphBlock or FencedCodeBlock is the parent is ListItemBlock

image

@MihailsKuzmins
Copy link
Member

Will be fixed in #236

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.

None yet

2 participants