コード例 #1
0
        public bool CanBuild(int start, StringRange content)
        {
            var startOfNextLine = content.StartOfNextLine(start);
            bool isMatch = content.HasStringAt(startOfNextLine, "---");

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

            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 = _expression.IsMatch(content.Document, startOfLine);
            } while (foundItem);

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

            return new List(content, start, end, true, items);
        }
コード例 #3
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;
        }
コード例 #4
0
        public Block Build(int start, StringRange content, out int end)
        {
            int endOfHeadingText = content.EndOfLine(start, false);

            int startOfMarker = content.StartOfNextLine(endOfHeadingText);
            end = content.EndOfLine(startOfMarker, false);
            return new Heading(content, start, endOfHeadingText, 2);
        }
コード例 #5
0
        public Block Build(int start, StringRange content, out int end)
        {
            int startOfLine = start;
            var items = new List<LinkDefinition>();

            do
            {
                var key = new StringRange(
                    content,
                    content.IndexOf('[', startOfLine) + 1,
                    content.IndexOf(']', startOfLine) - 1);

                var urlStart = content.IndexOf(':', key.End) + 1;

                if (content[urlStart] == ' ')
                    urlStart++;

                var url = new StringRange(
                    content,
                    urlStart,
                    content.EndOfLine(startOfLine));

                var item = new LinkDefinition(
                    content,
                    startOfLine,
                    content.EndOfLine(startOfLine),
                    key,
                    url);

                items.Add(item);
                startOfLine = content.StartOfNextLine(startOfLine);

                if (startOfLine == -1)
                    break;

            } while (_expression.IsMatch(content.Document, content.IndexOf('[', startOfLine)));

            // special case when content ends
            end = startOfLine != -1 ? content.EndOfLine(startOfLine, false) : content.End;

            return new LinkDefinitionList(content, start, end, items);
        }
コード例 #6
0
        public Block Build(int start, StringRange content, out int end)
        {
            // try reading syntax
            StringRange syntax = null;
            var endOfStartTag = content.IndexOf("```", start) + 3;
            var endOfStartTagLine = content.EndOfLine(endOfStartTag);

            if (endOfStartTagLine > endOfStartTag)
            {
                syntax = new StringRange(content.Document, endOfStartTag, endOfStartTagLine);
            }

            // start from the actual first line of the content
            var contentStart = content.StartOfNextLine(start);

            // find the end ``` by skipping the first ```
            var contentEnd = content.IndexOf("```", contentStart) - 1;

            // skip line ending
            end = content.EndOfLine(contentEnd + 1);

            // use the content between ``` and ```
            return new Codeblock(content, contentStart, contentEnd, syntax);
        }
コード例 #7
0
        public void IsStartOfLine_StartOfLine()
        {
            /* given */
            const string text = "0123456789\nSecond line";
            var stringRange = new StringRange(text);

            /* when */
            /* then */
            stringRange.IsStartOfLine(stringRange.StartOfNextLine(0)).ShouldBeEquivalentTo(true);
        }