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

Taghelper Issue #1

Open
mguinness opened this issue Aug 21, 2016 · 1 comment
Open

Taghelper Issue #1

mguinness opened this issue Aug 21, 2016 · 1 comment

Comments

@mguinness
Copy link

While this code is experimental, I'm having a problem with a taghelper. The tag helper in question parses inline markdown text and outputs as html.

However the minifier currently executes prior to the taghelper processing, causing the output to be incorrect. Do you have any pointers on how the minification can be delayed until taghelpers have completed?

Reading aspnet/Razor#444 is seems that may not be possible due to the way the razor engine breaks the markup into chunks. I would be interested to get your input.

@guardrex
Copy link
Owner

the minifier currently executes prior to the taghelper processing

It isn't so much as "prior to ... processing" as "outside of processing." The (crappy) minifer here (totally a Band-Aid until they make a professional one for us) just doesn't even try to deal with Tag Helper chunks. The only thing I needed to do was deal with spacing issues around hyperlinks, which is why you see this bit in the minifer ...

protected override void Visit(TagHelperChunk chunk)
{
    if (chunk.TagName == "a")
    {
        Writer.Write(@"WriteLiteral("" "");");
        TagHelperRenderer.RenderTagHelper(chunk);
        _comingOffHyperlink = true;
    }
    else
    {
        TagHelperRenderer.RenderTagHelper(chunk);
    }
}

at https://github.com/GuardRex/GuardRex.MinifyingMvcRazorHost/blob/master/ChunkVisitorMinifyingMvcRazorHost.cs#L184-L196

What it sounds like you would need to do is bring in the code under the TagHelperRenderer.RenderTagHelper(chunk); and take the output from the Tag Helper chunks and run them through a method similar to what you see in my MinifyChunk() method.

I don't know how easy/hard that would be to do ... I've never looked at that part of their code to see how it works, but you can take a look at it and see if you want to take a stab at it ... https://github.com/aspnet/Razor/blob/3b9539960b45ccb71d5a7f7d205c265db372b810/src/Microsoft.AspNetCore.Razor/CodeGenerators/CSharpTagHelperCodeRenderer.cs

If you decide to go for it, take the GuardRex minifer code into your app ... take their code ^^ into your app ... step through it as it builds the output of your Tag Helper to see which lines are actually creating the markup. Those are the spot(s) where you need to minify the html coming out. That's how I built the minifer itself. I just watched the Razor engine running line-by-line as it was processing a sample page to understand how it was building the output and where/when I needed to minify.

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

No branches or pull requests

2 participants