示例#1
0
 protected void ParseOpeningUnderscore(int index)
 {
     if (TextEnded)
     {
         if (PreviousIndex < Markdown.Length)
         {
             TagInfo.AddContent(new TagInfo(text: Markdown.Substring(PreviousIndex)));
         }
         PreviousIndex = Markdown.Length;
         State         = States.Pop();
     }
     else if (Markdown[index] == UnderscoreSymbol && !ShouldEscaped(Markdown[index]))
     {
         UnderscoreCounter++;
     }
     else if (char.IsWhiteSpace(Markdown[index]))
     {
         UnderscoreCounter = 0;
         BackslashCounter  = 0;
         State             = States.Pop();
     }
     else
     {
         OpenUnderscoreTag(index);
     }
 }
示例#2
0
        private void CloseUnderscoreTag(int index)
        {
            var tag = UnderscoreCounter == 1 ? Tag.Italic : Tag.Bold;

            if (!HasOpeningTag(tag, Markdown[index]))
            {
                if (TextEnded)
                {
                    TagInfo.AddContent(new TagInfo(text: Markdown.Substring(PreviousIndex)));
                }
                if (char.IsWhiteSpace(Markdown[index]))
                {
                    UnderscoreCounter = 0;
                }
                else
                {
                    SetNewState(OpenUnderscoreTag);
                    State(index);
                }
            }
            else if (TagsIntersect(tag))
            {
                var(currentTag, conflictedTag) =
                    UnderscoreCounter == 1 ? (Tag.Italic, Tag.Bold) : (Tag.Bold, Tag.Italic);
                ResetFormattingForConflictingTags(currentTag, conflictedTag);
                if (TextEnded)
                {
                    TagInfo.AddContent(new TagInfo(text: Markdown.Substring(PreviousIndex)));
                    PreviousIndex = Markdown.Length;
                }
            }
            else
            {
                if (TagInfo.Tag == Tag.Italic || TextEnded && tag == Tag.Italic)
                {
                    while (TagInfo.Tag != Tag.Italic)
                    {
                        TagInfo = NestedTagInfos.Pop();
                    }
                    foreach (var bold in TagInfo.FindAndGetBoldContent())
                    {
                        bold.ResetFormatting(true);
                    }
                }

                CloseFirstMatching(index);
            }
        }
示例#3
0
        private void OpenUnderscoreTag(int index)
        {
            var tag = UnderscoreCounter == 1 ? Tag.Italic : Tag.Bold;

            UnderscoreCounter = UnderscoreCounter == 1 ? 1 : 2;
            var length = index - UnderscoreCounter - PreviousIndex;

            if (length > 0)
            {
                TagInfo.AddContent(new TagInfo(text: Markdown.Substring(PreviousIndex, length)));
            }

            PreviousIndex     = index;
            UnderscoreCounter = 0;
            hasWhiteSpace     = false;

            SetNewTagInfo(new TagInfo(tag));
            TagInfo.InsideWord = !PreviousIsSpace;
            State = ParseUnderscoreContent;
            State(index);
        }
示例#4
0
 protected void SetNewTagInfo(TagInfo newTagInfo)
 {
     TagInfo.AddContent(newTagInfo);
     NestedTagInfos.Push(TagInfo);
     TagInfo = newTagInfo;
 }
示例#5
0
        private void ParseUnderscoreContent(int index)
        {
            if (TextEnded)
            {
                if (!PreviousIsSpace && UnderscoreCounter != 0)
                {
                    CloseUnderscoreTag(Markdown.Length - 1);
                    if (wordContainsDigits)
                    {
                        foreach (var tag in tagsInsideWord)
                        {
                            tag.ResetFormatting(true);
                        }
                    }
                }
                else
                {
                    TagInfo.AddContent(new TagInfo(text: Markdown.Substring(PreviousIndex)));
                    TagInfo.ResetFormatting();
                    TagInfo       = NestedTagInfos.Pop();
                    State         = States.Pop();
                    PreviousIndex = Markdown.Length;
                }
            }
            else if (Markdown[index] == UnderscoreSymbol && !ShouldEscaped(Markdown[index]))
            {
                UnderscoreCounter++;
            }
            else
            {
                if (Markdown[index] == LinkOpenSymbol && !ShouldEscaped(Markdown[index]))
                {
                    PreviousIsSpace = false;
                    SetLinkTag(index);
                    return;
                }

                if (char.IsDigit(Markdown[index]))
                {
                    wordContainsDigits = true;
                }

                if (UnderscoreCounter != 0)
                {
                    if (!PreviousIsSpace)
                    {
                        CloseUnderscoreTag(index);
                    }
                    else if (PreviousIsSpace)
                    {
                        SetNewState(OpenUnderscoreTag);
                        State(index);
                    }
                }

                if (char.IsWhiteSpace(Markdown[index]))
                {
                    hasWhiteSpace     = true;
                    UnderscoreCounter = 0;

                    if (TagInfo.InsideWord)
                    {
                        TagInfo.ResetFormatting();
                        State = States.Pop();
                    }

                    tagsInsideWord = new List <TagInfo>();
                }


                if (wordContainsDigits)
                {
                    foreach (var tag in tagsInsideWord)
                    {
                        tag.ResetFormatting(true);
                    }
                }

                PreviousIsSpace = char.IsWhiteSpace(Markdown[index]) ||
                                  Markdown[index] == '\\' && BackslashCounter % 2 == 0;
            }
        }