Example #1
0
        private void ButtonResult_Click(object sender, EventArgs e)
        {
            // TextBoxEdit.Text = ""
            if (string.IsNullOrEmpty(TextBoxEdit.Text))
            {
                return;
            }
            string sTemp;
            string sTempHtml;

            sTemp = TextBoxEdit.Text;

            // Preparing. Maybe someone paste ready code to this window
            sTemp = sTemp.Replace("<br>", Constants.vbNewLine + Constants.vbNewLine);
            sTemp = sTemp.Replace("<html>", "");
            sTemp = sTemp.Replace("</html>", "");
            sTemp = sTemp.Replace("<head>", "");
            sTemp = sTemp.Replace("<body>", "");
            sTemp = sTemp.Replace("</body>", "");


            sTemp = sTemp.Replace(Constants.vbNewLine + Constants.vbNewLine, Constants.vbNewLine + Constants.vbNewLine + "<br>");
            sTemp = "<html><head><body>" + Constants.vbNewLine + sTemp + Constants.vbNewLine + "</body></html>";
            TextBoxResult.Text = sTemp;

            sTemp     = sTemp.Replace("<body>", "<body text=\"#FFFFFF\" bgcolor=\"#000000\">" + Constants.vbNewLine + "<font face=\"Tahoma, Arial, Verdana, Helvetica, Sans-Serif\" size=\"2\">");
            sTemp     = sTemp.Replace("<a action=", "<a href=");
            sTemp     = sTemp.Replace("<a href=", "<a target=\"_blank\" href=");
            sTemp     = sTemp.Replace(Constants.vbNewLine, "");
            sTemp     = sTemp.Replace("<br>", Constants.vbNewLine + Constants.vbNewLine + "<br><br>");
            sTemp     = sTemp.Replace("<font color=\"LEVEL\">", "<font color=\"FFFF33\">");
            sTempHtml = sTemp;

            var outTempFile = new System.IO.StreamWriter("~temp.htm", false, System.Text.Encoding.Unicode, 1);

            outTempFile.Write(sTemp);
            outTempFile.Close();

            var sUrl = new Uri(Environment.CurrentDirectory + @"\~temp.htm");

            WebBrowserPreview.Url = sUrl;
            WebBrowserPreview.Show();
        }
Example #2
0
        public void RefreshPreview(bool dontReloadData = false, TableLocation loc = null)
        {
            if (!IsPreviewActive)
            {
                return;
            }

            if (!dontReloadData)
            {
                TableData = Interop.GetJsonTableData();
            }

            this.PreviewTableLocation = loc;

            var parser = new TableParserHtml();

            parser.TableData = TableData;

            string markdown = null;

            if (TableMode == "Grid Table")
            {
                markdown = parser.ToGridTableMarkdown();
            }
            else if (TableMode == "Html Table")
            {
                markdown = parser.ToTableHtml();
            }
            else
            {
                markdown = parser.ToPipeTableMarkdown();
            }

#if DEBUG
            var file       = Path.Combine("c:\\projects\\MarkdownMonster\\MarkdownMonster", "PreviewThemes", "TableEditor.html");
            var outputFile = file.Replace("TableEditor.html", "_TableEditorPreview.html");
            var url        = outputFile;
#else
            var file       = Path.Combine(App.InitialStartDirectory, "PreviewThemes", "TableEditor.html");
            var outputFile = file.Replace("TableEditor.html", "_TableEditorPreview.html");
            var url        = outputFile;
#endif
            var doc  = new MarkdownDocument();
            var html = doc.RenderHtml(markdown);

            try
            {
                string template = File.ReadAllText(file);
                template = template.Replace("{{Theme}}", mmApp.Configuration.PreviewTheme);
                template = template.Replace("{{Content}}", html);
                string body = StringUtils.ExtractString(template, "<body>", "</body>", returnDelimiters: true);

                // replace the entire body with just the HTML and remove scripts
                template = template.Replace(body, "<body>\n" + html + "\n</body>");

                File.WriteAllText(outputFile, template);
            }
            catch
            {
                // if this fails use the template shipped
            }

            WebBrowserPreview.Navigate(url);
        }