Skip to content

Commit

Permalink
improve error handle in js mathml convert
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexi committed Mar 15, 2024
1 parent 869e112 commit 2735520
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tex2mathml/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@ private void Formula_TextChanged(object? sender, TextChangedEventArgs e)

string jstr = System.IO.File.ReadAllText("./assets/temml.min.js");
engine.Execute(jstr);
var mathML = engine.Evaluate(@"temml.renderToString(inputtext)").ToObject();
if (mathML.ToString().IndexOf("error") == 0)
var mathML = new object();
try
{
mathML = ReplaceFirstOccurrence(mathML.ToString(), @"<math>", @"<math xmlns=""http://www.w3.org/1998/Math/MathML"">");
mathML = engine.Evaluate(@"temml.renderToString(inputtext, { displayMode: true })").ToObject();
if (mathML.ToString().IndexOf("error") == 0)
{
mathML = ReplaceFirstOccurrence(mathML.ToString(), @"<math>", @"<math xmlns=""http://www.w3.org/1998/Math/MathML"">");
}
else {
mathML = @"<p>" + mathML + "</p>";
}
}
else {
mathML = @"<p>" + mathML + "</p>";
catch (Exception jsEngineErr)
{
mathML = @"<p>" + jsEngineErr.Message + "</p>";
}

var mathMlHtml = @"<!DOCTYPE html>
finally
{
var mathMlHtml = @"<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -83,8 +92,8 @@ private void Formula_TextChanged(object? sender, TextChangedEventArgs e)
</body>
</html>
";
PART_WebView.HtmlContent = mathMlHtml;

PART_WebView.HtmlContent = mathMlHtml;
}
}

private void PART_WebView_WebViewNewWindowRequested(object? sender, WebViewCore.Events.WebViewNewWindowEventArgs e)
Expand Down

0 comments on commit 2735520

Please sign in to comment.