Exemplo n.º 1
0
        private static string ExtractSummary(string articleText, int paragraphCount, bool skipRule)
        {
            string summary = string.Empty;
            int    index   = 0;

            //Skip past first HR
            if (skipRule)
            {
                var hrMatch = Regexes.Hr.Match(articleText);
                if (hrMatch != null)
                {
                    index += hrMatch.Index + hrMatch.Length;
                }
            }

            //Skip past the first paragraph
            for (int i = 0; i <= paragraphCount; i++)
            {
                var pMatch = Regexes.P.Match(articleText.Substring(index));
                if (pMatch == null)
                {
                    break;
                }

                index += pMatch.Index;
                if (i < paragraphCount)
                {
                    index += pMatch.Length;
                }
            }

            summary += (index == 0) ? articleText : articleText.Substring(0, index);

            return(HtmlCleaner.CloseTags(summary));
        }