public string ToHtml(string markdown, Action <MarkdownPipelineBuilder> builder)
        {
            var pipelineBuilder = new Markdig.MarkdownPipelineBuilder();

            builder?.Invoke(pipelineBuilder);
            return(Markdig.Markdown.ToHtml(markdown, pipelineBuilder.Build()));
        }
Beispiel #2
0
        public async Task <IActionResult> Post(IFormFile file, TranslatedFileViewModel model)
        {
            var pipeline = new Markdig.MarkdownPipelineBuilder().UseAdvancedExtensions().Build();

            model.Languages.AddRange(LanguagesList());

            var filePath = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot",
                file.FileName);

            if (file.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                var tr = System.IO.File.ReadAllText(filePath);
                System.IO.File.Delete(filePath);

                model.OriginalHtml = Markdown.ToHtml(tr);
                model.OriginalText = tr.Replace("\r\n", "<br>");

                var translatedText = await Translate(tr, model);

                model.TranslatedHtml = Markdown.ToHtml(translatedText, pipeline);
                model.TranslatedText = translatedText.Replace("\r\n", "<br>");

                model.TranslatedPlainText = translatedText;
                model.from = OriginLanguage;
            }

            return(View("Index", model));
        }
Beispiel #3
0
        public HelpDialog(string filename)
        {
            InitializeComponent();

            string text = "";

            try
            {
                // load text from file
                text = File.ReadAllText(filename);
            }
            catch (Exception)
            {
                App.ShowErrorDialog(this, "Could not open " + filename);
                Close();
                IsValid = false;
                return;
            }

            // convert markup into htm
            var pipe = new Markdig.MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
            var html = Markdig.Markdown.ToHtml(text, pipe);

            // display markup in browser
            Browser.NavigateToString(html);
            Browser.Navigating += BrowserOnNavigating;
        }
        public string MarkdownToSpeakableString(string md)
        {
            var pipeline  = new Markdig.MarkdownPipelineBuilder().UseYamlFrontMatter().UsePipeTables().Build();
            var parsed    = Markdig.Markdown.Parse(md, pipeline);
            var speakable = Render(parsed.AsEnumerable());

            return(speakable);
        }
Beispiel #5
0
        public MarkdownRenderer(IPlantumlRenderer plantumlRenderer)
        {
            var b = new Markdig.MarkdownPipelineBuilder();

            b.UseAdvancedExtensions();
            b.Extensions.Add(new MarkdownPlantumlExtension(plantumlRenderer));
            markdownPipeline      = b.Build();
            this.plantumlRenderer = plantumlRenderer;
        }
Beispiel #6
0
    private void buttonViewHtml_Click(object sender, EventArgs e)
    {
        var MarkdownContent = textDescription.Text;
        var pipeline        = new Markdig.MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
        var HtmlContent     = Markdig.Markdown.ToHtml(MarkdownContent, pipeline);

        htmlDescription.BodyHtml = HtmlContent;
        _com.Model.ContentType   = "html";

        EnableHtmlView();
    }
Beispiel #7
0
        public string RenderToPlainText(string markdown)
        {
            var pipeline = new Markdig.MarkdownPipelineBuilder()
                           .UseYamlFrontMatter()
                           .UseMediaLinks()
                           .UseAdvancedExtensions()
                           .Build();
            var result = Markdig.Markdown.ToPlainText(markdown, pipeline);

            return(result);
        }
        public string ProcessMarkdownFile(string fName)
        {
            // Markdig.Markdown.ToHtml()
            var pipeline = new Markdig.MarkdownPipelineBuilder()
                           .UseAdvancedExtensions()
                           .UseSyntaxHighlighting()
                           .Build();
            string md = File.ReadAllText(fName);

            return(Markdown.ToHtml(md, pipeline));
        }
