toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.5k stars 259 forks source link

Unable to use 'media' queries in html templates #536

Open lazarus-cm opened 7 months ago

lazarus-cm commented 7 months ago

I'm using FluentEmail which has a dependency on RazorLight. If my email template contains media css queries within style tags I get this exception:

RazorLight.Compilation.TemplateCompilationException: 'Failed to compile generated Razor template: The name 'media' does not exist in the current context

Steps to reproduce the behavior: Add FluentEmail nuget package. Add RazorLight package (v .2.3.1) Use an html template that includes a media query:

@@media only screen and (max-width: 479px) { table[class="wrapper"], tr[class="wrapper"], td[class="wrapper"] { width: 100% !important; max-width: 480px !important; min-width: 320px !important; } }

Call IFluentEmail.UsingTemplate(template, model, true)

Expected behavior Using a media query (obviously escaped, i.e. @@media should not raise an exception.

Setup