Пример #1
0
        IEnumerable <FlatItem> FlattenList(MarkdownParagraph.ListBlock md, int level)
        {
            var isOrdered = md.Item1.IsOrdered;
            var items     = md.Item2;

            foreach (var mdpars in items)
            {
                var isFirstParagraph = true;
                foreach (var mdp in mdpars)
                {
                    var wasFirstParagraph = isFirstParagraph; isFirstParagraph = false;

                    if (mdp.IsParagraph || mdp.IsSpan)
                    {
                        var mdp1     = mdp;
                        var buglevel = BugWorkaroundIndent(ref mdp1, level);
                        yield return(new FlatItem {
                            Level = buglevel, HasBullet = wasFirstParagraph, IsBulletOrdered = isOrdered, Paragraph = mdp1
                        });
                    }
                    else if (mdp.IsQuotedBlock || mdp.IsCodeBlock)
                    {
                        yield return(new FlatItem {
                            Level = level, HasBullet = false, IsBulletOrdered = isOrdered, Paragraph = mdp
                        });
                    }
                    else if (mdp.IsListBlock)
                    {
                        foreach (var subitem in FlattenList(mdp as MarkdownParagraph.ListBlock, level + 1))
                        {
                            yield return(subitem);
                        }
                    }
                    else if (mdp.IsTableBlock)
                    {
                        yield return(new FlatItem {
                            Level = level, HasBullet = false, IsBulletOrdered = isOrdered, Paragraph = mdp
                        });
                    }
                    else
                    {
                        throw new NotImplementedException("nothing fancy allowed in lists");
                    }
                }
            }
        }
Пример #2
0
        IEnumerable <FlatItem> FlattenList(MarkdownParagraph.ListBlock md, int level)
        {
            var isOrdered = md.kind.IsOrdered;
            var items     = md.items;

            foreach (var mdpars in items)
            {
                var isFirstParagraph = true;
                foreach (var mdp in mdpars)
                {
                    var wasFirstParagraph = isFirstParagraph; isFirstParagraph = false;

                    if (mdp.IsParagraph || mdp.IsSpan)
                    {
                        var mdp1     = mdp;
                        var buglevel = BugWorkaroundIndent(ref mdp1, level);
                        yield return(new FlatItem(buglevel, wasFirstParagraph, isOrdered, mdp1));
                    }
                    else if (mdp.IsQuotedBlock || mdp.IsCodeBlock)
                    {
                        yield return(new FlatItem(level, false, isOrdered, mdp));
                    }
                    else if (mdp.IsListBlock)
                    {
                        foreach (var subitem in FlattenList(mdp as MarkdownParagraph.ListBlock, level + 1))
                        {
                            yield return(subitem);
                        }
                    }
                    else if (mdp.IsTableBlock)
                    {
                        yield return(new FlatItem(level, false, isOrdered, mdp));
                    }
                    else
                    {
                        reporter.Error("MD14", $"nothing fancy allowed in lists - specifically not '{mdp.GetType().Name}'");
                    }
                }
            }
        }
Пример #3
0
        IEnumerable <FlatItem> FlattenList(MarkdownParagraph.ListBlock md)
        {
            var flat      = FlattenList(md, 0).ToList();
            var isOrdered = new Dictionary <int, bool>();

            foreach (var item in flat)
            {
                var level         = item.Level;
                var isItemOrdered = item.IsBulletOrdered;
                var content       = item.Paragraph;
                if (isOrdered.ContainsKey(level) && isOrdered[level] != isItemOrdered)
                {
                    throw new NotImplementedException("List can't mix ordered and unordered items at same level");
                }
                isOrdered[level] = isItemOrdered;
                if (level > 3)
                {
                    throw new Exception("Can't have more than 4 levels in a list");
                }
            }
            return(flat);
        }