Ejemplo n.º 1
0
        public Tuple <bool, IElement> Parse(int parentIndentation, int unit, IParent last)
        {
            var definitionListItems = DefinitionListItem.Parse(this, last);

            if (definitionListItems.Count > 0)
            {
                var definitionList = last.Parent as DefinitionList;
                if (last.Parent is DefinitionListItem)
                {
                    definitionList = (DefinitionList)last.Parent.Parent;
                }

                if (definitionList != null)
                {
                    foreach (var item in definitionListItems)
                    {
                        definitionList.Add(item);
                    }

                    return(new Tuple <bool, IElement>(true, definitionListItems.Last()));
                }

                definitionList        = new DefinitionList(definitionListItems);
                definitionList.Parent = last;
                last.Add(definitionList);
                var listItem = definitionListItems.Last();
                return(new Tuple <bool, IElement>(true, listItem));
            }

            IElement newElement = this;

            if (Indentation > parentIndentation || TextAreas[0].IsQuoted)
            {
                var lastElement = last as IElement;
                var lastText    = lastElement?.TextAreas?.LastOrDefault()?.Content.Text.TrimEnd();
                if (lastText != null && lastText.EndsWith("::"))
                {
                    newElement = new LiteralBlock(TextAreas);
                    lastElement?.TextAreas.Last().Content.RemoveLiteral();
                }
                else
                {
                    var level = newElement.TextAreas[0].Indentation / unit;
                    while (level > 0)
                    {
                        newElement = new BlockQuote(level * unit, unit, newElement);
                        level--;
                    }
                }
            }

            return(new Tuple <bool, IElement>(false, newElement));
        }
Ejemplo n.º 2
0
        internal void FillAttribution()
        {
            for (var index = 1; index < Elements.Count; index++)
            {
                var item = Elements[index];
                if (item is Paragraph last)
                {
                    var text = last.TextAreas[0].Content.Text;
                    if (text.StartsWith("--") || text.StartsWith("\u2014"))
                    {
                        int  line          = 0;
                        int? indent        = null;
                        bool isAttribution = true;
                        for (var i = 0; i < last.TextAreas.Count; i++)
                        {
                            var info = last.TextAreas[i];
                            if (info.Content.Text.Last() == '\n')
                            {
                                if (line > 0)
                                {
                                    var next = i + 1;
                                    if (next == last.TextAreas.Count)
                                    {
                                        continue;
                                    }

                                    var indentation = last.TextAreas[next].Indentation;
                                    if (indent == null)
                                    {
                                        indent = indentation;
                                    }
                                    else
                                    {
                                        if (indentation != indent)
                                        {
                                            isAttribution = false;
                                            break;
                                        }
                                    }
                                }

                                line++;
                            }
                        }

                        if (isAttribution)
                        {
                            Attribution = new Attribution(last.TextAreas);
                            if (index < Elements.Count - 1)
                            {
                                var newItem = new BlockQuote(Indentation, _unit, Elements.Skip(index + 1).ToArray());
                                newItem.FillAttribution();
                                Parent.Add(newItem);
                                Elements = Elements.Take(index + 1).ToList();
                            }

                            Elements.Remove(last);
                        }
                    }
                }
            }
        }