| Index: third_party/pkg/markdown/lib/src/markdown/block_parser.dart
|
| diff --git a/sdk/lib/_internal/dartdoc/lib/src/markdown/block_parser.dart b/third_party/pkg/markdown/lib/src/markdown/block_parser.dart
|
| similarity index 92%
|
| copy from sdk/lib/_internal/dartdoc/lib/src/markdown/block_parser.dart
|
| copy to third_party/pkg/markdown/lib/src/markdown/block_parser.dart
|
| index bd14f36cad126cbd7255c06269bcc02bdd0a1578..42b93533345b9ab8ceae524a7a4c7c0f8ba47e16 100644
|
| --- a/sdk/lib/_internal/dartdoc/lib/src/markdown/block_parser.dart
|
| +++ b/third_party/pkg/markdown/lib/src/markdown/block_parser.dart
|
| @@ -19,6 +19,9 @@ final _RE_BLOCKQUOTE = new RegExp(r'^[ ]{0,3}>[ ]?(.*)$');
|
| /// A line indented four spaces. Used for code blocks and lists.
|
| final _RE_INDENT = new RegExp(r'^(?: |\t)(.*)$');
|
|
|
| +/// GitHub style triple quoted code block.
|
| +final _RE_CODE = new RegExp(r'^```(.*)$');
|
| +
|
| /// Three or more hyphens, asterisks or underscores by themselves. Note that
|
| /// a line like `----` is valid as both HR and SETEXT. In case of a tie,
|
| /// SETEXT should win.
|
| @@ -94,6 +97,7 @@ abstract class BlockSyntax {
|
| new SetextHeaderSyntax(),
|
| new HeaderSyntax(),
|
| new CodeBlockSyntax(),
|
| + new GitHubCodeBlockSyntax(),
|
| new BlockquoteSyntax(),
|
| new HorizontalRuleSyntax(),
|
| new UnorderedListSyntax(),
|
| @@ -240,6 +244,42 @@ class CodeBlockSyntax extends BlockSyntax {
|
| }
|
| }
|
|
|
| +/// Parses preformatted code blocks between two ``` sequences.
|
| +class GitHubCodeBlockSyntax extends BlockSyntax {
|
| + RegExp get pattern => _RE_CODE;
|
| +
|
| + List<String> parseChildLines(BlockParser parser) {
|
| + final childLines = <String>[];
|
| + parser.advance();
|
| + while (!parser.isDone) {
|
| + var match = pattern.firstMatch(parser.current);
|
| + if (match == null) {
|
| + childLines.add(parser.current);
|
| + parser.advance();
|
| + } else {
|
| + parser.advance();
|
| + break;
|
| + }
|
| + }
|
| + return childLines;
|
| + }
|
| +
|
| + Node parse(BlockParser parser) {
|
| + // Get the syntax identifier, if there is one.
|
| + var syntax = pattern.firstMatch(parser.current).group(1);
|
| +
|
| + final childLines = parseChildLines(parser);
|
| +
|
| + // The Markdown tests expect a trailing newline.
|
| + childLines.add('');
|
| +
|
| + // Escape the code.
|
| + final escaped = escapeHtml(childLines.join('\n'));
|
| +
|
| + return new Element('pre', [new Element.text('code', escaped)]);
|
| + }
|
| +}
|
| +
|
| /// Parses horizontal rules like `---`, `_ _ _`, `* * *`, etc.
|
| class HorizontalRuleSyntax extends BlockSyntax {
|
| RegExp get pattern => _RE_HR;
|
|
|