Beispiel #9
0
        public async Task MarkdownToPdf(IEnumerable <string> mds, Stream stream)
        {
            var pipeline = new Markdig.MarkdownPipelineBuilder().UseYamlFrontMatter().UsePipeTables().Build();

            var document = new Document(new iTextSharp.text.Rectangle(822, 1122));
            var writer   = PdfWriter.GetInstance(document, stream);

            document.Open();
            //PdfReader reader = null;
            //reader = new PdfReader(AideDeJeu.Tools.Helpers.GetResourceStream("AideDeJeu.Pdf.poker_size.pdf"));
            //PdfStamper stamper = null;
            //stamper = new PdfStamper(reader, stream);

            try
            {
                foreach (var md in mds)
                {
                    var expandedMd = await ExpandMarkdownAsync(md);

                    var parsed = Markdig.Markdown.Parse(expandedMd, pipeline);
                    Render(parsed.AsEnumerable(), document, writer);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                try
                {
                    document?.Close();
                }
                catch
                {
                }
                try
                {
                    writer?.Close();
                }
                catch
                {
                }
            }

            //stamper.Close();
            //reader.Close();
        }
        public void SetBookmark(BookmarkPrims bookmarkPrims)
        {
            var     pipeline = new Markdig.MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
            Viewbox viewbox  = new Viewbox();

            RichTextBoxs.Clear();

            foreach (var it in bookmarkPrims)
            {
                int  lineNo = it.Key - 1;
                bool redraw = false;

                CommentRichTextBox TextBox = null;
                if (!RichTextBoxs.ContainsKey(lineNo))
                {
                    TextBox = new CommentRichTextBox(it.Value);
                    RichTextBoxs.TryAdd(lineNo, TextBox);
                    redraw = true;
                }
                else
                if (RichTextBoxs[lineNo].m_comment != it.Value.m_comment)
                {
                    TextBox = RichTextBoxs[lineNo];
                    redraw  = true;
                }
                if (TextBox != null)
                {
                    var html = Markdig.Markdown.ToHtml(it.Value.m_comment, pipeline);
                    var xaml = HtmlToXamlConverter.ConvertHtmlToXaml(html, true);
                    CommentRichTextBox rtb = new CommentRichTextBox();
                    rtb.Document = XamlReader.Parse(xaml) as FlowDocument;
                    SetLineHeight(rtb);
                    double Height = GethDocumentHeight(viewbox, rtb);

                    TextBox.Document            = XamlReader.Parse(xaml) as FlowDocument;
                    TextBox.Document.Background = Brushes.LightGray;
                    SetLineHeight(TextBox);

                    TextBox.Height     = Height;
                    TextBox.Visibility = Visibility.Visible;
                }
                if (redraw)
                {
                    RequestRedrawLine(lineNo);
                }
            }
        }
        public static Markdig.MarkdownPipeline CreatePipeline(string jiraBaseUrl)
        {
            PipeTableOptions pipeTableOptions = new PipeTableOptions
            {
                RequireHeaderSeparator = false
            };

            MarkdownPipelineBuilder pipeline = new Markdig.MarkdownPipelineBuilder()
                                               .UseAutoLinks() // convert `http://...` into HTML `<a href ...>`
                                               .UsePipeTables(pipeTableOptions);

            if (!String.IsNullOrWhiteSpace(jiraBaseUrl))
            {
                pipeline.UseJiraLinks(new JiraLinkOptions(jiraBaseUrl));
            }

            return(pipeline.Build());
        }
Beispiel #12
0
        public ActionResult OnGet()
        {
            aboutMe = _blogContext.UserInformation.OrderByDescending(x => x.Id).FirstOrDefault();
            var markDownPipeline = new Markdig.MarkdownPipelineBuilder().UseAdvancedExtensions().Build();

            if (aboutMe != null)
            {
                MarkDownUserInfor = Markdig.Markdown.ToHtml(aboutMe.UserIntro, markDownPipeline);
            }

            /*
             * if(MarkDownUserInfor == null || MarkDownUserInfor.Length == 0)
             * {
             *  return NotFound();
             * }
             */

            return(Page());
        }
Beispiel #13
0
        private void RenderMarkdown()
        {
            stack = new StackLayout()
            {
                Spacing = this.Theme.Margin,
            };

            this.Padding = this.Theme.Margin;

            this.BackgroundColor = this.Theme.BackgroundColor;

            if (!string.IsNullOrEmpty(this.Markdown))
            {
                var pipeline = new Markdig.MarkdownPipelineBuilder().UsePipeTables().Build();
                var parsed   = Markdig.Markdown.Parse(this.Markdown, pipeline);
                this.Render(parsed.AsEnumerable());
            }

            this.Content = stack;
        }
Beispiel #14
0
        private void RenderMarkdown()
        {
            _Stack = new StackLayout()
            {
                Spacing = this.Theme.Margin,
            };

            this.Padding = this.Theme.Margin;

            this.BackgroundColor = this.Theme.BackgroundColor;

            if (!string.IsNullOrEmpty(this.Markdown))
            {
                var pipeline = new Markdig.MarkdownPipelineBuilder().UseYamlFrontMatter().UsePipeTables().Build();
                var parsed   = Markdig.Markdown.Parse(this.Markdown, pipeline);
                var views    = this.Render(parsed.AsEnumerable());
                views.ToList().ForEach(view => _Stack.Children.Add(view));
            }

            this.Content = _Stack;
        }
Beispiel #15
0
        public ActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            BlogDetail  = _blogContext.Blog.Include(b => b.Comment).ToList().Find(x => x.Id == id);
            BlogUser    = _blogContext.BlogUser.FirstOrDefault();
            BlogComment = new Comment {
                CommentUser = string.Empty,
                CommentText = string.Empty
            };
            var markDownPipeline = new Markdig.MarkdownPipelineBuilder().UseAdvancedExtensions().Build();

            if (BlogDetail != null)
            {
                BlogDetail.BlogText = Markdig.Markdown.ToHtml(BlogDetail.BlogText, markDownPipeline);
            }

            return(Page());
        }
