Browse Source

Bulk rules rename (unify)

pull/25/head
Vitaly Puzrin 10 years ago
parent
commit
90e5a9c9cc
  1. 4
      lib/parser_block.js
  2. 4
      lib/parser_inline.js
  3. 8
      lib/presets/commonmark.js
  4. 13
      lib/renderer.js
  5. 3
      lib/rules_block/code.js
  6. 2
      lib/rules_block/fence.js
  7. 4
      lib/rules_block/html_block.js
  8. 2
      lib/rules_core/linkify.js
  9. 5
      lib/rules_inline/backtick.js
  10. 4
      lib/rules_inline/html_inline.js
  11. 4
      test/misc.js

4
lib/parser_block.js

@ -11,14 +11,14 @@ var Ruler = require('./ruler');
var _rules = [
[ 'code', require('./rules_block/code') ],
[ 'fences', require('./rules_block/fences'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
[ 'fence', require('./rules_block/fence'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
[ 'blockquote', require('./rules_block/blockquote'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
[ 'hr', require('./rules_block/hr'), [ 'paragraph', 'reference', 'blockquote', 'list' ] ],
[ 'list', require('./rules_block/list'), [ 'paragraph', 'reference', 'blockquote' ] ],
[ 'reference', require('./rules_block/reference'), [ 'reference' ] ],
[ 'heading', require('./rules_block/heading'), [ 'paragraph', 'reference', 'blockquote' ] ],
[ 'lheading', require('./rules_block/lheading') ],
[ 'htmlblock', require('./rules_block/htmlblock'), [ 'paragraph', 'reference', 'blockquote' ] ],
[ 'html_block', require('./rules_block/html_block'), [ 'paragraph', 'reference', 'blockquote' ] ],
[ 'table', require('./rules_block/table'), [ 'paragraph', 'reference' ] ],
[ 'paragraph', require('./rules_block/paragraph') ]
];

4
lib/parser_inline.js

@ -16,13 +16,13 @@ var _rules = [
[ 'text', require('./rules_inline/text') ],
[ 'newline', require('./rules_inline/newline') ],
[ 'escape', require('./rules_inline/escape') ],
[ 'backticks', require('./rules_inline/backticks') ],
[ 'backtick', require('./rules_inline/backtick') ],
[ 'del', require('./rules_inline/del') ],
[ 'emphasis', require('./rules_inline/emphasis') ],
[ 'link', require('./rules_inline/link') ],
[ 'image', require('./rules_inline/image') ],
[ 'autolink', require('./rules_inline/autolink') ],
[ 'htmltag', require('./rules_inline/htmltag') ],
[ 'html_inline', require('./rules_inline/html_inline') ],
[ 'entity', require('./rules_inline/entity') ]
];

8
lib/presets/commonmark.js

@ -41,10 +41,10 @@ module.exports = {
rules: [
'blockquote',
'code',
'fences',
'fence',
'heading',
'hr',
'htmlblock',
'html_block',
'lheading',
'list',
'reference',
@ -55,11 +55,11 @@ module.exports = {
inline: {
rules: [
'autolink',
'backticks',
'backtick',
'emphasis',
'entity',
'escape',
'htmltag',
'html_inline',
'image',
'link',
'newline',

13
lib/renderer.js

@ -28,11 +28,10 @@ rules.blockquote_close = function (/* tokens, idx, options, env */) {
};
rules.code = function (tokens, idx /*, options, env */) {
if (tokens[idx].block) {
return '<pre><code>' + escapeHtml(tokens[idx].content) + '</code></pre>\n';
}
rules.code_block = function (tokens, idx /*, options, env */) {
return '<pre><code>' + escapeHtml(tokens[idx].content) + '</code></pre>\n';
};
rules.code_inline = function (tokens, idx /*, options, env */) {
return '<code>' + escapeHtml(tokens[idx].content) + '</code>';
};
@ -223,10 +222,10 @@ rules.text = function (tokens, idx /*, options, env */) {
};
rules.htmlblock = function (tokens, idx /*, options, env */) {
rules.html_block = function (tokens, idx /*, options, env */) {
return tokens[idx].content;
};
rules.htmltag = function (tokens, idx /*, options, env */) {
rules.html_inline = function (tokens, idx /*, options, env */) {
return tokens[idx].content;
};

3
lib/rules_block/code.js

@ -25,9 +25,8 @@ module.exports = function code(state, startLine, endLine/*, silent*/) {
state.line = nextLine;
state.tokens.push({
type: 'code',
type: 'code_block',
content: state.getLines(startLine, last, 4 + state.blkIndent, true),
block: true,
lines: [ startLine, state.line ],
level: state.level
});

2
lib/rules_block/fences.js → lib/rules_block/fence.js

@ -3,7 +3,7 @@
'use strict';
module.exports = function fences(state, startLine, endLine, silent) {
module.exports = function fence(state, startLine, endLine, silent) {
var marker, len, params, nextLine, mem,
haveEndMarker = false,
pos = state.bMarks[startLine] + state.tShift[startLine],

4
lib/rules_block/htmlblock.js → lib/rules_block/html_block.js

@ -15,7 +15,7 @@ function isLetter(ch) {
return (lc >= 0x61/* a */) && (lc <= 0x7a/* z */);
}
module.exports = function htmlblock(state, startLine, endLine, silent) {
module.exports = function html_block(state, startLine, endLine, silent) {
var ch, match, nextLine,
pos = state.bMarks[startLine],
max = state.eMarks[startLine],
@ -64,7 +64,7 @@ module.exports = function htmlblock(state, startLine, endLine, silent) {
state.line = nextLine;
state.tokens.push({
type: 'htmlblock',
type: 'html_block',
level: state.level,
lines: [ startLine, state.line ],
content: state.getLines(startLine, nextLine, 0, true)

2
lib/rules_core/linkify.js

@ -86,7 +86,7 @@ module.exports = function linkify(state) {
}
// Skip content of html tag links
if (token.type === 'htmltag') {
if (token.type === 'html_inline') {
if (isLinkOpen(token.content) && htmlLinkLevel > 0) {
htmlLinkLevel--;
}

5
lib/rules_inline/backticks.js → lib/rules_inline/backtick.js

@ -2,7 +2,7 @@
'use strict';
module.exports = function backticks(state, silent) {
module.exports = function backtick(state, silent) {
var start, max, marker, matchStart, matchEnd,
pos = state.pos,
ch = state.src.charCodeAt(pos);
@ -27,11 +27,10 @@ module.exports = function backticks(state, silent) {
if (matchEnd - matchStart === marker.length) {
if (!silent) {
state.push({
type: 'code',
type: 'code_inline',
content: state.src.slice(pos, matchStart)
.replace(/[ \n]+/g, ' ')
.trim(),
block: false,
level: state.level
});
}

4
lib/rules_inline/htmltag.js → lib/rules_inline/html_inline.js

@ -14,7 +14,7 @@ function isLetter(ch) {
}
module.exports = function htmltag(state, silent) {
module.exports = function html_inline(state, silent) {
var ch, match, max, content, pos = state.pos;
if (!state.md.options.html) { return false; }
@ -47,7 +47,7 @@ module.exports = function htmltag(state, silent) {
if (!silent) {
state.push({
type: 'htmltag',
type: 'html_inline',
content: content,
level: state.level
});

4
test/misc.js

@ -137,7 +137,7 @@ describe('API', function () {
};
// Disable 2 rule in each chain & compare result
md.disable([ 'block', 'inline', 'code', 'fences', 'emphasis', 'entity' ]);
md.disable([ 'block', 'inline', 'code', 'fence', 'emphasis', 'entity' ]);
var now = {
core: md.core.ruler.getRules('').length + 2,
@ -148,7 +148,7 @@ describe('API', function () {
assert.deepEqual(was, now);
// Enable the same rules back
md.enable([ 'block', 'inline', 'code', 'fences', 'emphasis', 'entity' ]);
md.enable([ 'block', 'inline', 'code', 'fence', 'emphasis', 'entity' ]);
var back = {
core: md.core.ruler.getRules('').length,

Loading…
Cancel
Save