mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
feature(simpleLineBreaks): parse linebreaks as <br />
This option enables linebreaks to always be treated as `<br />` tags without needing to add spaces in front of the line, the same way GitHub does. Closes #206
This commit is contained in:
parent
7c05093a06
commit
0942b5e87d
14
README.md
14
README.md
@ -262,6 +262,20 @@ var defaultOptions = showdown.getDefaultOptions();
|
|||||||
|
|
||||||
* **disableForced4SpacesIndentedSublists**: (boolean) [default false] Disables the requirement of indenting sublists by 4 spaces for them to be nested,
|
* **disableForced4SpacesIndentedSublists**: (boolean) [default false] Disables the requirement of indenting sublists by 4 spaces for them to be nested,
|
||||||
effectively reverting to the old behavior where 2 or 3 spaces were enough. (since v1.5.0)
|
effectively reverting to the old behavior where 2 or 3 spaces were enough. (since v1.5.0)
|
||||||
|
|
||||||
|
* **simpleLineBreaks**: (boolean) [default false] Parses line breaks as <br> like GitHub does, without needing 2 spaces at the end of the line (since v1.5.1)
|
||||||
|
|
||||||
|
```md
|
||||||
|
a line
|
||||||
|
wrapped in two
|
||||||
|
```
|
||||||
|
|
||||||
|
turns into:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<p>a line<br>
|
||||||
|
wrapped in two</p>
|
||||||
|
```
|
||||||
|
|
||||||
## Flavors
|
## Flavors
|
||||||
|
|
||||||
|
20
dist/showdown.js
vendored
20
dist/showdown.js
vendored
@ -1,4 +1,4 @@
|
|||||||
;/*! showdown 25-11-2016 */
|
;/*! showdown 30-11-2016 */
|
||||||
(function(){
|
(function(){
|
||||||
/**
|
/**
|
||||||
* Created by Tivie on 13-07-2015.
|
* Created by Tivie on 13-07-2015.
|
||||||
@ -82,6 +82,11 @@ function getDefaultOpts(simple) {
|
|||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
description: 'Disables the requirement of indenting nested sublists by 4 spaces',
|
description: 'Disables the requirement of indenting nested sublists by 4 spaces',
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
|
},
|
||||||
|
simpleLineBreaks: {
|
||||||
|
defaultValue: false,
|
||||||
|
description: 'Parses simple line breaks as <br> (GFM Style)',
|
||||||
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (simple === false) {
|
if (simple === false) {
|
||||||
@ -116,7 +121,8 @@ var showdown = {},
|
|||||||
tablesHeaderId: true,
|
tablesHeaderId: true,
|
||||||
ghCodeBlocks: true,
|
ghCodeBlocks: true,
|
||||||
tasklists: true,
|
tasklists: true,
|
||||||
disableForced4SpacesIndentedSublists: true
|
disableForced4SpacesIndentedSublists: true,
|
||||||
|
simpleLineBreaks: true
|
||||||
},
|
},
|
||||||
vanilla: getDefaultOpts(true)
|
vanilla: getDefaultOpts(true)
|
||||||
};
|
};
|
||||||
@ -2213,8 +2219,14 @@ showdown.subParser('spanGamut', function (text, options, globals) {
|
|||||||
text = showdown.subParser('italicsAndBold')(text, options, globals);
|
text = showdown.subParser('italicsAndBold')(text, options, globals);
|
||||||
text = showdown.subParser('strikethrough')(text, options, globals);
|
text = showdown.subParser('strikethrough')(text, options, globals);
|
||||||
|
|
||||||
// Do hard breaks:
|
// Do hard breaks
|
||||||
text = text.replace(/ +\n/g, ' <br />\n');
|
|
||||||
|
// GFM style hard breaks
|
||||||
|
if (options.simpleLineBreaks) {
|
||||||
|
text = text.replace(/\n/g, '<br />\n');
|
||||||
|
} else {
|
||||||
|
text = text.replace(/ +\n/g, '<br />\n');
|
||||||
|
}
|
||||||
|
|
||||||
text = globals.converter._dispatch('spanGamut.after', text, options, globals);
|
text = globals.converter._dispatch('spanGamut.after', text, options, globals);
|
||||||
return text;
|
return text;
|
||||||
|
2
dist/showdown.js.map
vendored
2
dist/showdown.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/showdown.min.js
vendored
4
dist/showdown.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/showdown.min.js.map
vendored
2
dist/showdown.min.js.map
vendored
File diff suppressed because one or more lines are too long
@ -80,6 +80,11 @@ function getDefaultOpts(simple) {
|
|||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
description: 'Disables the requirement of indenting nested sublists by 4 spaces',
|
description: 'Disables the requirement of indenting nested sublists by 4 spaces',
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
|
},
|
||||||
|
simpleLineBreaks: {
|
||||||
|
defaultValue: false,
|
||||||
|
description: 'Parses simple line breaks as <br> (GFM Style)',
|
||||||
|
type: 'boolean'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (simple === false) {
|
if (simple === false) {
|
||||||
|
@ -18,7 +18,8 @@ var showdown = {},
|
|||||||
tablesHeaderId: true,
|
tablesHeaderId: true,
|
||||||
ghCodeBlocks: true,
|
ghCodeBlocks: true,
|
||||||
tasklists: true,
|
tasklists: true,
|
||||||
disableForced4SpacesIndentedSublists: true
|
disableForced4SpacesIndentedSublists: true,
|
||||||
|
simpleLineBreaks: true
|
||||||
},
|
},
|
||||||
vanilla: getDefaultOpts(true)
|
vanilla: getDefaultOpts(true)
|
||||||
};
|
};
|
||||||
|
@ -23,8 +23,14 @@ showdown.subParser('spanGamut', function (text, options, globals) {
|
|||||||
text = showdown.subParser('italicsAndBold')(text, options, globals);
|
text = showdown.subParser('italicsAndBold')(text, options, globals);
|
||||||
text = showdown.subParser('strikethrough')(text, options, globals);
|
text = showdown.subParser('strikethrough')(text, options, globals);
|
||||||
|
|
||||||
// Do hard breaks:
|
// Do hard breaks
|
||||||
text = text.replace(/ +\n/g, ' <br />\n');
|
|
||||||
|
// GFM style hard breaks
|
||||||
|
if (options.simpleLineBreaks) {
|
||||||
|
text = text.replace(/\n/g, '<br />\n');
|
||||||
|
} else {
|
||||||
|
text = text.replace(/ +\n/g, '<br />\n');
|
||||||
|
}
|
||||||
|
|
||||||
text = globals.converter._dispatch('spanGamut.after', text, options, globals);
|
text = globals.converter._dispatch('spanGamut.after', text, options, globals);
|
||||||
return text;
|
return text;
|
||||||
|
2
test/features/#206.treat-single-line-breaks-as-br.html
Normal file
2
test/features/#206.treat-single-line-breaks-as-br.html
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<p>a simple<br />
|
||||||
|
wrapped line</p>
|
2
test/features/#206.treat-single-line-breaks-as-br.md
Normal file
2
test/features/#206.treat-single-line-breaks-as-br.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
a simple
|
||||||
|
wrapped line
|
@ -1,2 +1,2 @@
|
|||||||
<p>A first sentence <br />
|
<p>A first sentence<br />
|
||||||
and a line break.</p>
|
and a line break.</p>
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
<p>A first sentence <br />
|
<p>A first sentence<br />
|
||||||
and a line break.</p>
|
and a line break.</p>
|
||||||
|
@ -35,6 +35,8 @@ describe('makeHtml() features testsuite', function () {
|
|||||||
converter = new showdown.Converter({simplifiedAutoLink: true});
|
converter = new showdown.Converter({simplifiedAutoLink: true});
|
||||||
} else if (testsuite[i].name === 'disableForced4SpacesIndentedSublists') {
|
} else if (testsuite[i].name === 'disableForced4SpacesIndentedSublists') {
|
||||||
converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true});
|
converter = new showdown.Converter({disableForced4SpacesIndentedSublists: true});
|
||||||
|
} else if (testsuite[i].name === '#206.treat-single-line-breaks-as-br') {
|
||||||
|
converter = new showdown.Converter({simpleLineBreaks: true});
|
||||||
} else {
|
} else {
|
||||||
converter = new showdown.Converter();
|
converter = new showdown.Converter();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user