Esempio n. 1
0
        private void markdownForm_Load(object sender, EventArgs e)
        {
            lblTitle.Text = fileName;
            // markdig
            resourcePath = Directory.GetParent(Application.StartupPath).FullName + "\\res\\";
            string       filePath = resourcePath + fileName + ".md";
            StreamReader sr       = new StreamReader(new FileStream(
                                                         filePath,
                                                         FileMode.Open
                                                         )
                                                     );

            pipeline = new MarkdownPipelineBuilder()
                       .UseAdvancedExtensions()
                       .UseSyntaxHighlighting()
                       .Build();
            string result   = Markdown.ToHtml(sr.ReadToEnd(), pipeline);
            string htmlPath = resourcePath + "main.html";
            string cssLink  = "<link rel= \"stylesheet\" href= \"style.css\">\n";
            string incoding = "<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>\n";

            File.WriteAllText(htmlPath, string.Empty);
            StreamWriter sw = new StreamWriter(new FileStream(
                                                   htmlPath,
                                                   FileMode.Open
                                                   )
                                               );

            sw.WriteLine(cssLink + incoding + result);
            sw.Close();
            sr.Close();
            webBrowser.Url = new Uri(string.Format("file:///{0}/../res/main.html", Application.StartupPath));
            File.WriteAllText(htmlPath, string.Empty);
        }
Esempio n. 2
0
        public MarkdownRenderer(IPlantumlRenderer plantumlRenderer)
        {
            var b = new Markdig.MarkdownPipelineBuilder();

            b.UseAdvancedExtensions();
            b.Extensions.Add(new MarkdownPlantumlExtension(plantumlRenderer));
            markdownPipeline      = b.Build();
            this.plantumlRenderer = plantumlRenderer;
        }
Esempio n. 3
0
        public static string ConvertToHtml(string text, string uploadsPrefix, Markdig.MarkdownPipeline pipeline)
        {
            if (String.IsNullOrEmpty(text))
            {
                return(String.Empty);
            }

            // fix #319, most likely this is just a workaround for Markdig bug
            text = text.Replace("<details>", "").Replace("</details>", "");

            return(System.Net.WebUtility
                   .HtmlDecode(Markdig.Markdown.ToHtml(System.Net.WebUtility.HtmlEncode(text), pipeline))
                   .Replace("<a href=\"/uploads/", String.Format("<a href=\"{0}/uploads/", uploadsPrefix))
                   .Replace("<img src=\"/uploads/", String.Format("<img src=\"{0}/uploads/", uploadsPrefix)));
        }
Esempio n. 4
0
        private void modifyForm_Load(object sender, EventArgs e)
        {
            menuListBox.SelectedIndex = 0;
            resourcePath = Directory.GetParent(Application.StartupPath).FullName + "\\res\\";
            contentTabControl.SelectedIndex = 0;
            pipeline = new MarkdownPipelineBuilder()
                       .UseAdvancedExtensions()
                       .UseSyntaxHighlighting()
                       .Build();
            webBrowser1.Url = new Uri(string.Format("file:///{0}/../res/preview.html", Application.StartupPath));
            // get .md file name
            DirectoryInfo di = new DirectoryInfo(resourcePath);

            foreach (var item in di.GetFiles("*.md"))
            {
                cboFile.Items.Add(Path.GetFileNameWithoutExtension(item.Name));
            }
            if (cboFile.Items.Count >= 2)
            {
                cboFile.SelectedIndex = 1;
            }
            // location init
            string filePath = resourcePath + "data.txt";

            if (File.Exists(filePath))
            {
                StreamReader sr = new StreamReader(new FileStream(
                                                       filePath,
                                                       FileMode.Open
                                                       )
                                                   );
                string[] spstr = sr.ReadLine().Split(' ');
                sr.Close();
                cboStopwatchLoc.SelectedIndex = int.Parse(spstr[0]);
                cboPopupLoc.SelectedIndex     = int.Parse(spstr[1]);
                cboPopupTime.SelectedIndex    = int.Parse(spstr[2]) - 1;
                cboSource.SelectedIndex       = int.Parse(spstr[3]);
                cboTarget.SelectedIndex       = int.Parse(spstr[4]);
            }
        }
        private void Create()
        {
            this.pipeline = new MarkdownPipelineBuilder()
                            .UseAdvancedExtensions()
                            .UseSyntaxHighlighting()
                            .Build();

            richTextAreaMd = new RichTextArea()
            {
                Width = 320, Height = 600
            };
            richTextAreaHtml = new RichTextArea()
            {
                Width = 320, Height = 600
            };
            previewer = new WebView()
            {
                Width = 320, Height = 600
            };

            richTextAreaMd.Focus();
            richTextAreaMd.TextChanged += (object sender, EventArgs e) =>
            {
                richTextAreaHtml.Text = Markdig.Markdown.ToHtml((sender as RichTextArea).Text, pipeline);
                previewer.LoadHtml(richTextAreaHtml.Text);
            };
            //richTextAreaMd.Text = new StreamReader(new FileStream("/tmp/work/Projects/HelloMarkdown/HelloMarkdown/HelloMarkdown/DefaultMarkdown.md", FileMode.Open)).ReadToEnd();
            //richTextAreaMd.Text = new StreamReader(new FileStream("./DefaultMarkdown.md", FileMode.Open)).ReadToEnd();
            richTextAreaMd.Text = new StreamReader(new FileStream(System.IO.Path.Combine(System.AppContext.BaseDirectory, "DefaultMarkdown.md"), FileMode.Open)).ReadToEnd();
            Content             = new TableLayout
            {
                Padding = 0,
                Spacing = new Size(0, 0),
                Rows    =
                {
                    new TableRow(richTextAreaMd, richTextAreaHtml, previewer),
                }
            };
        }
