Beispiel #1
0
        public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder)
        {
            var content = MarkdownVisitor.Process(node).Trim('\n', '\r');

            // TODO: figure out of this is a problem
            content = content.Replace("&lt;", "<").Replace("&gt;", ">");

            var useBlockFormat = content.IndexOf('\n') > 0;

            if (useBlockFormat)
            {
                // TODO: detect language
                var attClass = node.Attributes.GetValueOrDefault("class", "");
                var language = string.Empty;
                foreach (var att in attClass.Split(' '))
                {
                    if (att.StartsWith("lang:"))
                    {
                        language = att.Replace("lang:", "");
                        break;
                    }
                }

                bodyBuilder.AppendLine().Append("```");
                bodyBuilder.AppendLine(language);
                bodyBuilder.AppendLine(content);
                bodyBuilder.AppendLine("```");
            }
            else
            {
                bodyBuilder.Append("`").Append(content).Append("`");
            }

            return(false);
        }
        public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder)
        {
            var content = MarkdownVisitor.Process(node).Trim('\n', '\r', ' ');

            bodyBuilder.AppendLine().Append(">");

            content = content.Replace("\n", "\n>");

            bodyBuilder.AppendLine(content).AppendLine();

            return(false);
        }
        public override bool OpenNode(HtmlParser.Node node, StringBuilder bodyBuilder)
        {
            string content = string.Empty;

            switch (node.Name)
            {
            case "ul":
            case "ol":
                _lists.Push(node.Name);

                //if (_lists.Count == 1)
                {
                    bodyBuilder.AppendLine();
                }


                // this is a weird hack, but we're doing it because HTML is weird
                // but we only care about the li elements, and we treat the rest as problematic (non-existant)
                // and if we loose content, so be it...
                foreach (var child in node.Children)
                {
                    if (child.GetNameSafely() != "li")
                    {
                        Console.WriteLine("!! Content ignored: " + child.ToString());
                        continue;
                    }

                    content = MarkdownVisitor.Process(child).Trim('\r', '\n', ' ');

                    if (content.IndexOf('\n') >= 0)
                    {
                        // we need to add a \t at every new line
                        content = content.Replace("\n", "\n\t");
                    }

                    bodyBuilder.AppendFormat("{0} {1}", node.Name == "ul" ? "*" : "1.", content).AppendLine();
                }

                return(false);

            case "li":
                content = MarkdownVisitor.Process(node).Trim('\n', ' ');

                bodyBuilder.AppendFormat("{0} {1}", _lists.Peek() == "ul" ? "*" : "1.", content).AppendLine();
                return(false);
            }
            return(true);
        }