コード例 #1
0
ファイル: ListBuilder.cs プロジェクト: pekkah/Tanka.Markdown
        protected int FindEndOfItem(StringRange content, int position)
        {
            /*********************************************
             * item will end when the next line is not 
             * indented by at least one space
             * ******************************************/

            for (int possibleEnd = position; possibleEnd < content.End; possibleEnd++)
            {
                possibleEnd = content.EndOfLine(possibleEnd, true);
                var lineStart = content.StartOfNextLine(possibleEnd);

                if (lineStart == -1)
                {
                    return content.EndOfLine(possibleEnd);
                }

                // if line does not start with space then last line was the end of item
                if (!content.HasCharactersAt(lineStart, ' '))
                {
                    return content.EndOfLine(possibleEnd);
                }
            }

            return position;
        }
コード例 #2
0
        public override Block Build(int start, StringRange content, out int end)
        {
            int startOfLine = start;
            var items = new List<Item>();
            bool foundItem = false;
            Item lastItem = null;

            do
            {
                int startOfItem = content.IndexOf(' ', startOfLine) + 1;
                int endOfItem = FindEndOfItem(content, startOfItem);

                IEnumerable<Span> spans = _inlineParser.Parse(new StringRange(content, startOfItem, endOfItem));
                lastItem = new Item(
                    content,
                    startOfItem,
                    endOfItem,
                    spans);

                items.Add(lastItem);
                startOfLine = content.StartOfNextLine(endOfItem);

                if (startOfLine == -1)
                    break;

                foundItem = content.HasCharactersAt(startOfLine, _startsWith, ' ');
            } while (foundItem);

            // special case when content ends
            end = content.EndOfLine(lastItem.End);

            return new List(content, start, end, false, items);
        }
コード例 #3
0
        public override bool CanBuild(int start, StringRange content)
        {
            if (!content.IsStartOfLine(start))
                return false;

            bool starts = content.HasCharactersAt(start, _startsWith, ' ');

            return starts;
        }
コード例 #4
0
        public Block Build(int start, StringRange content, out int end)
        {
            // \n\n
            end = content.EndOfLine(start, true);

            if (content.HasCharactersAt(end + 1, '\n'))
                end = content.EndOfLine(end + 1, true);

            return new EmptyLine(content, start, end);
        }