Beispiel #16
0
 /// <summary>
 /// Uses the bootstrap extension.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseBootstrap(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <BootstrapExtension>();
     return(pipeline);
 }
Beispiel #17
0
        /// <summary>
        /// Configures the pipeline using a string that defines the extensions to activate.
        /// </summary>
        /// <param name="pipeline">The pipeline (e.g: advanced for <see cref="UseAdvancedExtensions"/>, pipetables+gridtables for <see cref="UsePipeTables"/> and <see cref="UseGridTables"/></param>
        /// <param name="extensions">The extensions to activate as a string</param>
        /// <returns>The modified pipeline</returns>
        public static MarkdownPipelineBuilder Configure(this MarkdownPipelineBuilder pipeline, string extensions)
        {
            if (extensions == null)
            {
                return(pipeline);
            }

            // TODO: the extension string should come from the extension itself instead of this hardcoded switch case.

            foreach (var extension in extensions.Split(new[] { '+' }, StringSplitOptions.RemoveEmptyEntries))
            {
                switch (extension.ToLowerInvariant())
                {
                case "common":
                    break;

                case "advanced":
                    pipeline.UseAdvancedExtensions();
                    break;

                case "pipetables":
                    pipeline.UsePipeTables();
                    break;

                case "emphasisextras":
                    pipeline.UseEmphasisExtras();
                    break;

                case "listextras":
                    pipeline.UseListExtras();
                    break;

                case "hardlinebreak":
                    pipeline.UseSoftlineBreakAsHardlineBreak();
                    break;

                case "footnotes":
                    pipeline.UseFootnotes();
                    break;

                case "footers":
                    pipeline.UseFooters();
                    break;

                case "citations":
                    pipeline.UseCitations();
                    break;

                case "attributes":
                    pipeline.UseGenericAttributes();
                    break;

                case "gridtables":
                    pipeline.UseGridTables();
                    break;

                case "abbreviations":
                    pipeline.UseAbbreviations();
                    break;

                case "emojis":
                    pipeline.UseEmojiAndSmiley();
                    break;

                case "definitionlists":
                    pipeline.UseDefinitionLists();
                    break;

                case "customcontainers":
                    pipeline.UseCustomContainers();
                    break;

                case "figures":
                    pipeline.UseFigures();
                    break;

                case "mathematics":
                    pipeline.UseMathematics();
                    break;

                case "bootstrap":
                    pipeline.UseBootstrap();
                    break;

                case "medialinks":
                    pipeline.UseMediaLinks();
                    break;

                case "smartypants":
                    pipeline.UseSmartyPants();
                    break;

                case "autoidentifiers":
                    pipeline.UseAutoIdentifiers();
                    break;

                case "tasklists":
                    pipeline.UseTaskLists();
                    break;

                case "diagrams":
                    pipeline.UseDiagrams();
                    break;

                case "nofollowlinks":
                    pipeline.UseNoFollowLinks();
                    break;

                case "nohtml":
                    pipeline.DisableHtml();
                    break;

                case "yaml":
                    pipeline.UseYamlFrontMatter();
                    break;

                case "nonascii-noescape":
                    pipeline.UseNonAsciiNoEscape();
                    break;

                case "autolinks":
                    pipeline.UseAutoLinks();
                    break;

                default:
                    throw new ArgumentException($"Invalid extension `{extension}` from `{extensions}`", nameof(extensions));
                }
            }
            return(pipeline);
        }
