From 2735520d22a61bb506a17d913ec6769dbb897017 Mon Sep 17 00:00:00 2001 From: Vertexi <778950965@qq.com> Date: Fri, 15 Mar 2024 13:36:10 +0800 Subject: [PATCH] improve error handle in js mathml convert --- tex2mathml/Views/MainView.axaml.cs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/tex2mathml/Views/MainView.axaml.cs b/tex2mathml/Views/MainView.axaml.cs index f400991..3c2b573 100644 --- a/tex2mathml/Views/MainView.axaml.cs +++ b/tex2mathml/Views/MainView.axaml.cs @@ -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(), @"", @""); + mathML = engine.Evaluate(@"temml.renderToString(inputtext, { displayMode: true })").ToObject(); + if (mathML.ToString().IndexOf("error") == 0) + { + mathML = ReplaceFirstOccurrence(mathML.ToString(), @"", @""); + } + else { + mathML = @"

" + mathML + "

"; + } } - else { - mathML = @"

" + mathML + "

"; + catch (Exception jsEngineErr) + { + mathML = @"

" + jsEngineErr.Message + "

"; } - - var mathMlHtml = @" + finally + { + var mathMlHtml = @" @@ -83,8 +92,8 @@ private void Formula_TextChanged(object? sender, TextChangedEventArgs e) "; - PART_WebView.HtmlContent = mathMlHtml; - + PART_WebView.HtmlContent = mathMlHtml; + } } private void PART_WebView_WebViewNewWindowRequested(object? sender, WebViewCore.Events.WebViewNewWindowEventArgs e)