protected override void OnText(Text text)
 {
     if (preserveLinebreaksDepth == 0)
     {
         string cleanText = newLine.Replace(text.ToString(), " ");
         if (cleanText.Length != text.Length)
             text = new Text(cleanText, 0, cleanText.Length);
     }
     base.OnText(text);
 }
        /// <summary>
        /// Truncate text.  maxCost is the cost available for the
        /// string you need to return.
        ///
        /// The default implementation uses CharCount() to calculate
        /// where to split, then attempts to split at a space if
        /// possible.
        /// </summary>
        public virtual string TruncateText(Text el, int maxCost)
        {
            if (maxCost == 0)
                return string.Empty;

            string str = el.ToString();

            // normalizes maxCost to a max char length
            int cost = 0;
            int max = -1;
            for (int i = 0; i < str.Length; i++)
            {
                if (cost >= maxCost)
                {
                    max = i;
                    break;
                }
                cost += CharCost(str[i]);
            }
            if (max == -1)
                return str;  // never hit the max

            // avoid splitting up HTML entities

            string trimmedAtWords = StringHelper.RestrictLengthAtWords(str, max);
            if (ElementCost(new Text(trimmedAtWords, 0, trimmedAtWords.Length)) <= maxCost)
            {
                // It is possible for RestrictLengthAtWords to return
                // strings that are longer than desired (if there are
                // no spaces).  Only if that is not the case, use the
                // result.
                return trimmedAtWords;
            }

            // find last '&' before max
            string result = null;
            int lastAmp = str.LastIndexOf('&', max - 1, max);
            if (lastAmp >= 0)
            {
                Regex regex = new Regex(@"&[^\s&;]{1,20};");
                Match match = regex.Match(str, lastAmp);
                if (match.Success && match.Index + match.Length > max)
                    result = str.Substring(0, match.Index);
            }
            if (result == null)
                result = str.Substring(0, max);

            return result;
        }
        protected override void OnText(Text text)
        {
            if (_inTitle)
                return;

            string textToEmit = text.RawText;
            textToEmit = textToEmit.Replace("\n", " ");
            textToEmit = textToEmit.Replace("\r", " ");
            textToEmit = textToEmit.Replace("\r\n", " ");
            Emit(textToEmit);
        }
 protected override void OnText(Text text)
 {
     if (_nextTextIsTitleText)
     {
         _title = HttpUtility.HtmlDecode(text.ToString());
         _nextTextIsTitleText = false;
     }
     if (_collectingForTag != null)
         _collectingForTag.Name = _collectingForTag.Name + text.RawText;
     base.OnText(text);
 }
 protected override void OnText(Text text)
 {
     Emit(text.ToString());
 }
 protected override void OnText(Text text)
 {
     if (FlagIsSet(Flag.RemovePartialTags))
     {
         string newText = badStartTag.Replace(text.RawText, "");
         text = new Text(newText, 0, newText.Length);
     }
     base.OnText(text);
 }
        protected override void OnText(Text text)
        {
            if (text == null || _scriptDepth > 0)
                return;

            Emit(text.ToString());
            base.OnText(text);
        }
 protected virtual void OnText(Text text)
 {
     DefaultAction(text);
 }