Beispiel #18
0
 /// <summary>
 /// Configures the string to be used for line-endings, when writing.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <param name="newLine">The string to be used for line-endings.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder ConfigureNewLine(this MarkdownPipelineBuilder pipeline, string newLine)
 {
     pipeline.Use(new ConfigureNewLineExtension(newLine));
     return(pipeline);
 }
Beispiel #19
0
 /// <summary>
 /// Adds the specified extension instance to the extensions collection.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <param name="extension">The instance of the extension to be added.</param>
 /// <typeparam name="TExtension">The type of the extension.</typeparam>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder Use <TExtension>(this MarkdownPipelineBuilder pipeline, TExtension extension) where TExtension : class, IMarkdownExtension
 {
     pipeline.Extensions.AddIfNotAlready(extension);
     return(pipeline);
 }
Beispiel #20
0
 /// <summary>
 /// Uses this extension to disable URI escape with % characters for non-US-ASCII characters in order to workaround a bug under IE/Edge with local file links containing non US-ASCII chars. DO NOT USE OTHERWISE.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseNonAsciiNoEscape(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <NonAsciiNoEscapeExtension>();
     return(pipeline);
 }
Beispiel #21
0
 /// <summary>
 /// Uses this extension to enable autolinks from text `http://`, `https://`, `ftp://`, `mailto:`, `www.xxx.yyy`
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <param name="options">The options.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseAutoLinks(this MarkdownPipelineBuilder pipeline, AutoLinkOptions options = null)
 {
     pipeline.Extensions.ReplaceOrAdd <AutoLinkExtension>(new AutoLinkExtension(options));
     return(pipeline);
 }
Beispiel #22
0
 /// <summary>
 /// Uses pragma lines to output span with an id containing the line number (pragma-line#line_number_zero_based`)
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UsePragmaLines(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <PragmaLineExtension>();
     return(pipeline);
 }
Beispiel #23
0
 /// <summary>
 /// Uses YAML frontmatter extension that will parse a YAML frontmatter into the MarkdownDocument. Note that they are not rendered by any default HTML renderer.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseYamlFrontMatter(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <YamlFrontMatterExtension>();
     return(pipeline);
 }
Beispiel #24
0
 /// <summary>
 /// Uses the footnotes extension.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseFootnotes(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <FootnoteExtension>();
     return(pipeline);
 }
Beispiel #25
0
 /// <summary>
 /// Uses the softline break as hardline break extension
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseSoftlineBreakAsHardlineBreak(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <SoftlineBreakAsHardlineExtension>();
     return(pipeline);
 }
Beispiel #26
0
 /// <summary>
 /// Uses the cite extension.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseCitations(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <CitationExtension>();
     return(pipeline);
 }
Beispiel #27
0
 /// <summary>
 /// Uses the grid table extension.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseGridTables(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <GridTableExtension>();
     return(pipeline);
 }
Beispiel #28
0
 /// <summary>
 /// Uses the definition lists extension.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseDefinitionLists(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <DefinitionListExtension>();
     return(pipeline);
 }
Beispiel #29
0
 /// <summary>
 /// Uses precise source code location (useful for syntax highlighting).
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UsePreciseSourceLocation(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.PreciseSourceLocation = true;
     return(pipeline);
 }
Beispiel #30
0
 /// <summary>
 /// Uses the custom container extension.
 /// </summary>
 /// <param name="pipeline">The pipeline.</param>
 /// <returns>The modified pipeline</returns>
 public static MarkdownPipelineBuilder UseCustomContainers(this MarkdownPipelineBuilder pipeline)
 {
     pipeline.Extensions.AddIfNotAlready <CustomContainerExtension>();
     return(pipeline);
 }