Exemple #1
0
        public override string Convert(HtmlNode node)
        {
            string content;

            do
            {
                if (node.ChildNodes.Count == 1 && node.FirstChild.Name == "div")
                {
                    node = node.FirstChild;
                    continue;
                }

                content = TreatChildren(node);
                break;
            } while (true);

            var blockTags = new List <string>
            {
                "pre",
                "p",
                "ol",
                "oi",
                "table"
            };

            // if there is a block child then ignore adding the newlines for div
            if ((node.ChildNodes.Count == 1 && blockTags.Contains(node.FirstChild.Name)))
            {
                return(content);
            }

            return($"{(Td.FirstNodeWithinCell(node) ? "" : Environment.NewLine)}{content}{(Td.LastNodeWithinCell(node) ? "" : Environment.NewLine)}");
        }
        private static string IndentationFor(HtmlNode node)
        {
            string parentName = node.ParentNode.Name.ToLowerInvariant();

            // If p follows a list item, add newline and indent it
            var  length       = node.Ancestors("ol").Count() + node.Ancestors("ul").Count();
            bool parentIsList = parentName == "li" || parentName == "ol" || parentName == "ul";

            if (parentIsList && node.ParentNode.FirstChild != node)
            {
                return(Environment.NewLine + (new string(' ', length * 4)));
            }

            // If p is at the start of a table cell, no leading newline
            return(Td.FirstNodeWithinCell(node) ? "" : Environment.NewLine);
        }
 public override string Convert(HtmlNode node)
 {
     return($"{(Td.FirstNodeWithinCell(node) ? "" : Environment.NewLine)}{TreatChildren(node).Trim()}{(Td.LastNodeWithinCell(node) ? "" : Environment.NewLine)}");
 }