示例#1
0
        public override bool TryParse(BlockProcessor state, char pendingBulletType, out ListInfo result)
        {
            result = new ListInfo();

            var c = state.CurrentChar;

            var isRomanLow = CharHelper.IsRomanLetterLowerPartial(c);
            var isRomanUp  = !isRomanLow && CharHelper.IsRomanLetterUpperPartial(c);

            // We allow to parse roman only if we start on a new list or the pending list is already a roman list)
            if ((isRomanLow || isRomanUp) && (pendingBulletType == '\0' || pendingBulletType == 'i' || pendingBulletType == 'I'))
            {
                int startChar = state.Start;
                int endChar   = 0;
                // With a roman, we can have multiple characters
                // Note that we don't validate roman numbers
                while (isRomanLow ? CharHelper.IsRomanLetterLowerPartial(c) : CharHelper.IsRomanLetterUpperPartial(c))
                {
                    endChar = state.Start;
                    c       = state.NextChar();
                }

                result.OrderedStart        = CharHelper.RomanToArabic(state.Line.Text.Substring(startChar, endChar - startChar + 1)).ToString();
                result.BulletType          = isRomanLow ? 'i' : 'I';
                result.DefaultOrderedStart = isRomanLow ? "i" : "I";
            }
            else
            {
                // otherwise we expect a regular alpha lettered list with a single character.
                var isUpper = c.IsAlphaUpper();
                result.OrderedStart        = (Char.ToUpper(c) - 64).ToString();
                result.BulletType          = isUpper ? 'A' : 'a';
                result.DefaultOrderedStart = isUpper ? "A" : "a";
                state.NextChar();
            }

            // Finally we expect to always have a delimiter '.' or ')'
            char orderedDelimiter;

            if (!TryParseDelimiter(state, out orderedDelimiter))
            {
                return(false);
            }

            result.OrderedDelimiter = orderedDelimiter;
            return(true);
        }