Skip to content

Commit

Permalink
fix(Formatter): Don't strip whitespace in preformat
Browse files Browse the repository at this point in the history
In preformatted text, white space should be retained
  • Loading branch information
yamikuronue committed Nov 29, 2016
1 parent f980710 commit cc414dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions providers/nodebb/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,14 @@ exports.header6 = function header6(text) {
* @param {!string} text The text
* @returns {string} Text in a preformat block
*/
/* eslint-disable prefer-template */
exports.preformat = function preformat(text) {
if (text.indexOf('\n') > -1) {
return prefixifier('```\n', text, '\n```');
return '```\n' + text + '\n```';
}
return prefixifier('`', text, '`');
return '`' + text + '`';
};
/* eslint-enable prefer-template */

/**
* Format text with a strikethrough effect
Expand Down
4 changes: 4 additions & 0 deletions test/providers/nodebb/formatTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,10 @@ describe('providers/nodebb/format', () => {
const expected = '```\nline1\nline2\n```';
testModule.preformat('line1\nline2').should.equal(expected);
});
it('should retain existing whitespace', () => {
const expected = '```\n line1\n line2\n```';
testModule.preformat(' line1\n line2').should.equal(expected);
});
});
describe('strikethrough', () => {
it('should generate preformatted text in markdown', () => {
Expand Down

0 comments on commit cc414dc

Please sign in to comment.