Browse Source

API & options names polish

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
c384f13798
  1. 2
      bin/specsplit.js
  2. 13
      lib/defaults.js
  3. 4
      lib/lexer_block/blockquote.js
  4. 4
      lib/lexer_block/list.js
  5. 2
      lib/lexer_block/paragraph.js
  6. 6
      lib/lexer_block/state_block.js
  7. 5
      lib/lexer_inline/htmltag.js
  8. 16
      lib/parser.js
  9. 2
      lib/renderer.js
  10. 4
      test/remarkable.js
  11. 2
      test/remarked.js
  12. 2
      test/stmd.js

2
bin/specsplit.js

@ -60,7 +60,7 @@ readFile(options.spec, 'utf8', function (error, input) {
markdown = new Remarkable({
html: true,
xhtml: true,
codeLangPrefix: 'language-'
langprefix: 'language-'
});
if (error) {

13
lib/defaults.js

@ -0,0 +1,13 @@
// Default options
'use strict';
module.exports = {
blocksep: '\n',
innersep: '\n',
softbreak: '\n',
html: false,
xhtml: false,
langprefix: 'language-'
};

4
lib/lexer_block/blockquote.js

@ -8,7 +8,7 @@ var skipSpaces = require('../helpers').skipSpaces;
module.exports = function blockquote(state, startLine, endLine, silent) {
var nextLine, lastLineEmpty, oldTShift, oldBMarks, i, oldIndent,
rules_named = state.lexerBlock.rules_named,
rules_named = state.lexer.rules_named,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
@ -104,7 +104,7 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
}
state.tokens.push({ type: 'blockquote_open' });
state.lexerBlock.tokenize(state, startLine, nextLine);
state.lexer.tokenize(state, startLine, nextLine);
state.tokens.push({ type: 'blockquote_close' });
// Restore original tShift; this might not be necessary since the parser

4
lib/lexer_block/list.js

@ -89,7 +89,7 @@ module.exports = function list(state, startLine, endLine, silent) {
contentStart,
listTokIdx,
prevEmptyEnd,
rules_named = state.lexerBlock.rules_named;
rules_named = state.lexer.rules_named;
// Detect list type and position after marker
if ((posAfterMarker = skipOrderedListMarker(state, startLine)) >= 0) {
@ -167,7 +167,7 @@ module.exports = function list(state, startLine, endLine, silent) {
state.blkIndent = indent;
state.tight = true;
state.lexerBlock.tokenize(state, startLine, endLine, true);
state.lexer.tokenize(state, startLine, endLine, true);
// If any of list item is tight, mark list as tight
if (!state.tight || prevEmptyEnd) {

2
lib/lexer_block/paragraph.js

@ -10,7 +10,7 @@ var getLines = require('../helpers').getLines;
module.exports = function paragraph(state, startLine/*, endLine*/) {
var endLine,
nextLine = startLine + 1,
rules_named = state.lexerBlock.rules_named;
rules_named = state.lexer.rules_named;
endLine = state.lineMax;

6
lib/lexer_block/state_block.js

@ -3,7 +3,7 @@
'use strict';
function State(src, lexerBlock, tokens, options) {
function State(src, lexer, tokens, options) {
var ch, s, start, pos, len, indent, indent_found;
// TODO: check if we can move string replaces to parser, to avoid
@ -18,7 +18,7 @@ function State(src, lexerBlock, tokens, options) {
this.src = src;
// Shortcuts to simplify nested calls
this.lexerBlock = lexerBlock;
this.lexer = lexer;
// TODO: (?) set directly for faster access.
this.options = options;
@ -100,7 +100,7 @@ function State(src, lexerBlock, tokens, options) {
State.prototype.clone = function clone(src) {
return new State(
src,
this.lexerBlock,
this.lexer,
this.tokens,
this.options
);

5
lib/lexer_inline/htmltag.js

@ -33,15 +33,10 @@ module.exports = function htmltag(state) {
!isLetter(ch)) {
return false;
}
// console.log(HTML_TAG_RE)
match = state.src.slice(pos).match(HTML_TAG_RE);
if (!match) { return false; }
// console.log('--------')
// console.log(state.src.slice(pos))
// console.log(match)
state.push({
type: 'htmltag',
content: state.src.slice(pos, pos + match[0].length)

16
lib/parser.js

@ -9,17 +9,17 @@ var assign = require('object-assign');
var Renderer = require('./renderer');
var LexerBlock = require('./lexer_block');
var LexerInline = require('./lexer_inline');
var defaults = require('./defaults');
// Main class
//
function Parser(options) {
this.options = {};
this.state = null;
this.options = assign({}, defaults);
this.state = null;
this.lexerInline = new LexerInline();
this.lexerBlock = new LexerBlock();
this.renderer = new Renderer();
this.inline = new LexerInline();
this.block = new LexerBlock();
this.renderer = new Renderer();
if (options) { this.set(options); }
}
@ -34,13 +34,13 @@ Parser.prototype.render = function (src) {
var tokens, tok, i, l;
// Parse blocks
tokens = this.lexerBlock.parse(src, this.options);
tokens = this.block.parse(src, this.options);
// Parse inlines
for (i = 0, l = tokens.length; i < l; i++) {
tok = tokens[i];
if (tok.type === 'inline') {
tok.children = this.lexerInline.parse(tok.content, this.options);
tok.children = this.inline.parse(tok.content, this.options);
}
}

2
lib/renderer.js

@ -41,7 +41,7 @@ rules.code = function (tokens, idx /*, options*/) {
rules.fence = function (tokens, idx, options) {
var token = tokens[idx];
var langMark = '';
var langPrefix = options.codeLangPrefix || '';
var langPrefix = options.langprefix || '';
var params;
if (token.params) {

4
test/remarkable.js

@ -10,7 +10,9 @@ var Remarked = require('../');
describe('Default', function () {
var md = new Remarked();
var md = new Remarked({
langprefix: ''
});
utils.addTests(path.join(__dirname, 'fixtures/remarkable'), md);
});

2
test/remarked.js

@ -14,7 +14,7 @@ describe('remarked', function () {
// Set options, to give output more close to remarked
md.set({
codeLangPrefix: 'lang-'
langprefix: 'lang-'
});
utils.addTests(path.join(__dirname, 'fixtures/remarked_ok'), md);

2
test/stmd.js

@ -13,7 +13,7 @@ describe('stmd', function () {
var md = new Remarked({
html: true,
xhtml: true,
codeLangPrefix: 'language-'
langprefix: 'language-'
});
utils.addSpecTests(path.join(__dirname, 'fixtures/stmd/good.txt'), md);

Loading…
Cancel
Save