Пример #1
0
        public static Markdown Parse(string text, out int length)
        {
            var lines = text.Split('\n');
            var temp  = lines.FirstOrDefault() ?? "";

            length = temp.Length + 1;
            Markdown result = new Markdown();

            result.Children = MarkdownRaw.Parse(temp, true).Children;
            return(result);
        }
Пример #2
0
        private static List <MarkdownRaw> FilterNewLine(List <MarkdownRaw> children)
        {
            List <MarkdownRaw> result = new List <MarkdownRaw>();

            for (int i = 0; i < children.Count; i++)
            {
                if (children[i].GetType() != typeof(Markdown) ||
                    i == result.Count - 1)
                {
                    result.Add(children[i]);
                    continue;
                }
                MarkdownRaw last  = children[i];
                var         lines = children.Skip(i + 1).TakeWhile(
                    x => {
                    var check = last.GetType() == typeof(Markdown) &&
                                ((Markdown)last).Children.Count != 0;
                    last = x;
                    return(check);
                }).ToList();
                lines.Insert(0, children[i]);
                i += lines.Count() - 1;

                if (lines.Count > 1 && lines.Last().OuterMarkdown.Length == 0)
                {
                    lines.RemoveAt(lines.Count - 1);
                }
                if (lines.Count > 1)
                {
                    result.Add(new Markdown()
                    {
                        Children = lines
                    });
                }
                else
                {
                    result.Add(lines.First());
                }
            }

            return(result);
        }