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) { module.exports = function typographer(state) {
if (!state.options.typographer) { return; } if (!state.options.typographer) { return; }
var tokens = state.tokens, tok, i, l;
// Parse inlines state.typographer.process(state);
for (i = 0, l = tokens.length; i < l; i++) {
tok = tokens[i];
if (tok.type === 'inline') {
state.typographer.process(tok, state);
}
}
}; };

17
lib/rules_text/replace.js

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

Loading…
Cancel
Save