Skip to content

Commit

Permalink
API & options names polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Sep 17, 2014
1 parent 5d89fd8 commit c384f13
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bin/specsplit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ readFile(options.spec, 'utf8', function (error, input) {
markdown = new Remarkable({
html: true,
xhtml: true,
codeLangPrefix: 'language-'
langprefix: 'language-'
});

if (error) {
Expand Down
13 changes: 13 additions & 0 deletions lib/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Default options

'use strict';


module.exports = {
blocksep: '\n',
innersep: '\n',
softbreak: '\n',
html: false,
xhtml: false,
langprefix: 'language-'
};
4 changes: 2 additions & 2 deletions lib/lexer_block/blockquote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/lexer_block/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/lexer_block/paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions lib/lexer_block/state_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
);
Expand Down
5 changes: 0 additions & 5 deletions lib/lexer_inline/htmltag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion test/remarkable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion test/remarked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/stmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c384f13

Please sign in to comment.