Esempio n. 1
0
        public override Node parse(BlockParser parser)
        {
            var childLines = new List <string>();

            // Eat until we hit something that ends a paragraph.
            while (!BlockSyntax.isAtBlockEnd(parser))
            {
                childLines.Add(parser.current);
                parser.advance();
            }

            var paragraphLines = _extractReflinkDefinitions(parser, childLines);

            if (paragraphLines == null)
            {
                // Paragraph consisted solely of reference link definitions.
                return(new TextNode(""));
            }
            else
            {
                var contents = new UnparsedContent(paragraphLines.join('\n'));
                return(new Element("p", new List <Node>()
                {
                    contents
                }));
            }
        }
Esempio n. 2
0
        public override Node parse(BlockParser parser)
        {
            var    lines = new List <string>();
            string tag   = string.Empty;

            while (!parser.isDone)
            {
                var match = BlockParser._setextPattern.Match(parser.current);
                if (!match.Success)
                {
                    lines.Add(parser.current);
                    parser.advance();
                    continue;
                }
                else
                {
                    tag = match.Groups[1].Value[0] == '=' ? "h1" : "h2";
                    parser.advance();
                    break;
                }
            }


            var contents = new UnparsedContent(lines.join('\n'));

            return(new Element(tag, new List <Node>()
            {
                contents
            }));
        }
Esempio n. 3
0
        public override Node parse(BlockParser parser)
        {
            var match = pattern.Match(parser.current);

            parser.advance();
            var level    = match.Groups[1].Length;
            var contents = new UnparsedContent(match.Groups[2].Value.Trim());

            return(new Element("h" + level, new List <Node>()
            {
                contents
            }));
        }
Esempio n. 4
0
        Element parseRow(
            BlockParser parser, List <string> alignments, string cellType)
        {
            var line = parser.current
                       .replaceFirst(_openingPipe, "")
                       .replaceFirst(_closingPipe, "");
            var cells = line.split(_pipePattern);

            parser.advance();
            var    row     = new List <Node>();
            string preCell = string.Empty;

            for (var index = 0; index < cells.Length; index++)
            {
                var cell = cells[index];
                if (preCell != null)
                {
                    cell    = preCell + cell;
                    preCell = null;
                }

                if (cell.EndsWith("\\"))
                {
                    preCell = cell.Substring(0, cell.Length - 1) + '|';
                    continue;
                }

                var contents = new UnparsedContent(cell);
                row.Add(new Element(cellType, new List <Node>()
                {
                    contents
                }));
            }

            for (var i = 0; i < row.Count && i < alignments.Count; i++)
            {
                if (alignments[i] == null)
                {
                    continue;
                }

                ((Element)row[i]).attributes["style"] = "text-align: " + alignments[i] + ';';
            }

            return(new Element("tr", row));
        }