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
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!'));
//=> <h1># Remarkable rulezz!</h1>
@ -47,13 +52,10 @@ var Remarkable = require('remarkable');
var md = new Remarkable();
md.set({
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
html: false,
xhtml: false,
breaks: true,
langprefix: 'language-'
});
```

4
lib/defaults.js

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

39
lib/lexer_inline/newline.js

@ -9,30 +9,31 @@ module.exports = function escape(state) {
max = state.posMax;
// ' \n' -> hardbreak
if (pmax >= 1 &&
state.pending.charCodeAt(pmax) === 0x20 &&
state.pending.charCodeAt(pmax - 1) === 0x20) {
state.pending = state.pending.replace(/ +$/, '');
// Lookup in pending chars is bad practice! Don't copy to other rules!
// Pending string is stored in concat mode, indexed lookups will cause
// convertion to flat mode.
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({
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++;
// skip spaces
// skip heading spaces for next line
while (pos < max && state.src.charCodeAt(pos) === 0x20) { 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) {
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 () {
var md = new Remarked({
breaks: false,
langprefix: ''
});

1
test/remarked.js

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

1
test/stmd.js

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

Loading…
Cancel
Save