-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseAsCodeLibrary.cs
More file actions
57 lines (46 loc) · 1.54 KB
/
UseAsCodeLibrary.cs
File metadata and controls
57 lines (46 loc) · 1.54 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
namespace Airudit.MdBook.UnitTests;
using Airudit.MdBook.Core;
using System.Text;
public class UseAsCodeLibrary
{
[Fact]
public void Demo()
{
var inputPath = GetLocalFilePath("sample1.md");
var outputPath = GetLocalFilePath("sample1.md.html");
if (File.Exists(outputPath))
{
File.Delete(outputPath);
}
// demo code from the README file
SimpleMdToHtml(inputPath, null);
// verify
Assert.True(File.Exists(outputPath));
var contents = File.ReadAllText(outputPath, Encoding.UTF8);
Assert.Contains("<html", contents);
Assert.Contains("<h1 id=\"title\">Title</h1>", contents);
File.Delete(outputPath);
}
private static string GetLocalFilePath(string path)
{
return Path.Combine(Environment.CurrentDirectory, "../../..", path);
}
/// <summary>
/// Create an HTML from Markdown path file
/// </summary>
public static void SimpleMdToHtml(string inputFilePath, string? templateFilePath)
{
// configure
var sourceFile = new FileInfo(inputFilePath);
var layer = new SimpleMarkdownToHtmlLayer();
layer.AddFile(sourceFile, true);
layer.TemplateFilePath = templateFilePath;
// prepare stack
var context = new PackageContext();
context.AddLayer(layer);
var simpleConverterTask = new SimpleMarkdownToHtmlTask();
simpleConverterTask.Visit(context);
// this generates the file
simpleConverterTask.Run(context);
}
}