public async Task HighlightFailsForMissingLanguage() { // Given const string input = @" <html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <pre><code class=""language-zorg""> <html> <head> <title>Hi Mom!</title> </head> <body> <p>Hello, world! Pretty me up! </body> </html> </code></pre> </body> </html>"; TestDocument document = new TestDocument(input); TestExecutionContext context = new TestExecutionContext() { JsEngineFunc = () => new TestJsEngine() }; HighlightCode highlight = new HighlightCode(); // When, Then await Should.ThrowAsync <Exception>(async() => await ExecuteAsync(document, context, highlight)); }
public async Task CanHighlightAutoCodeBlocks() { // Given const string input = @" <html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <pre><code> if (foo == bar) { DoTheFooBar(); } </code></pre> </body> </html>"; TestDocument document = new TestDocument(input); TestExecutionContext context = new TestExecutionContext() { JsEngineFunc = () => new TestJsEngine() }; HighlightCode highlight = new HighlightCode(); // When TestDocument result = await ExecuteAsync(document, context, highlight).SingleAsync(); // Then result.Content.ShouldContain("hljs"); }
public async Task CanHighlightAfterRazor() { // Given // if we execute razor before this, the code block will be escaped. const string input = @" <html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <pre><code class=""language-html""> <strong class="super-strong">this is strong text</strong> </code></pre> </body> </html>"; TestDocument document = new TestDocument(input); TestExecutionContext context = new TestExecutionContext() { JsEngineFunc = () => new TestJsEngine() }; HighlightCode highlight = new HighlightCode(); // When TestDocument result = await ExecuteAsync(document, context, highlight).SingleAsync(); // Then result.Content.ShouldContain("language-html hljs"); }
public async Task CanHighlightCSharp() { // Given const string input = @" <html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <pre><code class=""language-csharp""> class Program { static void Main(string[] args) { var invoices = new List<Invoice> { new Invoice { InvoiceId = 0 } }; var oneTimeCharges = new List<OneTimeCharge> { new OneTimeCharge { Invoice = 0, OneTimeChargeId = 0 } }; var otcCharges = invoices.Join(oneTimeCharges, inv => inv.InvoiceId, otc => otc.Invoice, (inv, otc) => inv.InvoiceId); Console.WriteLine(otcCharges.Count()); } } public class OneTimeCharge { public int OneTimeChargeId { get; set; } public int? Invoice { get; set; } } public class Invoice { public int InvoiceId { get; set; } } </code></pre> </body> </html>"; TestDocument document = new TestDocument(input); TestExecutionContext context = new TestExecutionContext() { JsEngineFunc = () => new TestJsEngine() }; HighlightCode highlight = new HighlightCode(); // When TestDocument result = await ExecuteAsync(document, context, highlight).SingleAsync(); // Then result.Content.ShouldContain("language-csharp hljs"); }
public async Task HighlightSucceedsForMissingLanguageWhenConfiguredNotToWarn() { // Given const string input = @" <html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <pre><code class=""language-zorg""> <html> <head> <title>Hi Mom!</title> </head> <body> <p>Hello, world! Pretty me up! </body> </html> </code></pre> </body> </html>"; TestDocument document = new TestDocument(input); TestExecutionContext context = new TestExecutionContext() { JsEngineFunc = () => new TestJsEngine() }; HighlightCode highlight = new HighlightCode() .WithMissingLanguageWarning(false); // When IReadOnlyList <TestDocument> results = await ExecuteAsync(document, context, highlight); // Then results.ShouldNotBeEmpty(); }
public async Task CanHighlightHtml() { const string input = @" <html> <head> <title>Foobar</title> </head> <body> <h1>Title</h1> <p>This is some Foobar text</p> <pre><code class=""language-html""> <html> <head> <title>Hi Mom!</title> </head> <body> <p>Hello, world! Pretty me up! </body> </html> </code></pre> </body> </html>"; TestDocument document = new TestDocument(input); TestExecutionContext context = new TestExecutionContext() { JsEngineFunc = () => new TestJsEngine() }; HighlightCode highlight = new HighlightCode(); // When TestDocument result = await ExecuteAsync(document, context, highlight).SingleAsync(); // Then result.Content.ShouldContain("language-html hljs"); }