├── .editorconfig
├── .gitignore
├── .jscsrc
├── .jshintignore
├── .jshintrc
├── .npmignore
├── README.md
├── index.js
├── package.json
└── test
├── input.html
├── mocha.opts
├── output.html
└── 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-Retext
2 | [](http://badge.fury.io/js/posthtml-retext)
3 |
4 | [PostHTML](http://github.com/posthtml/posthtml) plugin wrapper over [Retext](https://github.com/wooorm/retext) extensible system for analysing and manipulating natural language
5 |
6 | ## Usage
7 |
8 | ```js
9 | var fs = require('fs'),
10 | posthtml = require('posthtml'),
11 | html = fs.readFileSync('path/to/file.html');
12 |
13 | posthtml()
14 | .use(require('posthtml-retext')([
15 | [require('retext-emoji'), { convert: 'encode' }], // Array if plugin has options
16 | require('retext-smartypants')
17 | ]))
18 | .process(html)
19 | .then(function(result) {
20 | fs.writeFileSync('path/to/file.html');
21 | })
22 | ```
23 |
24 | #### Input html
25 |
26 | ```html
27 |
28 |
29 |
30 | Hello "world"...
31 | The three wise monkeys [. . .] sometimes called the three mystic
32 | apes--are a pictorial maxim. Together they embody the proverbial
33 | principle to ("see no evil, hear no evil, speak no evil"). The
34 | three monkeys are Mizaru (:see_no_evil:), covering his eyes, who
35 | sees no evil; Kikazaru (:hear_no_evil:), covering his ears, who
36 | hears no evil; and Iwazaru (:speak_no_evil:), covering his mouth,
37 | who speaks no evil.
38 |
39 |
40 |
41 | ```
42 |
43 | #### Output html
44 |
45 | ```html
46 |
47 |
48 |
49 | Hello “world”…
50 | The three wise monkeys […] sometimes called the three mystic
51 | apes—are a pictorial maxim. Together they embody the proverbial
52 | principle to (“see no evil, hear no evil, speak no evil”). The
53 | three monkeys are Mizaru (🙈), covering his eyes, who
54 | sees no evil; Kikazaru (🙉), covering his ears, who
55 | hears no evil; and Iwazaru (🙊), covering his mouth,
56 | who speaks no evil.
57 |
58 |
59 |
60 | ```
61 |
62 | ## License
63 | MIT
64 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | var toTree = require('posthtml/lib/parser').toTree;
2 | var retext = require('retext')();
3 |
4 | module.exports = function(plugins) {
5 |
6 | plugins.forEach(function(plugin) {
7 | Array.isArray(plugin)?
8 | retext.use.apply(retext, plugin):
9 | retext.use(plugin);
10 | });
11 |
12 | return function posthtmlRetext(tree) {
13 | tree.walk(function(node) {
14 | if(typeof node === 'string' && !/^\n\s*$/.test(node)) {
15 | return toTree(retext.process(node))[0];
16 | }
17 | return node;
18 | });
19 | return tree;
20 | };
21 | };
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "posthtml-retext",
3 | "version": "0.1.0",
4 | "description": "Retext PostHTML plugin",
5 | "main": "index.js",
6 | "dependencies": {
7 | "retext": "^1.0.0",
8 | "posthtml": "^0.4.1"
9 | },
10 | "devDependencies": {
11 | "chai": "^3.2.0",
12 | "jscs": "^1.13.1",
13 | "jshint": "^2.8.0",
14 | "mocha": "^2.2.5",
15 | "retext-emoji": "^1.0.0",
16 | "retext-smartypants": "^1.0.0"
17 | },
18 | "scripts": {
19 | "test": "npm run lint && mocha",
20 | "lint": "jshint . && jscs . -v"
21 | },
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/voischev/posthtml-retext.git"
25 | },
26 | "keywords": [
27 | "analyse",
28 | "format",
29 | "html",
30 | "language",
31 | "manipulate",
32 | "manipulation",
33 | "natural",
34 | "nlcst",
35 | "parser",
36 | "plugin",
37 | "posthtml",
38 | "posthtml-plugin",
39 | "postproccessor",
40 | "retext",
41 | "text",
42 | "transform",
43 | "typography",
44 | "xml"
45 | ],
46 | "author": "Ivan Voischev ",
47 | "license": "MIT",
48 | "bugs": {
49 | "url": "https://github.com/voischev/posthtml-retext/issues"
50 | },
51 | "homepage": "https://github.com/voischev/posthtml-retext#readme"
52 | }
53 |
--------------------------------------------------------------------------------
/test/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello "world"...
5 | The three wise monkeys [. . .] sometimes called the three mystic
6 | apes--are a pictorial maxim. Together they embody the proverbial
7 | principle to ("see no evil, hear no evil, speak no evil"). The
8 | three monkeys are Mizaru (:see_no_evil:), covering his eyes, who
9 | sees no evil; Kikazaru (:hear_no_evil:), covering his ears, who
10 | hears no evil; and Iwazaru (:speak_no_evil:), covering his mouth,
11 | who speaks no evil.
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test/mocha.opts:
--------------------------------------------------------------------------------
1 | --inline-diffs
2 | --reporter spec
3 |
--------------------------------------------------------------------------------
/test/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello “world”…
5 | The three wise monkeys […] sometimes called the three mystic
6 | apes—are a pictorial maxim. Together they embody the proverbial
7 | principle to (“see no evil, hear no evil, speak no evil”). The
8 | three monkeys are Mizaru (🙈), covering his eyes, who
9 | sees no evil; Kikazaru (🙉), covering his ears, who
10 | hears no evil; and Iwazaru (🙊), covering his mouth,
11 | who speaks no evil.
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/test/test.js:
--------------------------------------------------------------------------------
1 | /* jshint mocha: true, maxlen: false */
2 | var pretext = require('..');
3 | var posthtml = require('posthtml');
4 | var fs = require('fs');
5 | var expect = require('chai').expect;
6 |
7 | function test(input, output, plugins, done) {
8 | posthtml()
9 | .use(pretext(plugins))
10 | .process(input)
11 | .then(function(result) {
12 | expect(output).to.eql(result.html);
13 | done();
14 | }).catch(function(error) {
15 | done(error);
16 | });
17 | }
18 |
19 | describe('Retext test', function() {
20 | it('plugins', function(done) {
21 | test(
22 | fs.readFileSync('./test/input.html', 'utf-8').toString(),
23 | fs.readFileSync('./test/output.html', 'utf-8').toString(),
24 | [[require('retext-emoji'), { 'convert': 'encode' }], require('retext-smartypants')],
25 | done
26 | );
27 | });
28 | });
29 |
--------------------------------------------------------------------------------