private void previewPageToolStripMenuItem_Click(object sender, EventArgs e) { Form1 form1; if (this.ActiveMdiChild is Form1) { form1 = (Form1)this.ActiveMdiChild; if (form1 != null) { string srcPath = form1.filepath; string targetPath = Path.Combine(Program.BlogSiteRoot, "_drafts"); if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } targetPath = Path.Combine(targetPath, "temp.html"); string title = Path.GetFileName(srcPath); SetStatus("Busy: Converting MD to Html."); PandocUtil.MD2Html(Program.BlogSiteRoot, Program.WorkingDirectory, srcPath, targetPath, title); frmwebBrowser wb = new frmwebBrowser(); wb.MdiParent = this; wb.Text = srcPath + childFormNumber++; wb.WindowState = FormWindowState.Maximized; wb.PathStr = targetPath; SetStatus("Busy: Rendering Preview."); wb.Show(); } } }
//New private void Html2MD_Click(object sender, EventArgs e) { var fileContent = string.Empty; var filePath = string.Empty; string file = ""; Form1 form1; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "Word files (*.html)|*.html|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { string targetPath = Path.Combine(Program.BlogSiteRoot, "_drafts"); if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } var srcPath = openFileDialog.FileName; string srcfilename = Path.GetFileName(srcPath); string srcfilebase = Path.GetFileNameWithoutExtension(srcfilename); string srcfilebasedotted = srcfilebase.Replace(" ", "-"); targetPath = Path.Combine(targetPath, srcfilebasedotted + ".md"); string mediaFolder = Path.Combine(Program.BlogSiteRoot, "media"); PandocUtil.MD2Html(mediaFolder, Program.WorkingDirectory, srcPath, targetPath, srcfilebase); string txt = ""; using (StreamReader sr = File.OpenText(targetPath)) txt = sr.ReadToEnd(); string crud = Program.BlogSiteRoot + "\\media/"; txt = txt.Replace(crud, "/media/"); File.WriteAllText(targetPath, txt); form1 = LoadForm1(); form1.Text = openFileDialog.FileName; form1.srcFilePath = targetPath; form1.tbSrcFilename_Text = srcfilebasedotted + ".md"; form1.tbSrcFolder_Text = Path.Combine(Program.BlogSiteRoot, "_draft"); form1.tbUrl_Text = ""; form1.tbHtmlTitle_Text = ""; form1.LoadFile(true); form1.Show(); form1.chkJustrDoneConversion_Checked = true; form1.Text = targetPath + " " + childFormNumber++; } } }