Browse files

Implement auto-link

  • Loading branch information...
1 parent 27451e5 commit e51a41d46b7f96e07b6c4366f8c44808327b5fd5 @drbrain drbrain committed Oct 30, 2011
Showing with 18 additions and 6 deletions.
  1. +2 −6 pegdown.kpeg
  2. +16 −0 test/test_pegdown.rb
View
8 pegdown.kpeg
@@ -633,14 +633,10 @@ TitleDouble = "\"" < ( !( "\"" Sp ( ")" | Newline ) ) . )* > "\""
AutoLink = AutoLinkUrl | AutoLinkEmail
AutoLinkUrl = "<" < /[A-Za-z]+/ "://" ( !Newline !">" . )+ > ">"
- { raise " $$ = mk_link(mk_str(yytext), yytext, ""); " }
+ { text }
AutoLinkEmail = "<" < /[-A-Za-z0-9+_]+/ "@" ( !Newline !">" . )+ > ">"
- { raise ' char *mailto = malloc(strlen(yytext) + 8);
- sprintf(mailto, "mailto:%s", yytext);
- $$ = mk_link(mk_str(yytext), mailto, "");
- free(mailto);'
- }
+ { "mailto:#{text}" }
Reference = NonindentSpace !"[]"
Label:label ":" Spnl RefSrc:link RefTitle:title BlankLine+
View
16 test/test_pegdown.rb
@@ -21,6 +21,22 @@ def mu_pp obj
s.chomp
end
+ def test_parse_auto_link_email
+ doc = parse "Autolink: <nobody@example>"
+
+ expected = doc(para("Autolink: mailto:nobody@example"))
+
+ assert_equal expected, doc
+ end
+
+ def test_parse_auto_link_url
+ doc = parse "Autolink: <http://example>"
+
+ expected = doc(para("Autolink: http://example"))
+
+ assert_equal expected, doc
+ end
+
def test_parse_block_quote
doc = parse <<-BLOCK_QUOTE
> this is

0 comments on commit e51a41d

Please sign in to comment.