Exemple #1
0
 public static Element CreateElement(CodeRenderer.MarkupStructure.Tag tag, Element ParentElement)
 {
     Element element;
     switch (tag.name)
     {
         case "br":
             element = new NewLine(ParentElement);
             break;
         case "img":
             element = new Image(tag.Attributes,ParentElement);
             break;
         case "body":
             element = new Body(tag.Attributes,ParentElement);
             break;
         case "div":
             element = new Section(tag.Attributes,ParentElement);
             break;
         case "p":
             element = new Paragraph(tag.Attributes,ParentElement);
             break;
         default:
             throw new NotImplementedException();
             break;
     }
     return element;
 }
Exemple #2
0
        protected static Element RenderTag(CodeRenderer.MarkupStructure.Tag tag,Element ParentElement)
        {
            Element element = Element.CreateElement(tag,ParentElement);
            bool isPrevText = false;
            switch (element.type)
            {
                case ElementType.DIVISION:

                    Section division = (Section)element;
                    foreach(CodeRenderer.MarkupStructure.Token token in tag.Content)
                        if (token is CodeRenderer.MarkupStructure.Text)
                        //if (token.type == CodeRenderer.MarkupStructure.TokenType.TEXT)
                        {
                            if (isPrevText)
                                division.Add(new Text(" ",division));
                            division.Add(new Text((CodeRenderer.MarkupStructure.Text)token,division));
                            isPrevText = true;
                        }
                        else
                        {
                            division.Add(RenderTag((CodeRenderer.MarkupStructure.Tag)token,division));
                            isPrevText = false;
                        }

                    break;
                default:
                    //throw new NotImplementedException();
                    break;
            }
            return element;
        }
Exemple #3
0
 protected static Head RenderHead(CodeRenderer.MarkupStructure.Tag HeadTag,Element ParentElement)
 {
     Head Head = new Head(HeadTag.Attributes,ParentElement);
     foreach (CodeRenderer.MarkupStructure.Tag tag in HeadTag.Content)
         if (tag.name == "title")
             Head.Title = RenderTitle(tag);
         else throw new NotImplementedException();
     return Head;
 }
Exemple #4
0
 public Attributes(List<CodeRenderer.MarkupStructure.TagAttribute> Attributes, Element ParentElement = null)
 {
     Map = new Dictionary<string, string>();
     if (ParentElement != null)
         Map = new Dictionary<string,string>(ParentElement.Attributes.Map);
     if (Attributes != null)
     {
         foreach (CodeRenderer.MarkupStructure.TagAttribute Attribute in Attributes)
         {
             if (Map.ContainsKey(Attribute.Key))
                 Map[Attribute.Key] = Attribute.Value;
             else Map.Add(Attribute.Key, Attribute.Value);
         }
     }
 }
Exemple #5
0
 public Style(Attributes Attributes, Element ParentElement)
 {
     this.Map = new Dictionary<string, string>();
     if (ParentElement != null)
         this.Map = new Dictionary<string,string>(ParentElement.Style.Map);
     if (Attributes.Map.ContainsKey("style"))
     {
         List<KeyValuePair<string, string>> StyleList = ParseStyle(Attributes.Map["style"]);
         foreach (KeyValuePair<string, string> StyleToken in StyleList)
         {
             if (Map.ContainsKey(StyleToken.Key))
                 Map[StyleToken.Key] = StyleToken.Value;
             else Map.Add(StyleToken.Key, StyleToken.Value);
         }
     }
 }
Exemple #6
0
 public Text(CodeRenderer.MarkupStructure.Text text, Element ParentElement)
     : base(null, ParentElement)
 {
     this.type = ElementType.TEXT;
     this.text = HtmlToText(text.text);
 }
Exemple #7
0
 public Element(List<CodeRenderer.MarkupStructure.TagAttribute> Attributes, Element ParentElement)
 {
     this.ParentElement = ParentElement;
     this.Attributes = new Attributes(Attributes, ParentElement);
     this.Style = new Style(this.Attributes, ParentElement);
 }
Exemple #8
0
 public virtual void Add(Element element)
 {
     Elements.Add(element);
 }
Exemple #9
0
 public Text(string text, Element ParentElement)
     : base(null, ParentElement)
 {
     this.type = ElementType.TEXT;
     this.text = text;
 }
Exemple #10
0
 public Section(List<CodeRenderer.MarkupStructure.TagAttribute> Attributes,Element ParentElement)
     : base(Attributes,ParentElement)
 {
     this.type = ElementType.DIVISION;
     this.Elements = new List<Element>();
 }
Exemple #11
0
 public Body(List<CodeRenderer.MarkupStructure.TagAttribute> Attributes,Element ParentElement)
     : base(Attributes,ParentElement)
 {
 }
Exemple #12
0
 public override void Add(Element element)
 {
     base.Add(element);
 }
Exemple #13
0
 public NewLine(Element ParentElement)
 {
     this.type = ElementType.NEWLINE;
 }
Exemple #14
0
 public Image(List<CodeRenderer.MarkupStructure.TagAttribute> Attributes, Element ParentElement)
     : base(Attributes, ParentElement)
 {
     foreach (CodeRenderer.MarkupStructure.TagAttribute attribute in Attributes)
     {
         switch (attribute.Key)
         {
             case "src":
                 this.Path = attribute.Value;
                 break;
             case "alt":
                 this.Alt = attribute.Value;
                 break;
             default:
                 throw new NotImplementedException();
         }
     }
 }