Exemplo n.º 1
0
 public string BuildText(XNode node, FodtStyle inheritStyle)
 {
     //if (node.NodeType != XmlNodeType.Text)
     //{
     //    Console.ForegroundColor = ConsoleColor.Red;
     //}
     //if (node.ToString().EndsWith("/>"))
     //{
     //    Console.ForegroundColor = ConsoleColor.Cyan;
     //}
     //Console.WriteLine(node);
     //Console.ForegroundColor = ConsoleColor.Yellow;
     //Console.WriteLine("--------------------------------------------------------");
     //Console.ResetColor();
     if (node.NodeType == XmlNodeType.Text)
     {
         return(inheritStyle.GetANSI() + this.BashEscapeString(node.ToString()) + inheritStyle.GetANSI());
     }
     else
     {
         if (node.ToString().EndsWith("/>"))
         {
             try
             {
                 System.Text.StringBuilder sb = new System.Text.StringBuilder();
                 sb.Append(' ', Int32.Parse(((XElement)node).Attributes().Where(x => x.Name.LocalName == "c").First().Value));
                 return /*inheritStyle.GetANSI() +*/ (sb.ToString() /*+inheritStyle.GetANSI()*/);
             }
             catch { }
         }
         else
         {
             string    ret    = inheritStyle.GetANSI();
             FodtStyle pStyle = new FodtStyle();
             try
             {
                 pStyle = GetStyleByName(((XElement)node).Attributes().Where(x => x.Name.LocalName == "style-name").First().Value);
             }
             catch { }
             int na = 0;
             foreach (var nodeNode in ((XElement)node).DescendantNodes())
             {
                 if (na > -1)
                 {
                     ret += BuildText(nodeNode, pStyle);
                 }
                 na++;
             }
             ret += inheritStyle.GetANSI();
         }
     }
     return("");
 }
Exemplo n.º 2
0
        public List <string> BuildANSI()
        {
            List <string> ret = new List <string>();
            XElement      moo = doc.Elements().Where(p => p.Name.LocalName == "document").First()
                                .Elements().Where(p => p.Name.LocalName == "body").First()
                                .Elements().Where(p => p.Name.LocalName == "text").First();

            foreach (XElement p in moo.Elements().Where(p => p.Name.LocalName == "p"))
            {
                FodtStyle pStyle = new FodtStyle();
                try
                {
                    pStyle = GetStyleByName(p.Attributes().Where(x => x.Name.LocalName == "style-name").First().Value);
                }
                catch { }
                string text = "";
                int    na   = 0;
                foreach (var node in p.DescendantNodes())
                {
                    if (na >= 0)
                    {
                        //if (node.NodeType != XmlNodeType.Text)
                        //{
                        //    Console.ForegroundColor = ConsoleColor.Red;
                        //}
                        //if (node.ToString().EndsWith("/>"))
                        //{
                        //    Console.ForegroundColor = ConsoleColor.Cyan;
                        //}
                        //Console.WriteLine(node);
                        //Console.ForegroundColor = ConsoleColor.Yellow;
                        //Console.WriteLine("--------------------------------------------------------");
                        //Console.ResetColor();
                        text += pStyle.GetANSI();
                        text += BuildText(node, pStyle);
                        text += pStyle.GetANSI();
                    }
                    na++;
                }
                //Console.WriteLine(text);


                //Console.WriteLine(pXml);
                //Console.WriteLine(pStyle);
                //Console.ForegroundColor = ConsoleColor.Green;
                //Console.WriteLine("////////////////////////////////////////////////////////////////////////////////////////////////////");
                //Console.ResetColor();
                ret.Add(text);
            }
            return(ret);
        }