public static function check(Parser $parser) { $line = $parser->consumeLine(); if (preg_match("/^( |\t){0,3}\\*( |\t)*\\*( |\t)*\\*( |\t|\\*)*\$/", $line) || preg_match("/^( |\t){0,3}-( |\t)*-( |\t)*-( |\t|\\-)*\$/", $line) || preg_match("/^( |\t){0,3}_( |\t)*_( |\t)*_( |\t|_)*\$/", $line)) { return new RuleBlock($parser, $line); } return null; }
public static function check(Parser $parser) { $line = $parser->consumeLine(); if (preg_match("/^( ){0,3}#{1,6}( |\$)/", $line)) { return new ATXHeaderBlock($parser, $line); } return null; }
public function testLines() { $parser = new Parser("Test\nTest"); $this->assertEquals(count($parser->getLines()), 2); $parser = new Parser("Test\r\nTest"); $this->assertEquals(count($parser->getLines()), 2); $parser = new Parser("Test\nTest\r\nTest"); $this->assertEquals(count($parser->getLines()), 3); }
public static function check(Parser $parser) { $title = $parser->consumeLine(); $underline = $parser->consumeLine(); if (preg_match("/^( {4}| *\$)/", $title)) { return null; } if (preg_match("/^ {0,3}(-+|=+) *\$/", $underline)) { return new SetextHeaderBlock($parser, $title, $underline); } return null; }
public static function check(Parser $parser) { $lines = []; try { $line = $parser->peakAhead(); while (preg_match("/^( {4}| *\$)/", $line)) { $parser->consumeLine(); $lines[] = $line; $line = $parser->peakAhead(); } } catch (\OutOfRangeException $ignored) { } if ($lines) { return new IndentedCodeBlock($parser, $lines); } return null; }
public static function check(Parser $parser) { $lines = []; $line = $parser->consumeLine(); if (!preg_match("/^( *)(`{3,}|~{3,})([^`]*)\$/", $line, $matches)) { return null; } $separators = $matches[2]; $infoString = $matches[3]; $indent = strlen($matches[1]); $endregex = "/^ {0,3}" . $separators[0] . "{" . strlen($separators) . ",} *\$/"; try { $line = $parser->consumeLine(); while (!preg_match($endregex, $line)) { $lines[] = $line; $line = $parser->consumeLine(); } } catch (\OutOfRangeException $ignored) { } return new FencedCodeBlock($parser, $lines, $infoString, $indent); }
public static function check(Parser $parser) { $line = $parser->peakAhead(); //Type 1 HTML Block : Code if (preg_match("/^ {0,3}<(script|pre|style)( |>|\$)/i", $line, $matches)) { $lines = []; $tag = $matches[0]; try { while (!preg_match("/<\\/{$tag}>/i", $line)) { $parser->consumeLine(); $lines[] = $line; $line = $parser->peakAhead(); } } catch (\OutOfRangeException $ignored) { } try { $parser->consumeLine(); $lines[] = $line; } catch (\OutOfRangeException $ignored) { } return new HTMLBlock($parser, $lines); } //Type 2 HTML Block : comment if (preg_match("/^ {0,3}<!--/", $line)) { $lines = []; try { while (!preg_match("/-->/", $line)) { $parser->consumeLine(); $lines[] = $line; $line = $parser->peakAhead(); } } catch (\OutOfRangeException $ignored) { } $parser->consumeLine(); $lines[] = $line; return new HTMLBlock($parser, $lines); } //Type 3 HTML Block : instructions if (preg_match("/^ {0,3}<\\?/", $line)) { $lines = []; try { while (!preg_match("/\\?>/", $line)) { $parser->consumeLine(); $lines[] = $line; $line = $parser->peakAhead(); } } catch (\OutOfRangeException $ignored) { } $parser->consumeLine(); $lines[] = $line; return new HTMLBlock($parser, $lines); } //Type 4 HTML Block if (preg_match("/^ {0,3}<![A-Z]/", $line)) { $lines = []; try { while (!preg_match("/>/", $line)) { $parser->consumeLine(); $lines[] = $line; $line = $parser->peakAhead(); } } catch (\OutOfRangeException $ignored) { } $parser->consumeLine(); $lines[] = $line; return new HTMLBlock($parser, $lines); } //Type 5 HTML Block : CDATA if (preg_match("/^ {0,3}<!\\[CDATA\\[/", $line)) { $lines = []; try { while (!preg_match("/\\]\\]>/", $line)) { $parser->consumeLine(); $lines[] = $line; $line = $parser->peakAhead(); } } catch (\OutOfRangeException $ignored) { } $parser->consumeLine(); $lines[] = $line; return new HTMLBlock($parser, $lines); } //Type 6 HTML Block : garbage $tags = ["address", "article", "aside", "base", "basefont", "blockquote", "body", "caption", "center", "col", "colgroup", "dd", "details", "dialog", "dir", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "form", "frame", "frameset", "h1", "head", "header", "hr", "html", "iframe", "legend", "li", "link", "main", "menu", "menuitem", "meta", "nav", "noframes", "ol", "optgroup", "option", "p", "param", "section", "source", "summary", "table", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track", "ul"]; if (preg_match("/^ {0,3}<\\/?(" . implode("|", $tags) . ")( |\$|\\/?>)/i", $line)) { $lines = []; try { while (!preg_match("/^ *\$/", $line)) { $parser->consumeLine(); $lines[] = $line; $line = $parser->peakAhead(); } } catch (\OutOfRangeException $ignored) { } try { $parser->consumeLine(); } catch (\OutOfRangeException $ignored) { } return new HTMLBlock($parser, $lines); } //Type 7 HTML Block : Any tag //Hell's regex, I broke it down in several parts for it to be readable a bit. $tagname = "[A-z][A-z0-9-]*"; $attrib_name = "[A-z_:][A-z0-9_\\.:-]*"; $attrib_value = "[^\"'=<>` ]+"; $single_quoted_attrib_value = "'[^']*'"; $double_quoted_attrib_value = "\"[^\"]*\""; $attributes = " +{$attrib_name}( *= *({$attrib_value}|{$single_quoted_attrib_value}|{$double_quoted_attrib_value}))?"; $opening_tag = "<({$tagname})({$attributes})* *\\/?>"; $closing_tag = "<\\/{$tagname} *>"; if (preg_match("/^ {0,3}({$opening_tag}|{$closing_tag})/i", $line, $matches)) { $lines = []; try { while (!preg_match("/^ *\$/i", $line)) { $parser->consumeLine(); $lines[] = $line; $line = $parser->peakAhead(); } } catch (\OutOfRangeException $ignored) { } try { $parser->consumeLine(); $lines[] = $line; } catch (\OutOfRangeException $ignored) { } return new HTMLBlock($parser, $lines); } return null; }