Пример #1
0
        public static Article Parse(string str)
        {
            List <IArticleItem> items = new List <IArticleItem>();

            foreach (var n in str.Split("\n"))
            {
                IArticleItem item = ParseLine(n);
                if (item != null)
                {
                    items.Add(item);
                }
            }
            return(new Article()
            {
                Items = items.ToArray()
            });
        }
Пример #2
0
        private static ParagraphV ParseArticleItem(IArticleItem item)
        {
            string PhType = "";
            string text   = null;

            if (item is Bullet)
            {
                PhType = "Bullet";
                text   = (item as Bullet).Text;
            }
            else if (item is EmptyLine)
            {
                PhType = "EmptyLine";
            }
            else if (item is Example)
            {
                PhType = "Example";
            }
            else if (item is Image)
            {
                PhType = "Image";
                text   = (item as Image).FileName;
            }
            else if (item is Code)
            {
                PhType = "Code";
                text   = (item as Code).Text;
            }
            else if (item is Paragraph)
            {
                PhType = "Paragraph";
                text   = (item as Paragraph).Text;
            }

            return(new ParagraphV()
            {
                PhType = PhType, Text = text
            });
        }
Пример #3
0
        private ParagraphVM ParseArticleItem(IArticleItem item)
        {
            bool   hasBullet = false;
            bool   hasBorder = false;
            string text      = null;

            if (item is Bullet)
            {
                hasBullet = true;
                text      = (item as Bullet).Text;
            }
            else if (item is EmptyLine)
            {
                text = "<br/>";
            }
            else if (item is Example)
            {
                text = "<b>例如:</b>";
            }
            else if (item is Image)
            {
                text = string.Format("<img src=\"/Repository/Docs/Resources/{0}\"/>", (item as Image).FileName);
            }
            else if (item is Code)
            {
                hasBorder = true;
                text      = string.Join("<br/>", (item as Code).Text.Split(new string[] { "\r\n" }, StringSplitOptions.None));
            }
            else if (item is Paragraph)
            {
                text = (item as Paragraph).Text;
            }


            return(new ParagraphVM()
            {
                HasBullet = hasBullet, HasBorder = hasBorder, Text = text
            });
        }
Пример #4
0
        public Article Parse(string filePath)
        {
            List <IArticleItem> items = new List <IArticleItem>();

            using (StreamReader file = new StreamReader(filePath, System.Text.Encoding.UTF8))
            {
                while (!file.EndOfStream)
                {
                    IArticleItem item = ParseLine(file.ReadLine());
                    if (item != null)
                    {
                        items.Add(item);
                    }
                }
            }


            return(new Article()
            {
                Items = items.ToArray()
            });
        }