statiqdev / Statiq.Framework

A flexible and extensible static content generation framework for .NET.
https://statiq.dev/framework
MIT License
425 stars 74 forks source link

GatherHeading doesn't include text from code blocks #238

Closed phil-scott-78 closed 2 years ago

phil-scott-78 commented 2 years ago

Given a heading like

<h2>My <code>string</code> is so powerful</h2>

the gathered up content ends up being "My is so powerful.

Looking at the code there is a special case for handling anchors. I just copied and pasted this module and created my own version that simply reads

if (x is IText text)
{
    return text.Text;
}

return string.Join(
    string.Empty,
    x.ChildNodes.OfType<IText>().Select(t => t.Text));
})

I'm sure I'm missing some cases, but this seems to be a bit more foolproof, especially if someone has things like bold, italics or just a span in there.

phil-scott-78 commented 2 years ago

Disregard! I was going through release notes while upgrading Statiq and it looks like you answered my question back in March with the WithNestedElements option.

I'll close this down.

daveaglick commented 2 years ago

Oh good, problems past me fixed are the best kind! I'm guessing it's not quite as smart as the code you posted above though in terms of looking for IText nodes, so let me know if it looks like we need to improve the feature after using it.

phil-scott-78 commented 2 years ago

It's working well for me right now, and I put a lot of silly stuff in headings so I suspect anyone doing anything different doesn't have valid HTML.

That being said I'm not sure how I'm configuring this is the best or most stable. Is there a more clever way to swap out a nested middle?

Ultimately it would be pretty slick if modules had a stable and unique identifier in the default pipeline that I could get right at.