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; }
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; }
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; }
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); } } }
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); } } }
public Text(CodeRenderer.MarkupStructure.Text text, Element ParentElement) : base(null, ParentElement) { this.type = ElementType.TEXT; this.text = HtmlToText(text.text); }
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); }
public virtual void Add(Element element) { Elements.Add(element); }
public Text(string text, Element ParentElement) : base(null, ParentElement) { this.type = ElementType.TEXT; this.text = text; }
public Section(List<CodeRenderer.MarkupStructure.TagAttribute> Attributes,Element ParentElement) : base(Attributes,ParentElement) { this.type = ElementType.DIVISION; this.Elements = new List<Element>(); }
public Body(List<CodeRenderer.MarkupStructure.TagAttribute> Attributes,Element ParentElement) : base(Attributes,ParentElement) { }
public override void Add(Element element) { base.Add(element); }
public NewLine(Element ParentElement) { this.type = ElementType.NEWLINE; }
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(); } } }