示例#1
0
文件: Element.cs 项目: kokudori/Y3
        public static Generator ToHTML5(this Element self, IReadOnlyCollection<ITag> inners, Generator generator)
        {
            var tags = new Generator(generator.Indention + 1);
            inners.ForEach(x => x.ToHTML5(tags));
            var annotations = String.Concat(self.Annotations.Select(x => x.ToHTML5()));

            var isText = inners.Count == 1 && inners.Single() is Text;
            if (!inners.Any())
            {
                if (self.Name.ToLower() == "script")
                    generator.Write("<{0}{1}></{0}>", self.Name, annotations);
                else
                    generator.Write("<{0}{1} />", self.Name, annotations);
            }
            else if (isText)
            {
                generator.Write("<{0}{1}>{2}</{0}>", self.Name, annotations, tags.Generate().Trim());
            }
            else
            {
                generator.Write("<{0}{1}>{2}", self.Name, annotations, tags.Generate());
                generator.Write("</{0}>", self.Name);
            }
            return generator;
        }
示例#2
0
文件: Y3.cs 项目: kokudori/Y3
 public static string ToHTML5(this Ast self)
 {
     var generator = new Generator();
     self.DocType.ToHTML5(generator);
     self.Root.ToHTML5(generator);
     return generator.Generate().Trim();
 }