Browse Source

Moved scans from typorgapher directly to rules

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
8294a63f8c
  1. 9
      lib/rules_core/typographer.js
  2. 17
      lib/rules_text/replace.js
  3. 16
      lib/rules_text/smartquotes.js
  4. 4
      lib/typographer.js

9
lib/rules_core/typographer.js

@ -2,13 +2,6 @@
module.exports = function typographer(state) {
if (!state.options.typographer) { return; }
var tokens = state.tokens, tok, i, l;
// Parse inlines
for (i = 0, l = tokens.length; i < l; i++) {
tok = tokens[i];
if (tok.type === 'inline') {
state.typographer.process(tok, state);
}
}
state.typographer.process(state);
};

17
lib/rules_text/replace.js

@ -6,13 +6,19 @@
var COPY_RE = /\((c|tm|r|p)\)/i;
var RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/;
module.exports = function replace(typographer, blockToken) {
var i, token, text,
tokens = blockToken.children,
module.exports = function replace(state) {
var i, token, text, inlineTokens, blkIdx,
typographer = state.typographer,
options = typographer.options;
for (i = tokens.length - 1; i >= 0; i--) {
token = tokens[i];
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) {
if (state.tokens[blkIdx].type !== 'inline') { continue; }
inlineTokens = state.tokens[blkIdx].children;
for (i = inlineTokens.length - 1; i >= 0; i--) {
token = inlineTokens[i];
if (token.type === 'text') {
text = token.content;
@ -56,4 +62,5 @@ module.exports = function replace(typographer, blockToken) {
token.content = text;
}
}
}
};

16
lib/rules_text/smartquotes.js

@ -20,14 +20,21 @@ function replaceAt(str, index, ch) {
return str.substr(0, index) + ch + str.substr(index + 1);
}
var stack = [];
module.exports = function smartquotes(typographer, blockToken) {
module.exports = function smartquotes(state) {
/*eslint max-depth:0*/
var i, token, text, t, pos, max, thisLevel, lastSpace, nextSpace, item, canOpen, canClose, j, isSingle, chars,
var i, token, text, t, pos, max, thisLevel, lastSpace, nextSpace, item,
canOpen, canClose, j, isSingle, chars, blkIdx, tokens,
typographer = state.typographer,
options = typographer.options,
tokens = blockToken.children;
stack = [];
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) {
if (state.tokens[blkIdx].type !== 'inline') { continue; }
tokens = state.tokens[blkIdx].children;
stack.length = 0;
for (i = 0; i < tokens.length; i++) {
@ -99,4 +106,5 @@ module.exports = function smartquotes(typographer, blockToken) {
}
}
}
}
};

4
lib/typographer.js

@ -33,13 +33,13 @@ Typographer.prototype.set = function (options) {
};
Typographer.prototype.process = function (token) {
Typographer.prototype.process = function (state) {
var i, l, rules;
rules = this.ruler.getRules('');
for (i = 0, l = rules.length; i < l; i++) {
rules[i](this, token);
rules[i](state);
}
};

Loading…
Cancel
Save