markdown-it-linkify-images
Advanced tools
Comparing version
32
index.js
@@ -10,3 +10,2 @@ 'use strict' | ||
var url = token.attrs[srcIndex][1] | ||
var title = '' | ||
var caption = md.utils.escapeHtml(token.content) | ||
@@ -17,10 +16,7 @@ | ||
var imgClass = generateClass(config.imgClass) | ||
var otherAttributes = generateAttributes(md, token) | ||
if (token.attrIndex('title') !== -1) { | ||
title = ' title="' + md.utils.escapeHtml(token.attrs[token.attrIndex('title')][1]) + '"' | ||
} | ||
return '' + | ||
'<a href="' + url + '"' + linkClass + target + '>' + | ||
'<img src="' + url + '" alt="' + caption + '"' + imgClass + title + '>' + | ||
'<img src="' + url + '" alt="' + caption + '"' + imgClass + otherAttributes + '>' + | ||
'</a>' | ||
@@ -30,2 +26,26 @@ } | ||
function generateAttributes (md, token) { | ||
var ignore = ['src', 'alt'] | ||
var escape = ['title'] | ||
var attributes = '' | ||
token.attrs.forEach(function (entry) { | ||
var name = entry[0] | ||
if (ignore.includes(name)) return | ||
var value = '' | ||
if (escape.includes(name)) { | ||
value = md.utils.escapeHtml(entry[1]) | ||
} else { | ||
value = entry[1] | ||
} | ||
attributes += ' ' + name + '="' + value + '"' | ||
}) | ||
return attributes | ||
} | ||
function generateTargetAttribute (target) { | ||
@@ -32,0 +52,0 @@ target = target || '_self' |
{ | ||
"name": "markdown-it-linkify-images", | ||
"version": "1.1.1", | ||
"version": "2.0.0", | ||
"description": "A markdown-it plugin to add links to images", | ||
@@ -29,10 +29,10 @@ "main": "index.js", | ||
"devDependencies": { | ||
"browserify": "^16.2.0", | ||
"browserify": "^16.5.1", | ||
"chai": "^4.1.1", | ||
"chalk": "^2.1.0", | ||
"mocha": "^6.1.4", | ||
"rimraf": "^2.5.2", | ||
"chalk": "^4.1.0", | ||
"mocha": "^8.1.0", | ||
"rimraf": "^3.0.2", | ||
"snazzy": "^8.0.0", | ||
"standard": "^12.0.1", | ||
"uglify-js": "^3.5.13" | ||
"standard": "^14.3.4", | ||
"uglify-js": "^3.10.1" | ||
}, | ||
@@ -57,6 +57,3 @@ "standard": { | ||
] | ||
}, | ||
"dependencies": { | ||
"markdown-it": "^8.4.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
5680
8.4%0
-100%7
40%44
46.67%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed