Dropping !image[] & other regex fixes

closes #452

- changed keyboard shortcut to insert ![].. not !image[]
- changed regex in ghostdown to only work for ![]
- added a further regex in ghostdown to properly match for URLs inside the parens
This commit is contained in:
Hannah Wolfe 2013-08-20 21:16:40 +01:00
parent 6bb5fdd757
commit 24673b4943
3 changed files with 8 additions and 7 deletions

View File

@ -1,14 +1,15 @@
(function () {
var ghostdown = function (converter) {
var ghostdown = function () {
return [
// [image] syntax
// ![] image syntax
{
type: 'lang',
filter: function (source) {
return source.replace(/\n?!(?:image)?\[([^\n\]]*)\](?:\(([^\n\)]*)\))?/gi, function (match, alt, src) {
filter: function (text) {
return text.replace(/\n?!\[([^\n\]]*)\](?:\(([^\n\)]*)\))?/gi, function (match, alt, src) {
var result = "";
if (src !== "http://") {
/* regex from isURL in node-validator. Yum! */
if (src && src.match(/^(?!mailto:)(?:(?:https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d{2,5})?(?:\/[^\s]*)?$/i)) {
result = '<img class="js-upload-target" src="' + src + '"/>';
}
return '<section class="js-drop-zone image-uploader">' + result +

View File

@ -140,7 +140,7 @@
strike: "~~$1~~",
code: "`$1`",
link: "[$1](http://)",
image: "!image[$1](http://)",
image: "![$1](http://)",
blockquote: "> $1"
}
};

View File

@ -34,7 +34,7 @@
</tr>
<tr>
<td>Image</td>
<td>!image[image](http://)</td>
<td>![alt](http://)</td>
<td>Ctrl + Shift + I</td>
</tr>
<tr>