-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCodeSample.cs
More file actions
35 lines (33 loc) · 1.48 KB
/
CodeSample.cs
File metadata and controls
35 lines (33 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.IO;
using System.Reflection;
using Xunit;
namespace Markdig.SyntaxHighlighting.Tests.Example {
public class CodeSample {
[Fact]
public void CodeSampleWorks() {
var location = GetType().GetTypeInfo().Assembly.Location;
var directory = Path.GetDirectoryName(location);
if (directory == null) {
throw new NullReferenceException("appPath came back null.");
}
var appPath = new Uri(directory).LocalPath;
var folder = Path.Combine(appPath, "Example");
var inputMarkdown = Path.Combine(folder, "README.md");
var referenceFile = Path.Combine(folder, "expected.html");
var expectedHtml = File.ReadAllText(referenceFile);
var markdown = File.ReadAllText(inputMarkdown);
var pipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.UseSyntaxHighlighting()
.Build();
var html = Markdown.ToHtml(markdown, pipeline);
var actualHtml = File.ReadAllText(Path.Combine(folder, "_template.html"))
.Replace("{{{this}}}", html);
actualHtml = actualHtml.Replace("\r\n", "\n").Replace("\n", "\r\n");
expectedHtml = expectedHtml.Replace("\r\n", "\n").Replace("\n", "\r\n");
File.WriteAllText(Path.Combine(folder, "actual.html"), actualHtml);
Assert.Equal(expectedHtml, actualHtml);
}
}
}