trenz-gmbh / TRENZ.Lib.RazorMail

Templated transactional e-mail using Razor
MIT License
2 stars 0 forks source link

Check if analyzers are possible for Razor views #6

Open ricardoboss opened 10 months ago

ricardoboss commented 10 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 10 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 5 months ago

Might be doable.

4>Sample.cshtml(25,11): Warning RzMa0001 : The tag '<details>' has limited support
image
chucker commented 5 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.):