evilstreak / markdown-js

A Markdown parser for javascript
7.7k stars 863 forks source link

Allow whitespaces in links between [Alt text] and [id] #2

Closed kapouer closed 14 years ago

kapouer commented 14 years ago

Hi, i just figured other markdown tools assume one can put whitespaces there. Here's a simple patch :

From c195026631d0c2a735776b2d2f6cc474fd167d9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lal?= <kapouer@melix.org>
Date: Mon, 24 May 2010 16:58:42 +0200
Subject: [PATCH] Allow whitespace in links [] []

---
 lib/markdown.js |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/markdown.js b/lib/markdown.js
index 58c6b79..899a724 100644
--- a/lib/markdown.js
+++ b/lib/markdown.js
@@ -831,7 +831,7 @@ Markdown.dialects.Gruber.inline = {

       // [Alt text][id]
       // [id]
-      m = text.match( /^\[([\s\S]*?)\](?:\[(.*?)\])?/ );
+      m = text.match( /^\[([\s\S]*?)\][ \t]*(?:\[(.*?)\])?/ );

       if ( m ) {
         // [id] case, text == id
-- 
1.7.1
evilstreak commented 14 years ago

Thanks for catching this one. Unfortunately tweaking the regex like that breaks a bunch of other formatting tested in test/features/. I've added a feature test for this issue to my local copy and will look into a fix for it.

evilstreak commented 14 years ago

Looking at other Markdown implementations (via http://babelmark.bobtfish.net/) the original and several others seem to allow a single space but not multiple spaces nor tabs. As such I've changed the regex to: /^\[([\s\S]*?)\](?: ?\[(.*?)\])?/

kapouer commented 14 years ago

safest choice ! thanks