Skip to content

Commit

Permalink
HTML mode: If the media is passed as a path/url (except data:), speci…
Browse files Browse the repository at this point in the history
…fy it as the title as well.
  • Loading branch information
papandreou committed Jul 6, 2015
1 parent b35623a commit 429490e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/magicPenMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ module.exports = {
var src;
if (typeof media === 'string') {
src = media;
if (typeof title === 'undefined' && !/^data:/.test(media)) {
title = media;
}
} else if (typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function' && typeof Blob !== 'undefined') {
src = URL.createObjectURL(new Blob([media], { type: sanitizeContentType(contentType) }));
} else {
Expand Down
12 changes: 6 additions & 6 deletions test/magicPenMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('magicpen-media', function () {
magicPen.clone('html').media('foo/bar.jpg').toString(),
'to equal',
'<div style="font-family: monospace; white-space: nowrap">\n' +
' <div><img src="foo/bar.jpg"></div>\n' +
' <div><img src="foo/bar.jpg" title="foo/bar.jpg"></div>\n' +
'</div>'
);
});
Expand All @@ -21,7 +21,7 @@ describe('magicpen-media', function () {
magicPen.clone('html').media('foo&bar".jpg').toString(),
'to equal',
'<div style="font-family: monospace; white-space: nowrap">\n' +
' <div><img src="foo&amp;bar&quot;.jpg"></div>\n' +
' <div><img src="foo&amp;bar&quot;.jpg" title="foo&amp;bar&quot;.jpg"></div>\n' +
'</div>'
);
});
Expand All @@ -31,7 +31,7 @@ describe('magicpen-media', function () {
magicPen.clone('html').media('foobar.jpg', { alt: 'hey"there' }).toString(),
'to equal',
'<div style="font-family: monospace; white-space: nowrap">\n' +
' <div><img src="foobar.jpg" alt="hey&quot;there"></div>\n' +
' <div><img src="foobar.jpg" alt="hey&quot;there" title="foobar.jpg"></div>\n' +
'</div>'
);
});
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('magicpen-media', function () {
magicPen.clone('html').media('foo/bar.jpg', { width: 10, height: 20 }).toString(),
'to equal',
'<div style="font-family: monospace; white-space: nowrap">\n' +
' <div><img src="foo/bar.jpg" style="max-width: 6em; max-width: 10ch; max-height: 20em"></div>\n' +
' <div><img src="foo/bar.jpg" title="foo/bar.jpg" style="max-width: 6em; max-width: 10ch; max-height: 20em"></div>\n' +
'</div>'
);
});
Expand All @@ -71,7 +71,7 @@ describe('magicpen-media', function () {
magicPen.clone('html').video('foo.mkv', { width: 10, height: 20 }).toString(),
'to equal',
'<div style="font-family: monospace; white-space: nowrap">\n' +
' <div><video src="foo.mkv" style="max-width: 6em; max-width: 10ch; max-height: 20em"></video></div>\n' +
' <div><video src="foo.mkv" title="foo.mkv" style="max-width: 6em; max-width: 10ch; max-height: 20em"></video></div>\n' +
'</div>'
);
});
Expand All @@ -81,7 +81,7 @@ describe('magicpen-media', function () {
magicPen.clone('html').audio('foo.aiff', { width: 10, height: 20 }).toString(),
'to equal',
'<div style="font-family: monospace; white-space: nowrap">\n' +
' <div><audio src="foo.aiff" style="max-width: 6em; max-width: 10ch; max-height: 20em"></audio></div>\n' +
' <div><audio src="foo.aiff" title="foo.aiff" style="max-width: 6em; max-width: 10ch; max-height: 20em"></audio></div>\n' +
'</div>'
);
});
Expand Down

0 comments on commit 429490e

Please sign in to comment.