Antaris/RazorEngine — Issue #34: Getting Raw Html to work..
Author: JakeGinnivan
Created: 2012-03-09 09:32:27+00:00
State: open

Hey,

I am trying to get Razor support happening in https://github.com/JakeGinnivan/pretzel

Here is my Linqpad script against 3.0.8 (latest nuget package)

void Main()
{
try
{	var config = new FluentTemplateServiceConfiguration(c=>c.EncodeUsing());
new TemplateService(config).Parse("

@(new RazorEngine.Text.HtmlEncodedString(\"Bold!\"))

").Dump();

}
catch (TemplateCompilationException ex)
{
ex.Errors.Dump();
ex.Dump();
}
}
public class MvcHtmlStringFactory : IEncodedStringFactory
{
public IEncodedString CreateEncodedString(string rawString)
{
return new HtmlEncodedString(rawString);
}

public IEncodedString CreateEncodedString(object obj)
{
obj.Dump();
if (obj == null)
return new HtmlEncodedString(string.Empty);

var htmlString = obj as HtmlEncodedString;
if (htmlString != null)
return htmlString;

return new HtmlEncodedString(obj.ToString());
}
}

The output is:

<strong>Bold!</strong>

I have tried a heap of combinations and I just cannot get a Raw Html string outputted. Please point me in the right direction...