示例#1
0
        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;
        }
        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);
        }
示例#3
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);
        }
        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);
        }
        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)
        {
            // sample link to gist: https://gist.github.com/pekkah/8304465
            int userNameStart = content.IndexOf(".com/") + 5;
            int gistIdStart = content.IndexOf('/', userNameStart) + 1;

            end = content.EndOfLine(gistIdStart, false);

            return new GistBlock(
                content,
                start,
                content.EndOfLine(start),
                new StringRange(
                    content,
                    userNameStart,
                    gistIdStart - 2),
                new StringRange(
                    content,
                    gistIdStart,
                    content.EndOfLine(gistIdStart)));
        }
示例#7
0
        public Block Build(int start, StringRange content, out int end)
        {
            end = content.EndOfLine(start, false);
 
            var counter = start;
            var level = 0;
            while (content[counter] == '#')
            {
                level++;
                counter++;
            }

            return new Heading(content, counter + 1, end, level);
        }
示例#8
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);
        }
        public override Span Build(int position, StringRange content, out int lastPosition)
        {
            lastPosition = content.EndOfLine(position, true);

            return new NewLineSpan(content, position, lastPosition);
        }