Permalink
Browse files

Added support for poorly formed internal urls.

Cases added: [[ url ]], [[ url | label ]], [[ url label ]]
Tests added and passing
  • Loading branch information...
1 parent 4d091b0 commit 56e9a94eca41d3d8f04c65aba1e65ff22b0b134c @rdblue committed Jan 18, 2010
Showing with 27 additions and 4 deletions.
  1. +13 −4 lib/marker/language.treetop
  2. +14 −0 test/links_test.rb
@@ -382,14 +382,23 @@ module Marker
# [ external [[internal]] ]
# MediaWiki: <a href="external"></a><a href="internal">internal</a>
# Marker: <a href="external">[[internal]]</a>
+ #
+ # also use this rule to match bad internal link syntax [[ url | label ]]
+ # because the rendering rules are the same
rule external_link
- external_link_start ws t:url rws l:external_link_enclosed_text ws external_link_end <ExternalLink>
- /
- external_link_start ws t:url ws external_link_end <ExternalLink>
- /
+# external_link_start ws t:url rws l:external_link_enclosed_text ws external_link_end <ExternalLink>
+# /
+# external_link_start ws t:url ws external_link_end <ExternalLink>
+# /
external_link_start ws t:implicit_url rws l:external_link_enclosed_text ws external_link_end <ExternalLink>
/
external_link_start ws t:implicit_url ws external_link_end <ExternalLink>
+ /
+ internal_link_start ws t:implicit_url rws l:internal_link_enclosed_text ws internal_link_end <ExternalLink>
+ /
+ internal_link_start ws t:implicit_url ws arg_delimiter ws l:internal_link_enclosed_text ws internal_link_end <ExternalLink>
+ /
+ internal_link_start ws t:implicit_url ws internal_link_end <ExternalLink>
end
rule external_link_enclosed_text
View
@@ -34,6 +34,20 @@ def test_internal_link_with_sanitization
assert_match("<a href='/Example page'>Example page</a>", markup.to_html)
end
+ def test_internal_with_url
+ text = "[[http://www.example.com]]"
+ markup = Marker.parse text
+ assert_match("<p><a href='http://www.example.com'>[1]</a></p>\n<ol><li><a href='http://www.example.com'>http://www.example.com</a></li></ol>", markup.to_html)
+
+ text = "[[http://www.example.com|Example page]]"
+ markup = Marker.parse text
+ assert_match("<a href='http://www.example.com'>Example page</a>", markup.to_html)
+
+ text = "[[http://www.example.com Example page]]"
+ markup = Marker.parse text
+ assert_match("<a href='http://www.example.com'>Example page</a>", markup.to_html)
+ end
+
def test_external_link_with_alias
text = "[http://www.example.com Example link]"
markup = Marker.parse text

0 comments on commit 56e9a94

Please sign in to comment.