Düzeneleme ve Sitil Güncellemesi
This commit is contained in:
@@ -21,32 +21,73 @@ namespace hMarkdown
|
||||
public Form1(string fn)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.AllowDrop = true;
|
||||
this.DragEnter += Form1_DragEnter;
|
||||
this.Resize += Form1_Resize;
|
||||
|
||||
if (fn.Length>0) {
|
||||
tbDosya.Text = fn;
|
||||
DosyaAc(); }
|
||||
DosyaAc();
|
||||
}
|
||||
}
|
||||
|
||||
private void Form1_Resize(object sender, EventArgs e)
|
||||
{
|
||||
if (this.Width > 200)
|
||||
tbDosya.Width = this.Width - 250;
|
||||
}
|
||||
|
||||
private void Form1_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
|
||||
private void DosyaAc()
|
||||
{
|
||||
string contents = File.ReadAllText(@tbDosya.Text);
|
||||
try {
|
||||
if(File.Exists(tbDosya.Text)) {
|
||||
rtbEditor.Text = File.ReadAllText(tbDosya.Text);
|
||||
}
|
||||
} catch {}
|
||||
RenderHtml();
|
||||
}
|
||||
|
||||
var result = Markdown.ToHtml(contents);
|
||||
var bas = @"<html><style type = ""text/css"">
|
||||
.markdown-body {
|
||||
color-scheme: light;
|
||||
-ms-text-size-adjust: 100%;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
margin: 0;
|
||||
color: #1f2328;
|
||||
background-color: #fff;
|
||||
font-family: -apple-system, Threbucet, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Tahoma, Verdana, Arial, sans-serif, ""Apple Color Emoji"", ""Segoe UI Emoji"";
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
word-wrap: break-word;}
|
||||
</style><body> <div id = ""output"" class=""markdown-body"">";
|
||||
private void RenderHtml()
|
||||
{
|
||||
string contents = rtbEditor.Text;
|
||||
|
||||
result = bas + result + "</div></body></html>";
|
||||
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
|
||||
var result = Markdown.ToHtml(contents, pipeline);
|
||||
|
||||
var bas = @"<html>
|
||||
<head>
|
||||
<meta http-equiv=""X-UA-Compatible"" content=""IE=edge"" />
|
||||
<link rel=""stylesheet"" href=""https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown-light.min.css"">
|
||||
<link rel=""stylesheet"" href=""https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.5/styles/github.min.css"">
|
||||
<script src=""https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.5/highlight.min.js""></script>
|
||||
<script>hljs.initHighlightingOnLoad();</script>
|
||||
<style>
|
||||
.markdown-body {
|
||||
box-sizing: border-box;
|
||||
min-width: 200px;
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 45px;
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
.markdown-body {
|
||||
padding: 15px;
|
||||
}
|
||||
}
|
||||
table { width: 100%; }
|
||||
img { max-width: 100%; }
|
||||
</style>
|
||||
</head>
|
||||
<body class=""markdown-body"">";
|
||||
|
||||
result = bas + result + @"
|
||||
</body>
|
||||
</html>";
|
||||
webBrowser.DocumentText = result;
|
||||
|
||||
//webBrowser.Document.Body.Style.font = "font-family: Tahoma, Threbucet, Verdana; font-size: large;";
|
||||
@@ -71,7 +112,68 @@ namespace hMarkdown
|
||||
private void Form1_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
foreach (string file in files) Console.WriteLine(file);
|
||||
if (files.Length > 0)
|
||||
{
|
||||
tbDosya.Text = files[0];
|
||||
DosyaAc();
|
||||
}
|
||||
}
|
||||
|
||||
private void tbEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (rtbEditor.Visible)
|
||||
{
|
||||
rtbEditor.Visible = false;
|
||||
webBrowser.Visible = true;
|
||||
tbEdit.Text = "Düzenle";
|
||||
RenderHtml();
|
||||
}
|
||||
else
|
||||
{
|
||||
rtbEditor.Visible = true;
|
||||
webBrowser.Visible = false;
|
||||
tbEdit.Text = "Görüntüle";
|
||||
}
|
||||
}
|
||||
|
||||
private void tbSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(tbDosya.Text))
|
||||
{
|
||||
File.WriteAllText(tbDosya.Text, rtbEditor.Text);
|
||||
MessageBox.Show("Dosya kaydedildi.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save as... logic could go here, but for now just warn
|
||||
MessageBox.Show("Lütfen önce bir dosya açın veya oluşturun.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Hata: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void tbHelp_Click(object sender, EventArgs e)
|
||||
{
|
||||
ShowHelp();
|
||||
}
|
||||
|
||||
private void rtbEditor_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.F1)
|
||||
{
|
||||
ShowHelp();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowHelp()
|
||||
{
|
||||
var helpForm = new HelpForm();
|
||||
helpForm.Show();
|
||||
}
|
||||
|
||||
private void webBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
|
||||
@@ -82,14 +184,7 @@ namespace hMarkdown
|
||||
{
|
||||
|
||||
tbDosya.Text = file.Replace("file:///", ""); ;
|
||||
string contents = File.ReadAllText(@tbDosya.Text);
|
||||
|
||||
var result = Markdown.ToHtml(contents);
|
||||
|
||||
webBrowser.DocumentText = result;
|
||||
webBrowser.Document.ExecCommand("SelectAll", false, "null");
|
||||
webBrowser.Document.ExecCommand("FontName", false, "Tahoma");
|
||||
webBrowser.Document.ExecCommand("Unselect", false, "null");
|
||||
DosyaAc();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user