package main import ( "os" "regexp" qt "github.com/mappu/miqt/qt6" ) // src_to_html converts plaintext Javascript source to HTML with embedded images // for use with QTextEdit. func src_to_html(s string) string { // Convert "" to but only if the target file exists return regexp.MustCompile(`"[0-9]+\.png"`).ReplaceAllStringFunc(s, func(match string) string { rawName := match[1 : len(match)-1] if _, err := os.Stat(rawName); err == nil { return `` } return match // no good }) } // html_to_src converts the mini HTML from a QTextEdit into plaintext Javascript // source, with images converted back to string literals. func html_to_src(s string) string { // Convert to "" patchedHtmlSrc := regexp.MustCompile(``).ReplaceAllStringFunc(s, func(match string) string { return match[9 : len(match)-3] }) tmp := qt.NewQTextEdit2() tmp.SetHtml(patchedHtmlSrc) ret := tmp.ToPlainText() tmp.Delete() return ret }