Closed kobruleht closed 3 years ago
using System;
using RazorEngineCore;
namespace ConsoleApp44
{
class Program
{
static void Main(string[] args)
{
RazorEngine engine = new RazorEngine();
IRazorEngineCompiledTemplate razorEngineCompiledTemplate = engine.Compile(@"
@if (true) {
var test=1;
}
");
Console.WriteLine(razorEngineCompiledTemplate.Run());
Console.ReadKey();
}
}
}
looks ok to me
Try without if:
@{
var test=1;
}
same output
namespace ConsoleApp44
{
class Program
{
static void Main(string[] args)
{
RazorEngine engine = new RazorEngine();
IRazorEngineCompiledTemplate razorEngineCompiledTemplate = engine.Compile(@"
@{
var test=1;
}
");
Console.WriteLine("start");
Console.WriteLine(razorEngineCompiledTemplate.Run());
Console.WriteLine("end");
Console.ReadKey();
}
}
}
Please try
<img src='@("test")'>
output is without trailing ' :
<img src='test>
could you please submit it a way of console app code, like I do. It will make reproducing a lot easier
Code:
using System;
using System.Threading.Tasks;
using RazorEngineCore;
namespace SampleApp
{
public class Program
{
static async Task Main(string[] args)
{
RazorEngine razorEngine = new RazorEngine();
var template =
await razorEngine.CompileAsync<RazorEngineCorePageModel>(
@"<img href='@(""test"")'>");
var res = await template.RunAsync();
// Observed: trailing ' is lost
Console.WriteLine(res);
Console.ReadKey();
}
}
}
Project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RazorEngineCore" Version="2021.3.1" />
<PackageReference Include="RazorEngineCore.Extensions" Version="0.3.0" />
</ItemGroup>
</Project>
Without RazorEngineCore.Extensions package it works OK .
RazorEngineCore.Extensions provides encoding and Html helper which are used for Html rendering. RazorEngineCore.Extensions seems dead. Why not to add using html encoding by default and Html helper from it to RazorEngineCore.
@adoconnection this is resolved on my end, you can close this issue.
To reproduce, add code block to template like
Works as expected. This will appear in result as plain text.
How to run code blocks like in real Razor ?
Using