trenz-gmbh / TRENZ.Lib.RazorMail

Templated transactional e-mail using Razor
https://nuget.org/packages/TRENZ.Lib.RazorMail.Core
MIT License
3 stars 0 forks source link

Check if analyzers are possible for Razor views #6

Open ricardoboss opened 11 months ago

ricardoboss commented 11 months ago

This would allow us to integrate https://www.caniemail.com/api/data.json and display warnings if we are using features not supported by our mail client targets.

chucker commented 11 months ago

May not be so trivial. Roslyn doesn't seem to have an actual semantic model for the DOM; it writes most of it as literals. E.g.,

<head>
    <title></title>

    <style type="text/css">
        * { text-align: center;
        }
    </style>

…seems to become:

            WriteLiteral("\n<!DOCTYPE html>\n\n<html lang=\"en\">\n");
            __tagHelperExecutionContext = __tagHelperScopeManager.Begin("head", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "…", async() => {
                WriteLiteral("\n    <title></title>\n\n    <style type=\"text/css\">\n        * { text-align: center;\n        }\n    </style>\n\n    ");

We can debug this behavior with <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> in the .csproj.

chucker commented 6 months ago

Might be doable.

4>Sample.cshtml(25,11): Warning RzMa0001 : The tag '<details>' has limited support
image
chucker commented 6 months ago
image

So I have a proof of concept, of sorts.

Now, here come some caveats, aside from development for this being a drag (I've had VS crash, I've had the analyzer silently decide not to work, etc.):