Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Unified Diff: third_party/pkg/markdown/lib/src/markdown/block_parser.dart

Issue 18497012: Add markdown to third_party/pkg (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;

Powered by Google App Engine
This is Rietveld 408576698