Skip to content

fix, unordered list utilize type attribute - #249

Merged
onizet merged 5 commits into
onizet:devfrom
AyUsH18102001:task/ahi/no-ref/nested-uo-list-uses-own-marker-setting
Oct 12, 2026
Merged

onizet merged 5 commits into
onizet:devfrom
AyUsH18102001:task/ahi/no-ref/nested-uo-list-uses-own-marker-setting

Conversation

@AyUsH18102001

Copy link
Copy Markdown
Contributor

Problem Statement

Only ordered lists have the capability to utilize the legacy tyoe attribute

Resolution

Both ordered and unordered list mut utilize their legacy type attribute in absence of inline stle list-style-type attribute Both list tyle types are resolved in the method ListTypeToListStyleType()

@onizet onizet left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I was using w3schools.com and they never talk about the type attribute on the UL tag. This is a nice addition to make this library more complete. Thank you for all your support recently.


var paragraphs = mainPart.Document!.Body!.Elements<Paragraph>().ToList();
Assert.That(paragraphs, Has.Count.EqualTo(4));
Assert.That(paragraphs.Select(GetBulletText), Is.EqualTo(new[] { "•", "▪", "•", "▪" }));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This would be better to use [TestCase] and returning that BulletText as ExpectedResult.

return null;

if (!orderedList)
return type!.ToLowerInvariant() switch

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The null forgiving "!" is no longer needed as you assert first string.IsNullOrEmpty

if (!orderedList)
return type!.ToLowerInvariant() switch
{
"disc" or "circle" or "square" => type.ToLowerInvariant(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is a 2nd call ToLowerInvariant() which could be avoided. Just returns "disc" => disc, "circle" => "circle" etc

To avoid that if branch, you can use this pattern matching:

return (orderedList, type) switch
{
    (false, var t) when t.Equals("disc", StringComparison.OrdinalIgnoreCase)
        => "disc",
    (false, var t) when t.Equals("circle", StringComparison.OrdinalIgnoreCase)
        => "circle",
    (false, var t) when t.Equals("square", StringComparison.OrdinalIgnoreCase)
        => "square",

    (true, "1") => "decimal",
    (true, "a") => "lower-alpha",
    (true, "A") => "upper-alpha",
    (true, "i") => "lower-roman",
    (true, "I") => "upper-roman",
    (true, "lower-greek" or "upper-greek") => type,

    _ => null
};

"A" => "upper-alpha",
"i" => "lower-roman",
"I" => "upper-roman",
"lower-greek" or "upper-greek" => type,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This line hits my eyes because it enforces casing. But I was already reviewing the MDN documentation and those are not part of the W3C standard.
Interesting part is using Git blame, I see that it was you who submitted that code change. Do you use that or was that included by mistake?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I invluded the greek list marker styles (lower-greek and upper-greek) for a bug which I submitted long back, here is the commit 524efdc#diff-14522a172736ece97f58356f21b2c45c09eddcca8442774351b948d9aea10d05

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Yes, agree I saw your commit. But your previous PR brought support of list-style-type: lower-greek which is a W3C standard. type: lower-greek is non-standard.
As you were the original author of that line change, I'm checking if your intent was to use list-style-type AND type ? If not, you can remove the greek version of type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if your intent was to use list-style-type AND type

yes, now that we have merged both attributes (type and list-style-type) resolution in the ListTypeToListStyleType() for both ul and ol elements. we cant differentiate that the type arg is from either of the attribute value

So for ordered list since there is no support for greek markers in legacy "type" attribute, it would always resolved by "list-style-type" inline style attribute

I hope this is what you were looking for as response

@AyUsH18102001

Copy link
Copy Markdown
Contributor Author

Hello @onizet

yes, our usecase involves sanitized html from word as well, and this html produces such legacy attrbutes dependent html tags.
wil resolve all the flagged comments

@AyUsH18102001

Copy link
Copy Markdown
Contributor Author

Hello @onizet

new changes pushed, please review

Thanks

[TestCase("disc", "circle", ExpectedResult = "•,\u25CB,•,\u25CB")]
public async Task<string> NestedUnorderedList_TypeAttribute_UsesOwnBullet(string listType, string nestedListType)
{
await converter.ParseBody($@"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Simplify the HTML to the minimum. The goal is not to test consecutive list. So please remove the 2nd <ul>
The [Test] is no longer applicable (as you now accept params) so convert it to /// <summary>
and rename Ingredients to List Item1 and so on.
Thanks!

@AyUsH18102001 AyUsH18102001 Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

(true, "A") => "upper-alpha",
(true, "i") => "lower-roman",
(true, "I") => "upper-roman",
(true, "lower-greek" or "upper-greek") => type,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this is case-sensitive which is not defensive. So either applies the same logic as Equals(OrdinalIgnoreCase), either remove lower/upper-greek which are non-standard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed the "lower-greek" and "upper_greek" case

@AyUsH18102001

Copy link
Copy Markdown
Contributor Author

comments resolved

@onizet
onizet merged commit b1231bc into onizet:dev Oct 12, 2026
3 checks passed
onizet added a commit that referenced this pull request Oct 12, 2026
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.

2 participants