Skip to content

Loading…

Enable spaces in a link/image url #48

Closed
wants to merge 1 commit into from

3 participants

@sbstjn

Changed the regular expression for handling links and images, whitespaces are now allowed in a link url or image url. GitHub allows this, so it seems legit to change…

[link text](Link to file/Lorem Ipsum.txt "Alt2") is link text

@ashb
Collaborator

Hmmm interesting one.

The original markdown parser didn't accept this, nor do about half the other parsers covered by this babelmark:

http://babelmark.bobtfish.net/?markdown=%5Blink+text%5D%28Link+to+file%2FLorem+Ipsum.txt+%22Alt2%22%29

Spaces in URLs are an abomination but that's a whole other issue :)

@sbstjn

Afaik GitHub uses for redcarpet for its Markdown conversion.

In my case I'm linking to local files on a desktop computer's file system. So it's kinda ok to use spaces in links, but of course those links and files with spaces get never deployed into the wild ;)

@evilstreak
Owner

I agree with @ashb that spaces in URLs and paths are pretty nasty, but I don't think allowing it does any harm.

@semu I couldn't use your changes as they broke several other link and image tests, but I have added tests and a fix for this request in 8bf9022.

@evilstreak evilstreak closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2012
  1. More in line with GitHub Markdown styles

    Sebastian committed
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/markdown.js
View
6 lib/markdown.js
@@ -814,7 +814,7 @@ Markdown.dialects.Gruber.inline = {
// ![Alt text](/path/to/img.jpg "Optional title")
// 1 2 3 4 <--- captures
- var m = text.match( /^!\[(.*?)\][ \t]*\([ \t]*(\S*)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/ );
+ var m = text.match( /^!\[(.*?)\][ \t]*\([ \t]*([^("|\))]*)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/ );
if ( m ) {
if ( m[2] && m[2][0] == '<' && m[2][m[2].length-1] == '>' )
@@ -866,7 +866,7 @@ Markdown.dialects.Gruber.inline = {
// back based on if there a matching ones in the url
// ([here](/url/(test))
// The parens have to be balanced
- var m = text.match( /^\s*\([ \t]*(\S+)(?:[ \t]+(["'])(.*?)\2)?[ \t]*\)/ );
+ var m = text.match( /^\s*\([ \t]*([^("|\))]*)(?:[ \t]+(["'])(.*?)\2)?[ \t]*\)/ );
if ( m ) {
var url = m[1];
consumed += m[0].length;
@@ -1613,4 +1613,4 @@ function merge_text_nodes( jsonml ) {
else {
return exports;
}
-} )() );
+} )() );
Something went wrong with that request. Please try again.