Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly handle a false value for the parseImgDimensions option #985

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ var defaultOptions = showdown.getDefaultOptions();
<h3>foo</h3>
```

* **parseImgDimensions**: (boolean) [default false] Enable support for setting image dimensions from within markdown syntax.
* **parseImgDimensions**: (boolean) [default true] Enable support for setting image dimensions from within markdown syntax.
Examples:
```
![foo](foo.jpg =100x80) simple, assumes units are in px
Expand Down
2 changes: 1 addition & 1 deletion docs/available-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ Open links in new windows.
Set image dimensions from within Markdown syntax.

* type: `boolean`
* default value: `false`
* default value: `true`
* introduced in: `1.1.0`

=== "example"
Expand Down
2 changes: 1 addition & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getDefaultOpts (simple) {
type: 'integer'
},
parseImgDimensions: {
defaultValue: false,
defaultValue: true,
describe: 'Turn on/off image dimension parsing',
type: 'boolean'
},
Expand Down
2 changes: 1 addition & 1 deletion src/subParsers/makehtml/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ showdown.subParser('makehtml.images', function (text, options, globals) {
result += ' title="' + title + '"';
}

if (width && height) {
if (options.parseImgDimensions && width && height) {
width = (width === '*') ? 'auto' : width;
height = (height === '*') ? 'auto' : height;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p><img src="./pic/pic1_50.png" alt="my image" /></p>
<p><img src="./pic/pic1_50.png" alt="my image2" /></p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
![my image](./pic/pic1_50.png =100pxx20px)

![my image2][1]

[1]: ./pic/pic1_50.png =100pxx20px
2 changes: 2 additions & 0 deletions test/functional/makehtml/testsuite.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ describe('makeHtml() features testsuite', function () {
var converter;
if (testsuite[i].name === '#143.support-image-dimensions') {
converter = new showdown.Converter({parseImgDimensions: true});
} else if (testsuite[i].name === '#143.not.support-image-dimensions') {
converter = new showdown.Converter({parseImgDimensions: false});
} else if (testsuite[i].name === '#69.header-level-start') {
converter = new showdown.Converter({headerLevelStart: 3});
} else if (testsuite[i].name === '#164.1.simple-autolink' || testsuite[i].name === '#204.certain-links-with-at-and-dot-break-url') {
Expand Down