Ejemplo n.º 1
0
        private static FMDItem Match(string line)
        {
            FMDItem item = new FMDItem();

            item.Url = _patterns[EPattern.EUrl].Match(line);
            item.H1  = _patterns[EPattern.EH1].Match(line);

            if (!string.IsNullOrEmpty(item.Url) && !string.IsNullOrEmpty(item.H1))
            {
                item.H1 = _patterns[EPattern.EUrlH].Match(line);
            }

            item.H2          = _patterns[EPattern.EH2].Match(line);
            item.Description = _patterns[EPattern.EDec1].Match(line);
            return(item);
        }
Ejemplo n.º 2
0
        public static List <FMDItem> ReadMd(string fmd, string floder)
        {
            MdFloder = floder;
            fmd      = fmd.Replace(@"\#", "#");
            List <FMDItem> infos = new List <FMDItem>();

            string[] lines = fmd.Split(new[] { "\r\n" }, StringSplitOptions.None);

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                if (!string.IsNullOrEmpty(line) && !line.StartsWith("//"))
                {
                    TempItem = new FMDItem();

                    TempItem.Url = _patterns[EPattern.EUrl].Match(line);
                    bool isHasUrl = !string.IsNullOrEmpty(TempItem.Url);

                    string h1 = _patterns[EPattern.EH1].Match(line);

                    if (!string.IsNullOrEmpty(h1))
                    {
                        if (isHasUrl)
                        {
                            TempItem.H1 = _patterns[EPattern.EUrlH].Match(line);
                        }
                        else
                        {
                            TempItem.H1 = h1;
                        }
                    }

                    string imgUrl = _patterns[EPattern.EImgUrl].Match(line);
                    if (imgUrl != null)
                    {
                        TempItem.H1      = "===";
                        TempItem.IsImage = true;
                        TempItem.Url     = imgUrl;
                    }


                    //RemapURL();

                    if (string.IsNullOrEmpty(TempItem.H1))
                    {
                        if (isHasUrl)
                        {
                            TempItem.H2 = _patterns[EPattern.EUrlH].Match(line);
                        }
                        else
                        {
                            TempItem.H2 = _patterns[EPattern.EH2].Match(line);
                        }

                        bool isNext = true;
                        int  index  = i + 1;
                        while (isNext)
                        {
                            if (index < lines.Length)
                            {
                                string dec2 = _patterns[EPattern.EDec1].Match(lines[index]);
                                if (!string.IsNullOrEmpty(dec2))
                                {
                                    if (string.IsNullOrEmpty(TempItem.Description))
                                    {
                                        TempItem.Description = $"  {dec2}";
                                    }
                                    else
                                    {
                                        TempItem.Description = $"{TempItem.Description}\r\n  {dec2}";
                                    }

                                    index++;
                                }
                                else
                                {
                                    isNext = false;
                                }
                            }
                            else
                            {
                                isNext = false;
                            }
                        }

                        i = index - 1;
                    }

                    if (!TempItem.IsNull())
                    {
                        TempItem.Description = ReferenceUtil.ParseCustomFuhao(TempItem.Description);
                        infos.Add(TempItem);
                    }
                }
            }

            return(infos);
        }