示例#1
0
 private static Color?ProcessBgColor(string tag, Color?oldColor, bool isCloseTag)
 {
     if (isCloseTag)
     {
         return(new Color?());
     }
     if (tag.Length <= 8)
     {
         return(new Color?());
     }
     tag = tag.Substring(8);
     return(new Color?(TinyHTMLParsers.ParseColor(tag, oldColor)));
 }
示例#2
0
 private static void ProcessSpan(
     ref FormattedText currentFormattedText,
     string lowerHtmlTag,
     string htmlTag,
     bool isClosingTag,
     TinyHTMLParsers.TinyHTMLParsersData parserData)
 {
     if (isClosingTag)
     {
         if (parserData.lastFormattedText.Count <= 0)
         {
             return;
         }
         currentFormattedText = parserData.lastFormattedText.Pop();
         currentFormattedText.ShouldDisplayBullet = false;
     }
     else
     {
         parserData.lastFormattedText.Push(new FormattedText(currentFormattedText));
         string attribute = TinyHTMLParsers.ParseAttribute(htmlTag, lowerHtmlTag, "style");
         string tag1      = TinyHTMLParsers.ProcessStyle(attribute, "color");
         if (!string.IsNullOrEmpty(tag1))
         {
             currentFormattedText.FontColor = TinyHTMLParsers.ParseColor(tag1, new Color?(currentFormattedText.FontColor));
         }
         string tag2 = TinyHTMLParsers.ProcessStyle(attribute, "background-color");
         if (!string.IsNullOrEmpty(tag2))
         {
             currentFormattedText.BgColor = new Color?(TinyHTMLParsers.ParseColor(tag2, currentFormattedText.BgColor));
         }
         string htmlTag1 = TinyHTMLParsers.ProcessStyle(attribute, "font-family");
         if (!string.IsNullOrEmpty(htmlTag1))
         {
             currentFormattedText.FontName = TinyHTMLParsers.ParseFont(htmlTag1);
         }
         string tag3 = TinyHTMLParsers.ProcessStyle(attribute, "font-size");
         if (string.IsNullOrEmpty(tag3))
         {
             return;
         }
         currentFormattedText.FontSize = TinyHTMLParsers.ParseNumber(tag3, currentFormattedText.FontSize);
     }
 }
示例#3
0
        public static bool ApplyHTMLSettingsFromTag(
            ref FormattedText currentFormattedText,
            FormattedText prevText,
            string htmlTag,
            TinyHTMLParsers.TinyHTMLParsersData parserData,
            ref bool shouldProduceNewLine,
            ref string text)
        {
            if (string.IsNullOrEmpty(htmlTag))
            {
                return(true);
            }
            htmlTag = htmlTag.Trim('<', '>');
            bool flag1 = htmlTag.StartsWith("/");

            currentFormattedText.IsClosingTag = flag1;
            if (flag1)
            {
                htmlTag = htmlTag.TrimStart('/');
            }
            string lower = htmlTag.ToLower();
            bool   flag2 = true;

            if (lower == "i" || lower == "em")
            {
                currentFormattedText.FontStyle = TinyHTMLParsers.ProcessFontStyle(currentFormattedText.FontStyle, FontStyle.Italic, flag1);
            }
            else if (lower == "b" || lower == "strong")
            {
                currentFormattedText.FontStyle = TinyHTMLParsers.ProcessFontStyle(currentFormattedText.FontStyle, FontStyle.Bold, flag1);
            }
            else if (lower == "u")
            {
                currentFormattedText.FontStyle = TinyHTMLParsers.ProcessFontStyle(currentFormattedText.FontStyle, FontStyle.Underline, flag1);
            }
            else if (lower.StartsWith("color") && htmlTag.Length > 6)
            {
                currentFormattedText.FontColor = TinyHTMLParsers.ParseColor(htmlTag.Substring(6), new Color?(currentFormattedText.FontColor));
            }
            else if (lower.StartsWith("size=") || lower.StartsWith("size ="))
            {
                currentFormattedText.FontSize = TinyHTMLParsers.ParseSize(htmlTag, prevText.FontSize);
            }
            else if ((lower.StartsWith("font=") || lower.StartsWith("font =")) && htmlTag.Length > 5)
            {
                currentFormattedText.FontName = TinyHTMLParsers.ParseFont(htmlTag.Substring(5));
            }
            else if (lower == "strike")
            {
                currentFormattedText.FontStyle = TinyHTMLParsers.ProcessFontStyle(currentFormattedText.FontStyle, FontStyle.Strikeout, flag1);
            }
            else if (lower.StartsWith("bgcolor"))
            {
                currentFormattedText.BgColor = TinyHTMLParsers.ProcessBgColor(lower, currentFormattedText.BgColor, flag1);
            }
            else if (lower == "ul")
            {
                TinyHTMLParsers.ProcessListEntry(flag1, FormattedText.HTMLLikeListType.List, parserData.lastListType, parserData.lastListNumberCount, currentFormattedText);
            }
            else if (lower == "ol")
            {
                TinyHTMLParsers.ProcessListEntry(flag1, FormattedText.HTMLLikeListType.OrderedList, parserData.lastListType, parserData.lastListNumberCount, currentFormattedText);
            }
            else if (lower == "li")
            {
                int numberCount = 0;
                shouldProduceNewLine = !shouldProduceNewLine && !flag1;
                if (parserData.lastListNumberCount.Count > 0)
                {
                    numberCount = parserData.lastListNumberCount.Pop();
                }
                if (parserData.lastListType.Count > 0)
                {
                    TinyHTMLParsers.ProcessSingleListEntry(flag1, ref numberCount, currentFormattedText, parserData);
                }
                parserData.lastListNumberCount.Push(numberCount);
            }
            else if (!(lower == "html"))
            {
                if (lower == "br" || lower == "br /" || lower == "br/")
                {
                    shouldProduceNewLine = !flag1;
                }
                else if (lower == "p")
                {
                    if (flag1)
                    {
                        shouldProduceNewLine = false;
                    }
                    else if (!prevText.IsClosingTag && !prevText.StartNewLine)
                    {
                        shouldProduceNewLine = !shouldProduceNewLine;
                    }
                }
                else if (lower.StartsWith("img "))
                {
                    TinyHTMLParsers.SetImage(TinyHTMLParsers.ParseImageAttribute(htmlTag, lower, "src"), TinyHTMLParsers.ParseAttribute(htmlTag, lower, "width"), TinyHTMLParsers.ParseAttribute(htmlTag, lower, "height"), currentFormattedText);
                }
                else if (lower.StartsWith("a"))
                {
                    TinyHTMLParsers.ProcessLink(currentFormattedText, htmlTag, lower, flag1, ref text);
                }
                else if (lower.StartsWith("span"))
                {
                    TinyHTMLParsers.ProcessSpan(ref currentFormattedText, lower, htmlTag, flag1, parserData);
                }
                else
                {
                    flag2 = false;
                }
            }
            return(flag2);
        }