Exemplo n.º 1
0
 private void AssertEqual(InlineElement element)
 {
     Assert.AreEqual(Content, element.Type);
     if (element is InlineText text)
     {
         Assert.AreEqual(0, Children?.Length ?? 0);
         Assert.AreEqual(Text, text.Content);
     }
     else if (element is CodeSpan code)
     {
         Assert.AreEqual(0, Children?.Length ?? 0);
         Assert.AreEqual(Text, code.Code);
     }
     else if (element is InlineHtml html)
     {
         Assert.AreEqual(0, Children?.Length ?? 0);
         Assert.AreEqual(Text, html.Content);
     }
     else if (element is ContainerInlineElement container)
     {
         Assert.AreEqual(Children.Length, container.Children.Length);
         for (int i = 0; i < Children.Length; i++)
         {
             Children[i].AssertEqual(container.Children[i]);
         }
     }
 }
Exemplo n.º 2
0
        protected IRenderable InstantiateTag(ITag tag, ArgumentList arguments)
        {
            IRenderable statement;

            if (tag is IInlineTag)
            {
                statement = new InlineElement(tag)
                {
                    Arguments = arguments
                };
            }
            else if (tag is IConditionalTag)
            {
                statement = new ConditionalElement(tag)
                {
                    Arguments = arguments
                };
            }
            else if (tag is IBlockTag)
            {
                statement = new BlockElement(tag)
                {
                    Arguments = arguments
                };
            }
            else
            {
                throw new Exception(String.Format(@"Internal compiler error. Unknown tag type {0}", tag));
            }

            // TODO: Validation of parameters.

            return(statement);
        }
Exemplo n.º 3
0
    public void Append(IInlineContainer parent, InlineElement inlineElement)
    {
        if (inlineElement.Parent != null)
        {
            inlineElement.Paragraph?.Invalidate(Paragraph.InvalidationFlags.TextFlow);
            inlineElement.Parent?.RemoveContent(inlineElement);
        }

        _children ??= new List <InlineElement>();
        _children.Add(inlineElement);

        inlineElement.Parent = parent;
        inlineElement.Paragraph?.Invalidate(Paragraph.InvalidationFlags.TextFlow);
    }
Exemplo n.º 4
0
    public void Remove(IInlineContainer parent, InlineElement inlineElement)
    {
        if (inlineElement.Parent != parent)
        {
            throw new ArgumentException("Element is not in this parent");
        }

        inlineElement.Paragraph?.Invalidate(Paragraph.InvalidationFlags.TextFlow);

        if (_children != null && _children.Remove(inlineElement))
        {
            if (_children.Count == 0)
            {
                _children = null;
            }
        }

        inlineElement.Parent = null;
    }
Exemplo n.º 5
0
        public static Inline GetWindowsInline(this InlineElement inline)
        {
            switch (inline)
            {
            case TextRun r:
                return(new Run(r.Text)
                {
                    FontWeight = r.IsBold ? FontWeights.Bold : FontWeights.Regular,
                    FontStyle = r.IsItalic ? FontStyles.Italic : FontStyles.Normal
                });

            case Symbol s:
                return(new InlineUIContainer(new Image
                {
                    Width = 12,
                    Height = 12,
                    Source = ((DiceIcons)Enum.Parse(typeof(DiceIcons), s.Name)).GetImageSource()
                }));

            default:
                throw new ArgumentException("Unknown InlineElement.");
            }
        }
Exemplo n.º 6
0
 public void RemoveContent(InlineElement inlineElement) => _children.Remove(this, inlineElement);
Exemplo n.º 7
0
 public void AppendContent(InlineElement inlineElement) => _children.Append(this, inlineElement);
Exemplo n.º 8
0
        /// <summary>
        /// Parses XML for a set of block elements.
        /// </summary>
        /// <param name="Xml">XML representation</param>
        /// <returns>Array of block elements</returns>
        public static BlockElement[] Parse(XmlElement Xml)
        {
            List <BlockElement> Result = new List <BlockElement>();

            foreach (XmlNode N in Xml.ChildNodes)
            {
                if (N is XmlElement E)
                {
                    switch (E.LocalName)
                    {
                    case "paragraph":
                        Result.Add(new Paragraph()
                        {
                            Elements = InlineElement.Parse(E)
                        });
                        break;

                    case "section":
                        Section Section = new Section();

                        foreach (XmlNode N2 in E.ChildNodes)
                        {
                            if (N2 is XmlElement E2)
                            {
                                switch (E2.LocalName)
                                {
                                case "header":
                                    Section.Header = InlineElement.Parse(E2);
                                    break;

                                case "body":
                                    Section.Body = BlockElement.Parse(E2);
                                    break;
                                }
                            }
                        }

                        Result.Add(Section);
                        break;

                    case "bulletItems":
                        List <Item> Items = new List <Item>();

                        foreach (XmlNode N2 in E.ChildNodes)
                        {
                            if (N2 is XmlElement E2 && E2.LocalName == "item")
                            {
                                Items.Add(new Item()
                                {
                                    Elements = InlineElement.Parse(E2)
                                });
                            }
                        }

                        Result.Add(new BulletList()
                        {
                            Items = Items.ToArray()
                        });
                        break;

                    case "numberedItems":
                        Items = new List <Item>();

                        foreach (XmlNode N2 in E.ChildNodes)
                        {
                            if (N2 is XmlElement E2 && E2.LocalName == "item")
                            {
                                Items.Add(new Item()
                                {
                                    Elements = InlineElement.Parse(E2)
                                });
                            }
                        }

                        Result.Add(new NumberedList()
                        {
                            Items = Items.ToArray()
                        });
                        break;

                    default:
                        return(null);
                    }
                }
            }

            return(Result.ToArray());
        }
Exemplo n.º 9
0
 public WidgetText(InlineElement content, string styleId) : this()
 {
     Content = content;
     AddStyle(styleId);
 }
Exemplo n.º 10
0
 public void SetHelpText(InlineElement content)
 {
     _textLabel.Content = content;
 }