-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_test.csx
executable file
·54 lines (41 loc) · 1.29 KB
/
create_test.csx
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
// real reference:
#r "./Tests/bin/Debug/netcoreapp3.1/BlaTeX.Tests.dll"
// path hints:
#r "./Tests/bin/Debug/netcoreapp3.1/BlaTeX.dll"
#r "./Tests/bin/Debug/netcoreapp3.1/JBSnorro.dll"
#r "./Tests/bin/Debug/netcoreapp3.1/Microsoft.JSInterop.dll"
using BlaTeX.Tests;
using System.Xml.Linq;
using JBSnorro;
if (Args.Count != 1)
throw new ArgumentException("Expected one argument.");
string input = Args[0];
Console.WriteLine($"Rendering \"{input}\":");
var imports = new[] { $"{Program.RootFolder}/wwwroot/js/blatex_wrapper.js" };
var result = await new NodeJSRuntime(imports).InvokeAsync<string>("blatex_wrapper.default.renderToString", new[] { input }).AsTask();
bool wrap = true;
if (wrap)
{
Console.WriteLine();
Console.WriteLine("@inherits KaTeXTestComponentBase");
Console.WriteLine();
result = $"<KaTeXTest math=\"{input}\">{result}</KaTeXTest>";
}
static string Format(string s)
{
return XElement.Parse(s).ToString();
}
var formatted = Preserve("\n", Format)(result);
Console.WriteLine(formatted);
Func<string, string> Preserve(string stringToPreserve, Func<string, string> map)
{
string f(string s)
{
const string escapeSequence = "escapestring";
s = s.Replace(stringToPreserve, escapeSequence);
s = map(s);
s = s.Replace(escapeSequence, stringToPreserve);
return s;
}
return f;
}