Browse Source

Added `breaks` option, on by default

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
f13f984335
  1. 18
      README.md
  2. 4
      lib/defaults.js
  3. 39
      lib/lexer_inline/newline.js
  4. 5
      lib/renderer.js
  5. 1
      test/remarkable.js
  6. 1
      test/remarked.js
  7. 1
      test/stmd.js

18
README.md

@ -34,7 +34,12 @@ Usage
```javascript ```javascript
var Remarkable = require('remarkable')(); var Remarkable = require('remarkable')();
var md = new Remarkable(/* options */); var md = new Remarkable({
html: false,
xhtml: false,
breaks: true,
langprefix: 'language-'
});
console.log(md.parse('# Remarkable rulezz!')); console.log(md.parse('# Remarkable rulezz!'));
//=> <h1># Remarkable rulezz!</h1> //=> <h1># Remarkable rulezz!</h1>
@ -47,13 +52,10 @@ var Remarkable = require('remarkable');
var md = new Remarkable(); var md = new Remarkable();
md.set({ md.set({
gfm: true, html: false,
tables: true, xhtml: false,
breaks: false, breaks: true,
pedantic: false, langprefix: 'language-'
sanitize: true,
smartLists: true,
smartypants: false
}); });
``` ```

4
lib/defaults.js

@ -4,10 +4,8 @@
module.exports = { module.exports = {
blocksep: '\n',
innersep: '\n',
softbreak: '\n',
html: false, html: false,
xhtml: false, xhtml: false,
breaks: true,
langprefix: 'language-' langprefix: 'language-'
}; };

39
lib/lexer_inline/newline.js

@ -9,30 +9,31 @@ module.exports = function escape(state) {
max = state.posMax; max = state.posMax;
// ' \n' -> hardbreak // ' \n' -> hardbreak
if (pmax >= 1 && // Lookup in pending chars is bad practice! Don't copy to other rules!
state.pending.charCodeAt(pmax) === 0x20 && // Pending string is stored in concat mode, indexed lookups will cause
state.pending.charCodeAt(pmax - 1) === 0x20) { // convertion to flat mode.
state.pending = state.pending.replace(/ +$/, ''); if (pmax >= 0 && state.pending.charCodeAt(pmax) === 0x20) {
if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 0x20) {
state.pending = state.pending.replace(/ +$/, '');
state.push({
type: 'hardbreak'
});
} else {
state.pending = state.pending.slice(0, -1);
state.push({
type: 'softbreak'
});
}
} else {
state.push({ state.push({
type: 'hardbreak' type: 'softbreak'
}); });
pos++;
// skip spaces
while (pos < max && state.src.charCodeAt(pos) === 0x20) { pos++; }
state.pos = pos;
return true;
}
if (pmax > 0 && state.pending.charCodeAt(pmax) === 0x20) {
state.pending = state.pending.replace(/ +$/, '');
} }
state.pending += '\n';
pos++; pos++;
// skip spaces
// skip heading spaces for next line
while (pos < max && state.src.charCodeAt(pos) === 0x20) { pos++; } while (pos < max && state.src.charCodeAt(pos) === 0x20) { pos++; }
state.pos = pos; state.pos = pos;

5
lib/renderer.js

@ -154,7 +154,10 @@ rules.em_close = function(/*tokens, idx, options*/) {
rules.hardbreak = function (tokens, idx, options) { rules.hardbreak = function (tokens, idx, options) {
return (options.xhtml ? '<br />' : '<br>') + '\n'; return options.xhtml ? '<br />\n' : '<br>\n';
};
rules.softbreak = function (tokens, idx, options) {
return options.breaks ? (options.xhtml ? '<br />\n' : '<br>\n') : '\n';
}; };

1
test/remarkable.js

@ -11,6 +11,7 @@ var Remarked = require('../');
describe('Default', function () { describe('Default', function () {
var md = new Remarked({ var md = new Remarked({
breaks: false,
langprefix: '' langprefix: ''
}); });

1
test/remarked.js

@ -14,6 +14,7 @@ describe('remarked', function () {
// Set options, to give output more close to remarked // Set options, to give output more close to remarked
md.set({ md.set({
breaks: false,
langprefix: 'lang-' langprefix: 'lang-'
}); });

1
test/stmd.js

@ -13,6 +13,7 @@ describe('stmd', function () {
var md = new Remarked({ var md = new Remarked({
html: true, html: true,
xhtml: true, xhtml: true,
breaks: false,
langprefix: 'language-' langprefix: 'language-'
}); });

Loading…
Cancel
Save