Esempio n. 6
0
        /// <summary>
        /// Normalizes the specified markdown to a normalized markdown text.
        /// </summary>
        /// <param name="markdown">The markdown.</param>
        /// <param name="writer">The destination <see cref="TextWriter"/> that will receive the result of the conversion.</param>
        /// <param name="options">The normalize options</param>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <returns>A normalized markdown text.</returns>
        public static MarkdownDocument Normalize(string markdown, TextWriter writer, NormalizeOptions options = null, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
        {
            pipeline = pipeline ?? new MarkdownPipelineBuilder().Build();
            pipeline = CheckForSelfPipeline(pipeline, markdown);

            // We override the renderer with our own writer
            var renderer = new NormalizeRenderer(writer, options);

            pipeline.Setup(renderer);

            var document = Parse(markdown, pipeline, context);

            renderer.Render(document);
            writer.Flush();

            return(document);
        }
Esempio n. 7
0
        /// <summary>
        /// Normalizes the specified markdown to a normalized markdown text.
        /// </summary>
        /// <param name="markdown">The markdown.</param>
        /// <param name="options">The normalize options</param>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <returns>A normalized markdown text.</returns>
        public static string Normalize(string markdown, NormalizeOptions options = null, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
        {
            var writer = new StringWriter();

            Normalize(markdown, writer, options, pipeline, context);
            return(writer.ToString());
        }
Esempio n. 8
0
        /// <summary>
        /// Converts a Markdown string to Plain text and output to the specified writer.
        /// </summary>
        /// <param name="markdown">A Markdown text.</param>
        /// <param name="writer">The destination <see cref="TextWriter"/> that will receive the result of the conversion.</param>
        /// <param name="pipeline">The pipeline used for the conversion.</param>
        /// <param name="context">A parser context used for the parsing.</param>
        /// <returns>The Markdown document that has been parsed</returns>
        /// <exception cref="System.ArgumentNullException">if reader or writer variable are null</exception>
        public static MarkdownDocument ToPlainText(string markdown, TextWriter writer, MarkdownPipeline pipeline = null, MarkdownParserContext context = null)
        {
            if (markdown == null)
            {
                throw new ArgumentNullException(nameof(markdown));
            }
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            pipeline = pipeline ?? new MarkdownPipelineBuilder().Build();
            pipeline = CheckForSelfPipeline(pipeline, markdown);

            // We override the renderer with our own writer
            var renderer = new HtmlRenderer(writer)
            {
                EnableHtmlForBlock  = false,
                EnableHtmlForInline = false,
                EnableHtmlEscape    = false,
            };

            pipeline.Setup(renderer);

            var document = Parse(markdown, pipeline, context);

            renderer.Render(document);
            writer.Flush();

            return(document);
        }
Esempio n. 9
0
 public HtmlRendererCache(MarkdownPipeline pipeline, bool customWriter = false)
 {
     _pipeline     = pipeline;
     _customWriter = customWriter;
 }
Esempio n. 10
0
 public MarkdigService(MarkdownPipeline mdpl)
 {
     Pipeline = mdpl;
 }
Esempio n. 11
0
 public MarkdigService(IOptions <MarkdigOptions> options)
 {
     Pipeline = options.Value.PipelineBuilder.Build();
 }
Esempio n. 12
0
 public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)
 {
 }