├── .editorconfig ├── .gitignore ├── .jscsrc ├── .jshintignore ├── .jshintrc ├── .npmignore ├── README.md ├── index.js ├── package.json └── test ├── mocha.opts └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs. 2 | # More information at http://EditorConfig.org 3 | 4 | # No .editorconfig files above the root directory 5 | root = true 6 | 7 | [*] 8 | charset = utf-8 9 | indent_size = 4 10 | end_of_line = lf 11 | indent_style = space 12 | trim_trailing_whitespace = true 13 | insert_final_newline = true 14 | 15 | [*.{bemjson.js,deps.js}] 16 | indent_size = 4 17 | 18 | [{bower,package}.json] 19 | indent_size = 2 20 | 21 | [*.md] 22 | trim_trailing_whitespace = false 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS 2 | .DS_Store 3 | ._* 4 | 5 | # NODEJS 6 | node_modules 7 | npm-debug.log 8 | -------------------------------------------------------------------------------- /.jscsrc: -------------------------------------------------------------------------------- 1 | { 2 | "disallowSpacesInCallExpression": true, 3 | "disallowSpaceAfterObjectKeys": true, 4 | "disallowNewlineBeforeBlockStatements": true, 5 | "disallowMultipleLineBreaks": true, 6 | "requireSemicolons": true, 7 | "requireFunctionDeclarations": true, 8 | "requireCommaBeforeLineBreak": true, 9 | "disallowTrailingComma": true, 10 | "disallowTrailingWhitespace": true, 11 | "disallowSpacesInFunction": { 12 | "beforeOpeningRoundBrace": true 13 | }, 14 | "requireSpacesInFunction": { 15 | "beforeOpeningCurlyBrace": true 16 | }, 17 | "disallowSpacesInConditionalExpression": { 18 | "afterTest": true, 19 | "afterConsequent": true 20 | }, 21 | "excludeFiles": [ 22 | ".git/**", 23 | "node_modules/**" 24 | ], 25 | "fileExtensions": [".js"] 26 | } 27 | -------------------------------------------------------------------------------- /.jshintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "eqeqeq": true, 3 | "expr": true, 4 | "maxlen": 120, 5 | "undef": true, 6 | "unused": true, 7 | "node": true 8 | } 9 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test/ 3 | npm-debug.log 4 | .editorconfig 5 | .jscsrc 6 | .jshintignore 7 | .jshintrc 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PostHTML-Textr 2 | [![npm version](https://badge.fury.io/js/posthtml-textr.svg)](http://badge.fury.io/js/posthtml-textr) 3 | 4 | [PostHTML](http://github.com/posthtml/posthtml) plugin wrapper over [Textr](http://a.github.io/textr) modular typographic framework 5 | 6 | ## Usage 7 | 8 | ```js 9 | var posthtml = require('posthtml'), 10 | html = '

Hello "world"...\n

foo...bar

'; 11 | 12 | posthtml() 13 | .use(require('posthtml-textr')( 14 | { locale: 'ru'}, 15 | [ 16 | require('typographic-ellipses'), 17 | require('typographic-single-spaces'), 18 | require('typographic-quotes') 19 | ] 20 | )) 21 | .process(html) 22 | .then(function(result) { 23 | console.log(result.html); 24 | //

Hello «world»…

foo…bar

25 | }) 26 | ``` 27 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = function(options, plugins) { 2 | options = options || {}; 3 | plugins = [].concat(plugins) || []; 4 | 5 | var tr = require('textr')(options); 6 | 7 | plugins.forEach(function(plugin) { 8 | tr.use(plugin); 9 | }); 10 | 11 | return function posthtmlTextr(tree) { 12 | tree.walk(function(node) { 13 | if(typeof(node) === 'string' && !/^\n\s*$/.test(node)) { 14 | return tr(node); 15 | } 16 | return node; 17 | }); 18 | return tree; 19 | }; 20 | }; 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "posthtml-textr", 3 | "version": "1.0.5", 4 | "description": "Textr PostHTML plugin", 5 | "main": "index.js", 6 | "dependencies": { 7 | "textr": "^0.3.0" 8 | }, 9 | "devDependencies": { 10 | "chai": "^3.2.0", 11 | "jscs": "^1.13.1", 12 | "jshint": "^2.8.0", 13 | "mocha": "^2.2.5", 14 | "posthtml": "^0.2.0", 15 | "typographic-quotes": "^1.2.1" 16 | }, 17 | "scripts": { 18 | "test": "npm run lint && mocha", 19 | "lint": "jshint . && jscs . -v" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "git+https://github.com/voischev/posthtml-textr.git" 24 | }, 25 | "keywords": [ 26 | "html", 27 | "xml", 28 | "textr", 29 | "text", 30 | "format", 31 | "typography", 32 | "postproccessor", 33 | "parser", 34 | "transform", 35 | "manipulation", 36 | "plugin", 37 | "posthtml", 38 | "posthtml-plugin" 39 | ], 40 | "author": "Ivan Voischev ", 41 | "license": "MIT", 42 | "bugs": { 43 | "url": "https://github.com/voischev/posthtml-textr/issues" 44 | }, 45 | "homepage": "https://github.com/voischev/posthtml-textr#readme" 46 | } 47 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --inline-diffs 2 | --reporter spec 3 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | /* jshint mocha: true, maxlen: false */ 2 | var ptextr = require('..'); 3 | var posthtml = require('posthtml'); 4 | var expect = require('chai').expect; 5 | 6 | function test(input, output, options, plugins, done) { 7 | posthtml() 8 | .use(ptextr(options, plugins)) 9 | .process(input) 10 | .then(function(result) { 11 | expect(output).to.eql(result.html); 12 | done(); 13 | }).catch(function(error) { 14 | done(error); 15 | }); 16 | } 17 | 18 | describe('Textr test', function() { 19 | it('plugins', function(done) { 20 | test( 21 | '

Hello "world"

', 22 | '

Hello «world»

', 23 | { locale: 'ru'}, 24 | [require('typographic-quotes')], 25 | done 26 | ); 27 | }); 28 | }); 29 | --------------------------------------------------------------------------------