mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
feat(images): add support for image's implicit reference syntax
Closes #366
This commit is contained in:
parent
f1eab2a7f2
commit
0c6c07b341
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.
|
@ -6,8 +6,9 @@ showdown.subParser('images', function (text, options, globals) {
|
|||
|
||||
text = globals.converter._dispatch('images.before', text, options, globals);
|
||||
|
||||
var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
|
||||
referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g;
|
||||
var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
|
||||
referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g,
|
||||
refShortcutRegExp = /!\[([^\[\]]+)]()()()()()/g;
|
||||
|
||||
function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
|
||||
|
||||
|
@ -77,6 +78,9 @@ showdown.subParser('images', function (text, options, globals) {
|
|||
// Next, handle inline images: ![alt text](url =<width>x<height> "optional title")
|
||||
text = text.replace(inlineRegExp, writeImageTag);
|
||||
|
||||
// handle reference-style shortcuts: |[img text]
|
||||
text = text.replace(refShortcutRegExp, writeImageTag);
|
||||
|
||||
text = globals.converter._dispatch('images.after', text, options, globals);
|
||||
return text;
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<p><img src="/path/to/img.jpg" alt="Alt text" /></p>
|
||||
<p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>
|
||||
<p><img src="url/to/image" alt="Alt text" title="Optional title attribute" /></p>
|
||||
<p><img src="url/to/image.jpg" alt="Alt text" title="Optional title attribute" /></p>
|
||||
<p><img src="url/to/image2.jpg" alt="My Image" title="Optional title attribute" /></p>
|
||||
<p>![leave me alone]</p>
|
||||
<p>![leave me alone][]</p>
|
||||
|
|
|
@ -5,4 +5,11 @@
|
|||
|
||||
![Alt text][id]
|
||||
|
||||
[id]: url/to/image "Optional title attribute"
|
||||
![My Image]
|
||||
|
||||
![leave me alone]
|
||||
|
||||
![leave me alone][]
|
||||
|
||||
[id]: url/to/image.jpg "Optional title attribute"
|
||||
[My Image]: url/to/image2.jpg "Optional title attribute"
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
<p>Search the web at <a href="http://google.com/">Google</a> or <a href="http://daringfireball.net/">Daring Fireball</a>.</p>
|
||||
<p>Search the web at <a href="http://google.com/">Google</a> or <a href="http://daringfireball.net/">Daring Fireball</a>.</p>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
|
||||
Search the web at [Google][] or [Daring Fireball][].
|
||||
|
||||
Search the web at [Google] or [Daring Fireball].
|
||||
|
||||
|
||||
[Google]: http://google.com/
|
||||
[Daring Fireball]: http://daringfireball.net/
|
||||
|
|
Loading…
Reference in New Issue
Block a user