Beispiel #1
0
        public static Marker CreateTag(ref string text, int pos)
        {
            if (IsTagStrong(text, pos))
            {
                return(new Marker(pos, MarkerType.Strong));
            }
            if (IsTagItalic(text, pos))
            {
                return(new Marker(pos, MarkerType.Italic));
            }
            if (IsTagLink(text, pos))
            {
                if (Marker.IsEndTag(text, pos))
                {
                    var i = pos;
                    while (text[i + 1] != '(')
                    {
                        i++;
                    }
                    var advancedInfo = CutLink(ref text, i);
                    return(new Marker(pos, MarkerType.Link, advancedInfo));
                }
                return(new Marker(pos, MarkerType.Link));
            }

            return(null);
        }
Beispiel #2
0
        public static string ConvertLine(string line)
        {
            var tags = new Stack <Marker>();

            for (int i = 0; i < line.Length; i++)
            {
                if (line[i] == '\\')
                {
                    line = line.Remove(i, 1);
                    i++;
                }
                var tag = Marker.CreateTag(ref line, i);
                if (tag == null)
                {
                    continue;
                }
                i += tag.Length - 1;

                if (Marker.IsEndTag(line, tag.Pos) && tags.Any(t => t.Type == tag.Type))
                {
                    line = ConvertTag(line, tags, tag);
                    continue;
                }

                if (Marker.IsBeginTag(line, tag.Pos))
                {
                    tags.Push(tag);
                }
            }

            return(line);
        }