Ejemplo n.º 1
0
    private void buttonEditMarkdown_Click(object sender, EventArgs e)
    {
        if (htmlDescription.Visible)
        {
            var config = new ReverseMarkdown.Config
            {
                UnknownTags       = ReverseMarkdown.Config.UnknownTagsOption.PassThrough, // Include the unknown tag completely in the result (default as well)
                GithubFlavored    = true,                                                 // generate GitHub flavoured markdown, supported for BR, PRE and table tags
                RemoveComments    = false,                                                // will ignore all comments
                SmartHrefHandling = true                                                  // remove markdown output for links where appropriate
            };
            var    converter = new ReverseMarkdown.Converter(config);
            string html      = htmlDescription.BodyHtml;
            string result    = converter.Convert(html);
            textDescription.Text = result;
        }
        else if (webView2.Visible)
        {
            textDescription.Text = webView2.TextUrl;
        }

        _com.Model.ContentType = "markdown";

        EnableMarkdownView();
    }
Ejemplo n.º 2
0
        /// <summary>
        /// 将html转换为markdown
        /// </summary>
        /// <param name="source">待转换的html代码</param>
        /// <returns>生成的markdown代码</returns>
        public static string ConvertHtmlToMarkdown(string source)
        {
            if (string.IsNullOrEmpty(source))
            {
                return("");
            }



            var config = new ReverseMarkdown.Config
            {
                UnknownTags = Config.UnknownTagsOption.Bypass,
                // generate GitHub flavoured markdown, supported for BR, PRE and table tags
                GithubFlavored = false,
                // will ignore all comments
                RemoveComments = true,
                // remove markdown output for links where appropriate
                SmartHrefHandling = true
            };

            var converter = new ReverseMarkdown.Converter(config);
            var markdown  = converter.Convert(ClearHtml(source));

            return(markdown);
        }
Ejemplo n.º 3
0
        public Converter(Config config)
        {
            this._config = config;

            foreach (Type ctype in System.Reflection.Assembly.GetExecutingAssembly().GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IConverter)) && !t.IsAbstract))
            {
                Activator.CreateInstance(ctype, this);
            }
        }
Ejemplo n.º 4
0
    public void UsageWithConfig()
    {
        #region UsageWithConfig

        var config = new ReverseMarkdown.Config
        {
            // Include the unknown tag completely in the result (default as well)
            UnknownTags = Config.UnknownTagsOption.PassThrough,
            // generate GitHub flavoured markdown, supported for BR, PRE and table tags
            GithubFlavored = true,
            // will ignore all comments
            RemoveComments = true,
            // remove markdown output for links where appropriate
            SmartHrefHandling = true
        };

        var converter = new ReverseMarkdown.Converter(config);

        #endregion
    }