mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
feat(image): optionally add image captions from alt tags
This commit is contained in:
parent
66798912de
commit
5557e6282c
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -46,6 +46,11 @@ function getDefaultOpts (simple) {
|
||||||
describe: 'Turn on/off image dimension parsing',
|
describe: 'Turn on/off image dimension parsing',
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
},
|
},
|
||||||
|
extractImageCaptions: {
|
||||||
|
defaultValue: false,
|
||||||
|
describe: 'Extract image alt tag as a caption for the image',
|
||||||
|
type: 'boolean'
|
||||||
|
},
|
||||||
simplifiedAutoLink: {
|
simplifiedAutoLink: {
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
describe: 'Turn on/off GFM autolink style',
|
describe: 'Turn on/off GFM autolink style',
|
||||||
|
|
|
@ -59,7 +59,13 @@ showdown.subParser('makehtml.images', function (text, options, globals) {
|
||||||
.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
|
.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
|
||||||
//url = showdown.helper.escapeCharacters(url, '*_', false);
|
//url = showdown.helper.escapeCharacters(url, '*_', false);
|
||||||
url = url.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
|
url = url.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
|
||||||
var result = '<img src="' + url + '" alt="' + altText + '"';
|
var result = '';
|
||||||
|
|
||||||
|
if (options.extractImageCaptions && altText) {
|
||||||
|
result += '<figure>';
|
||||||
|
}
|
||||||
|
|
||||||
|
result += '<img src="' + url + '" alt="' + altText + '"';
|
||||||
|
|
||||||
if (title && showdown.helper.isString(title)) {
|
if (title && showdown.helper.isString(title)) {
|
||||||
title = title
|
title = title
|
||||||
|
@ -79,6 +85,11 @@ showdown.subParser('makehtml.images', function (text, options, globals) {
|
||||||
|
|
||||||
result += ' />';
|
result += ' />';
|
||||||
|
|
||||||
|
if (options.extractImageCaptions && altText) {
|
||||||
|
result += '<figcaption>' + altText + '</figcaption>';
|
||||||
|
result += '</figure>';
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
<p><figure><img src="./image.png" alt="This is a caption" /><figcaption>This is a caption</figcaption></figure></p>
|
||||||
|
<p><img src="./no-caption.png" alt="" /></p>
|
|
@ -0,0 +1,3 @@
|
||||||
|
![This is a caption](./image.png)
|
||||||
|
|
||||||
|
![](./no-caption.png)
|
|
@ -95,6 +95,8 @@ describe('makeHtml() features testsuite', function () {
|
||||||
converter = new showdown.Converter({openLinksInNewWindow: true});
|
converter = new showdown.Converter({openLinksInNewWindow: true});
|
||||||
} else if (testsuite[i].name === '#355.simplifiedAutoLink-URLs-inside-parenthesis-followed-by-another-character-are-not-parsed-correctly') {
|
} else if (testsuite[i].name === '#355.simplifiedAutoLink-URLs-inside-parenthesis-followed-by-another-character-are-not-parsed-correctly') {
|
||||||
converter = new showdown.Converter({simplifiedAutoLink: true});
|
converter = new showdown.Converter({simplifiedAutoLink: true});
|
||||||
|
} else if (testsuite[i].name === 'extractImageCaptions') {
|
||||||
|
converter = new showdown.Converter({extractImageCaptions: true});
|
||||||
} else {
|
} else {
|
||||||
converter = new showdown.Converter();
|
converter = new showdown.Converter();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user