mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
refactor(*): convert to babel and generation to lib, es, dist folders (#2)
* refactor(*): convert to babel and generation to lib, es, dist * chore(*): remove generated files * fix(*): lint run command
This commit is contained in:
committed by
GitHub
parent
d22a2895a4
commit
32a7fb51da
@@ -0,0 +1,86 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
"react"
|
||||||
|
],
|
||||||
|
"plugins": [
|
||||||
|
"transform-decorators-legacy",
|
||||||
|
[
|
||||||
|
"transform-es2015-template-literals",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"transform-es2015-literals",
|
||||||
|
"transform-es2015-function-name",
|
||||||
|
"transform-es2015-arrow-functions",
|
||||||
|
"transform-es2015-block-scoped-functions",
|
||||||
|
[
|
||||||
|
"transform-es2015-classes",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"transform-es2015-object-super",
|
||||||
|
"transform-es2015-shorthand-properties",
|
||||||
|
[
|
||||||
|
"transform-es2015-computed-properties",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"transform-es2015-for-of",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"transform-es2015-sticky-regex",
|
||||||
|
"transform-es2015-unicode-regex",
|
||||||
|
"check-es2015-constants",
|
||||||
|
[
|
||||||
|
"transform-es2015-spread",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"transform-es2015-parameters",
|
||||||
|
[
|
||||||
|
"transform-es2015-destructuring",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"transform-es2015-block-scoping",
|
||||||
|
"transform-object-rest-spread",
|
||||||
|
"transform-react-jsx",
|
||||||
|
"syntax-jsx"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"test": {
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"transform-es2015-modules-commonjs",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"commonjs": {
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"transform-es2015-modules-commonjs",
|
||||||
|
{
|
||||||
|
"loose": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"rollup": {
|
||||||
|
"plugins": [
|
||||||
|
"external-helpers"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Generated
-9822
File diff suppressed because it is too large
Load Diff
+20
-4
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"bootstrap": "lerna bootstrap",
|
"bootstrap": "lerna bootstrap",
|
||||||
"test": "lerna run test",
|
"test": "lerna run build && lerna run link && lerna run test",
|
||||||
"cover": "lerna run cover",
|
"cover": "lerna run cover",
|
||||||
"lint": "lerna run lint"
|
"lint": "lerna run build && lerna run link && lerna run lint"
|
||||||
},
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Nikolay Kostyurin",
|
"name": "Nikolay Kostyurin",
|
||||||
@@ -11,23 +11,36 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-cli": "^6.26.0",
|
||||||
"babel-core": "^6.26.3",
|
"babel-core": "^6.26.3",
|
||||||
"babel-jest": "^23.4.2",
|
"babel-jest": "^23.4.2",
|
||||||
|
"babel-plugin-external-helpers": "^6.22.0",
|
||||||
|
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
||||||
|
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
|
||||||
|
"babel-preset-env": "^1.7.0",
|
||||||
|
"babel-preset-es2015": "^6.24.1",
|
||||||
|
"babel-preset-react": "^6.24.1",
|
||||||
"benchmark": "^2.1.4",
|
"benchmark": "^2.1.4",
|
||||||
|
"cross-env": "^5.2.0",
|
||||||
"eslint": "^4.19.1",
|
"eslint": "^4.19.1",
|
||||||
"eslint-config-airbnb": "^16.1.0",
|
"eslint-config-airbnb": "^16.1.0",
|
||||||
"eslint-plugin-import": "^2.12.0",
|
"eslint-plugin-import": "^2.12.0",
|
||||||
"eslint-plugin-jest": "^21.17.0",
|
"eslint-plugin-jest": "^21.17.0",
|
||||||
"eslint-plugin-jsx-a11y": "^6.0.3",
|
"eslint-plugin-jsx-a11y": "^6.0.3",
|
||||||
"eslint-plugin-react": "^7.9.1",
|
"eslint-plugin-react": "^7.9.1",
|
||||||
|
"husky": "^0.14.3",
|
||||||
"jest": "^23.1.0",
|
"jest": "^23.1.0",
|
||||||
"jsdoc-to-markdown": "^4.0.1",
|
"jsdoc-to-markdown": "^4.0.1",
|
||||||
"lerna": "^2.11.0",
|
"lerna": "^2.11.0",
|
||||||
|
"lint-staged": "^7.2.2",
|
||||||
"microtime": "^2.1.8",
|
"microtime": "^2.1.8",
|
||||||
"posthtml-render": "^1.1.4",
|
"posthtml-render": "^1.1.4",
|
||||||
"rollup": "^0.62.0",
|
"rollup": "^0.62.0",
|
||||||
"rollup-plugin-commonjs": "^9.1.3",
|
"rollup-plugin-babel": "^3.0.7",
|
||||||
"rollup-plugin-node-resolve": "^3.3.0",
|
"rollup-plugin-commonjs": "^9.1.6",
|
||||||
|
"rollup-plugin-node-resolve": "^3.4.0",
|
||||||
|
"rollup-plugin-replace": "^2.0.0",
|
||||||
|
"rollup-plugin-uglify": "^5.0.2",
|
||||||
"size-limit": "^0.18.5",
|
"size-limit": "^0.18.5",
|
||||||
"xbbcode-parser": "^0.1.2"
|
"xbbcode-parser": "^0.1.2"
|
||||||
},
|
},
|
||||||
@@ -38,5 +51,8 @@
|
|||||||
"jest": {
|
"jest": {
|
||||||
"coverageDirectory": "./coverage/",
|
"coverageDirectory": "./coverage/",
|
||||||
"collectCoverage": true
|
"collectCoverage": true
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"babel-plugin-transform-object-rest-spread": "^6.26.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
test
|
test
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
test
|
test
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
dist
|
dist
|
||||||
|
lib
|
||||||
|
es
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
src
|
src
|
||||||
dist
|
!dist
|
||||||
!lib
|
!lib
|
||||||
|
!es
|
||||||
*.test.js
|
*.test.js
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const bbob = require('@bbob/core');
|
const bbob = require('@bbob/core');
|
||||||
|
const render = require('@bbob/html');
|
||||||
const presetHTML5 = require('@bbob/preset-html5');
|
const presetHTML5 = require('@bbob/preset-html5');
|
||||||
const code = `[i]Text[/i]`;
|
const code = `[i]Text[/i]`;
|
||||||
|
|
||||||
const html = bbob([presetHTML5()]).process(code).html;
|
const html = bbob([presetHTML5()]).process(code, { render }).html;
|
||||||
|
|
||||||
console.log(html); // <span style="font-style: italic;">Text</span>
|
console.log(html); // <span style="font-style: italic;">Text</span>
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,40 +1,72 @@
|
|||||||
{
|
{
|
||||||
"name": "@bbob/core",
|
"name": "@bbob/core",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"description": "BBob is a tool to transform BBCode markup useing presets",
|
"description": "Fast, flexible, and lean implementation of BBcode parser with plugins",
|
||||||
"main": "lib/index.js",
|
|
||||||
"directories": {
|
|
||||||
"lib": "lib"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@bbob/html": "^1.1.0",
|
|
||||||
"@bbob/parser": "^1.2.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@bbob/preset-html5": "^1.x"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/JiLiZART/bbob.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bbcode",
|
"bbcode",
|
||||||
"parser",
|
"parser",
|
||||||
|
"fast",
|
||||||
|
"bbcode parser",
|
||||||
|
"bbcodeparser",
|
||||||
|
"bbob",
|
||||||
|
"serializer",
|
||||||
|
"bbcode serializer",
|
||||||
|
"bbcode serializer",
|
||||||
|
"bbcodeserializer",
|
||||||
|
"parse",
|
||||||
|
"serialize",
|
||||||
"html",
|
"html",
|
||||||
"transform"
|
"transform"
|
||||||
],
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@bbob/parser": "^1.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@bbob/html": "^1.x"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@bbob/html": "^1.x",
|
||||||
|
"@bbob/preset-html5": "^1.x",
|
||||||
|
"@bbob/react": "^1.x",
|
||||||
|
"@bbob/preset-react": "^1.x"
|
||||||
|
},
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"module": "es/index.js",
|
||||||
|
"jsnext:main": "es/index.js",
|
||||||
|
"browser": "dist/index.js",
|
||||||
|
"browserName": "BbobCore",
|
||||||
|
"homepage": "https://github.com/JiLiZART/bbob",
|
||||||
|
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/JiLiZART/bbob/issues"
|
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/JiLiZART/bbob#readme",
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/JiLiZART/bbob.git"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||||
|
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||||
|
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||||
|
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||||
"test": "../../node_modules/.bin/jest --",
|
"test": "../../node_modules/.bin/jest --",
|
||||||
"cover": "../../node_modules/.bin/jest --coverage",
|
"cover": "../../node_modules/.bin/jest --coverage",
|
||||||
"lint": "../../node_modules/.bin/eslint ."
|
"lint": "../../node_modules/.bin/eslint .",
|
||||||
|
"size": "../../node_modules/.bin/size-limit"
|
||||||
},
|
},
|
||||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
"size-limit": [
|
||||||
"license": "MIT",
|
{
|
||||||
|
"path": "lib/index.js"
|
||||||
|
}
|
||||||
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://registry.npmjs.org/"
|
"registry": "https://registry.npmjs.org/"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"lib",
|
||||||
|
"src",
|
||||||
|
"es"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
const parser = require('@bbob/parser');
|
import { parse } from '@bbob/parser';
|
||||||
const render = require('@bbob/html');
|
import { iterate, match } from './utils';
|
||||||
|
|
||||||
const { iterate, match } = require('./utils');
|
|
||||||
|
|
||||||
function walk(cb) {
|
function walk(cb) {
|
||||||
return iterate(this, cb);
|
return iterate(this, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function bbob(plugs) {
|
export default function bbob(plugs) {
|
||||||
const plugins = typeof plugs === 'function' ? [plugs] : plugs || [];
|
const plugins = typeof plugs === 'function' ? [plugs] : plugs || [];
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
@@ -18,8 +16,8 @@ module.exports = function bbob(plugs) {
|
|||||||
process(input, opts) {
|
process(input, opts) {
|
||||||
options = opts || {};
|
options = opts || {};
|
||||||
|
|
||||||
const parseFn = options.parser || parser;
|
const parseFn = options.parser || parse;
|
||||||
const renderFn = options.render || render;
|
const renderFn = options.render;
|
||||||
|
|
||||||
let tree = options.skipParse
|
let tree = options.skipParse
|
||||||
? input || []
|
? input || []
|
||||||
@@ -39,6 +37,9 @@ module.exports = function bbob(plugs) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
get html() {
|
get html() {
|
||||||
|
if (typeof renderFn !== 'function') {
|
||||||
|
throw new Error('"render" function not defined, please pass to "process(input, { render })"');
|
||||||
|
}
|
||||||
return renderFn(tree, tree.options);
|
return renderFn(tree, tree.options);
|
||||||
},
|
},
|
||||||
tree,
|
tree,
|
||||||
@@ -46,4 +47,4 @@ module.exports = function bbob(plugs) {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
@@ -59,7 +59,7 @@ function match(expression, cb) {
|
|||||||
: iterate(this, node => (same(expression, node) ? cb(node) : node));
|
: iterate(this, node => (same(expression, node) ? cb(node) : node));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
iterate,
|
iterate,
|
||||||
match,
|
match,
|
||||||
};
|
};
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
const core = require('../lib');
|
import render from '@bbob/html'
|
||||||
|
import core from '../src'
|
||||||
|
|
||||||
const stringify = val => JSON.stringify(val);
|
const stringify = val => JSON.stringify(val);
|
||||||
|
|
||||||
|
const process = (plugins, input) => core(plugins).process(input, { render });
|
||||||
|
|
||||||
describe('@bbob/core', () => {
|
describe('@bbob/core', () => {
|
||||||
test('parse bbcode string to ast and html', () => {
|
test('parse bbcode string to ast and html', () => {
|
||||||
const res = core().process('[style size="15px"]Large Text[/style]');
|
const res = process([], '[style size="15px"]Large Text[/style]');
|
||||||
const ast = res.tree;
|
const ast = res.tree;
|
||||||
|
|
||||||
expect(res.html).toBe(`<style size="15px">Large Text</style>`);
|
expect(res.html).toBe(`<style size="15px">Large Text</style>`);
|
||||||
@@ -31,7 +34,7 @@ describe('@bbob/core', () => {
|
|||||||
return node
|
return node
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = core([testPlugin()]).process('[mytag size="15px"]Large Text[/mytag]');
|
const res = process([testPlugin()], '[mytag size="15px"]Large Text[/mytag]');
|
||||||
const ast = res.tree;
|
const ast = res.tree;
|
||||||
|
|
||||||
expect(ast).toBeInstanceOf(Array);
|
expect(ast).toBeInstanceOf(Array);
|
||||||
@@ -61,7 +64,7 @@ describe('@bbob/core', () => {
|
|||||||
return node
|
return node
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = core([testPlugin()]).process(`[mytag1 size="15"]Tag1[/mytag1][mytag2 size="16"]Tag2[/mytag2][mytag3]Tag3[/mytag3]`);
|
const res = process([testPlugin()], `[mytag1 size="15"]Tag1[/mytag1][mytag2 size="16"]Tag2[/mytag2][mytag3]Tag3[/mytag3]`);
|
||||||
const ast = res.tree;
|
const ast = res.tree;
|
||||||
|
|
||||||
expect(ast).toBeInstanceOf(Array);
|
expect(ast).toBeInstanceOf(Array);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { iterate } = require('../lib/utils');
|
import { iterate } from '../src/utils';
|
||||||
|
|
||||||
describe('@bbob/core utils', () => {
|
describe('@bbob/core utils', () => {
|
||||||
test('iterate', () => {
|
test('iterate', () => {
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
test
|
test
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
dist
|
dist
|
||||||
|
lib
|
||||||
|
es
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
src
|
src
|
||||||
dist
|
!dist
|
||||||
!lib
|
!lib
|
||||||
|
!es
|
||||||
*.test.js
|
*.test.js
|
||||||
|
|||||||
@@ -2,21 +2,51 @@
|
|||||||
"name": "@bbob/html",
|
"name": "@bbob/html",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"description": "HTML renderer for BBCode pareser BBob",
|
"description": "HTML renderer for BBCode pareser BBob",
|
||||||
"main": "lib/index.js",
|
"keywords": [],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bbob/plugin-helper": "^1.1.0"
|
"@bbob/plugin-helper": "^1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@bbob/parser": "^1.2.0"
|
"@bbob/parser": "^1.2.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
|
||||||
"test": "../../node_modules/.bin/jest --",
|
"main": "lib/index.js",
|
||||||
"cover": "../../node_modules/.bin/jest --coverage",
|
"module": "es/index.js",
|
||||||
"lint": "../../node_modules/.bin/eslint ."
|
"jsnext:main": "es/index.js",
|
||||||
},
|
"browser": "dist/index.js",
|
||||||
|
"browserName": "BbobHtml",
|
||||||
|
"homepage": "https://github.com/JiLiZART/bbob",
|
||||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/JiLiZART/bbob.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||||
|
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||||
|
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||||
|
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||||
|
"test": "../../node_modules/.bin/jest --",
|
||||||
|
"cover": "../../node_modules/.bin/jest --coverage",
|
||||||
|
"lint": "../../node_modules/.bin/eslint .",
|
||||||
|
"size": "../../node_modules/.bin/size-limit"
|
||||||
|
},
|
||||||
|
"size-limit": [
|
||||||
|
{
|
||||||
|
"path": "lib/index.js"
|
||||||
|
}
|
||||||
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://registry.npmjs.org/"
|
"registry": "https://registry.npmjs.org/"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"lib",
|
||||||
|
"src",
|
||||||
|
"es"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ const renderNodes = (nodes, { stripTags = false } = {}) => []
|
|||||||
.concat(nodes)
|
.concat(nodes)
|
||||||
.reduce((r, node) => r + renderNode(node, { stripTags }), '');
|
.reduce((r, node) => r + renderNode(node, { stripTags }), '');
|
||||||
|
|
||||||
module.exports = renderNodes;
|
export const render = renderNodes;
|
||||||
|
export default renderNodes;
|
||||||
@@ -1,14 +1,20 @@
|
|||||||
const render = require('../lib/index');
|
import {parse} from '@bbob/parser'
|
||||||
const parse = require('@bbob/parser');
|
import {render} from '../src';
|
||||||
|
|
||||||
const process = (input, params) => render(parse(input), params);
|
const process = (input, params) => {
|
||||||
|
const ast = parse(input);
|
||||||
|
const html = render(ast, params);
|
||||||
|
|
||||||
|
return html
|
||||||
|
};
|
||||||
|
|
||||||
describe('@bbob/html', () => {
|
describe('@bbob/html', () => {
|
||||||
test('render bbcode tag with single param as html tag', () => {
|
test('render bbcode tag with single param as html tag', () => {
|
||||||
const input = '[url=https://ru.wikipedia.org]Text[/url]';
|
const input = '[url=https://ru.wikipedia.org]Text[/url]';
|
||||||
const result = '<url url="https://ru.wikipedia.org">Text</url>';
|
const expected = '<url url="https://ru.wikipedia.org">Text</url>';
|
||||||
|
const result = process(input)
|
||||||
|
|
||||||
expect(process(input)).toBe(result);
|
expect(result).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('render bbcode tag with multiple params as html tag', () => {
|
test('render bbcode tag with multiple params as html tag', () => {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
test
|
test
|
||||||
rollup.config.js
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
dist
|
dist
|
||||||
|
lib
|
||||||
|
es
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
src
|
src
|
||||||
dist
|
!dist
|
||||||
!lib
|
!lib
|
||||||
|
!es
|
||||||
*.test.js
|
*.test.js
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
module.exports = require('./parse');
|
|
||||||
@@ -1,41 +1,46 @@
|
|||||||
{
|
{
|
||||||
"name": "@bbob/parser",
|
"name": "@bbob/parser",
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"description": "Fast, flexible, and lean implementation of BBcode parser",
|
"description": "Just parses BBcode to AST array",
|
||||||
"homepage": "https://github.com/JiLiZART/bbob",
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bbcode",
|
"bbcode",
|
||||||
"parser",
|
"parser",
|
||||||
"fast",
|
"ast",
|
||||||
"bbcode parser",
|
"bbcode parser",
|
||||||
"bbcodeparser",
|
"bbcodeparser",
|
||||||
"bbob",
|
"bbob",
|
||||||
"serializer",
|
"array",
|
||||||
"bbcode serializer",
|
"parse"
|
||||||
"bbcode serializer",
|
|
||||||
"bbcodeserializer",
|
|
||||||
"parse",
|
|
||||||
"serialize",
|
|
||||||
"html"
|
|
||||||
],
|
],
|
||||||
"main": "lib/index.js",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bbob/plugin-helper": "^1.1.0"
|
"@bbob/plugin-helper": "^1.1.0"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"module": "es/index.js",
|
||||||
|
"jsnext:main": "es/index.js",
|
||||||
|
"browser": "dist/index.js",
|
||||||
|
"browserName": "BbobParser",
|
||||||
|
"homepage": "https://github.com/JiLiZART/bbob",
|
||||||
|
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/JiLiZART/bbob.git"
|
"url": "git://github.com/JiLiZART/bbob.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "../../node_modules/.bin/rollup -c",
|
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||||
"dev": "../../node_modules/.bin/rollup -c -w",
|
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||||
|
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||||
|
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||||
"test": "../../node_modules/.bin/jest --",
|
"test": "../../node_modules/.bin/jest --",
|
||||||
"cover": "../../node_modules/.bin/jest --coverage",
|
"cover": "../../node_modules/.bin/jest --coverage",
|
||||||
"lint": "../../node_modules/.bin/eslint .",
|
"lint": "../../node_modules/.bin/eslint .",
|
||||||
"size": "../../node_modules/.bin/size-limit"
|
"size": "../../node_modules/.bin/size-limit"
|
||||||
},
|
},
|
||||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
|
||||||
"license": "MIT",
|
|
||||||
"size-limit": [
|
"size-limit": [
|
||||||
{
|
{
|
||||||
"path": "lib/index.js"
|
"path": "lib/index.js"
|
||||||
@@ -45,6 +50,9 @@
|
|||||||
"registry": "https://registry.npmjs.org/"
|
"registry": "https://registry.npmjs.org/"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib"
|
"dist",
|
||||||
|
"lib",
|
||||||
|
"src",
|
||||||
|
"es"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
import resolve from 'rollup-plugin-node-resolve';
|
|
||||||
import commonjs from 'rollup-plugin-commonjs';
|
|
||||||
import pkg from './package.json';
|
|
||||||
|
|
||||||
export default [
|
|
||||||
// browser-friendly UMD build
|
|
||||||
{
|
|
||||||
input: 'lib/index.js',
|
|
||||||
output: {
|
|
||||||
name: 'BBobParser',
|
|
||||||
file: pkg.browser,
|
|
||||||
format: 'umd',
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
resolve(), // so Rollup can find `ms`
|
|
||||||
commonjs(), // so Rollup can convert `ms` to an ES module
|
|
||||||
],
|
|
||||||
},
|
|
||||||
|
|
||||||
// CommonJS (for Node) and ES module (for bundlers) build.
|
|
||||||
// (We could have three entries in the configuration array
|
|
||||||
// instead of two, but it's quicker to generate multiple
|
|
||||||
// builds from a single configuration where possible, using
|
|
||||||
// an array for the output` option, where we can specify
|
|
||||||
// `file` and `format` for each target)
|
|
||||||
{
|
|
||||||
input: 'lib/index.js',
|
|
||||||
output: [
|
|
||||||
{ file: pkg.main, format: 'cjs' },
|
|
||||||
{ file: pkg.module, format: 'es' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
const {
|
import {
|
||||||
getChar,
|
|
||||||
OPEN_BRAKET,
|
OPEN_BRAKET,
|
||||||
CLOSE_BRAKET,
|
CLOSE_BRAKET,
|
||||||
SLASH,
|
SLASH,
|
||||||
} = require('@bbob/plugin-helper/lib/char');
|
} from '@bbob/plugin-helper/lib/char';
|
||||||
|
|
||||||
// type, value, line, row,
|
// type, value, line, row,
|
||||||
const TOKEN_TYPE_ID = 'type'; // 0;
|
const TOKEN_TYPE_ID = 'type'; // 0;
|
||||||
@@ -28,7 +27,7 @@ const isTextToken = token =>
|
|||||||
token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
|
token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
|
||||||
|
|
||||||
const isTagToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
|
const isTagToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
|
||||||
const isTagEnd = token => getTokenValue(token).charCodeAt(0) === SLASH;
|
const isTagEnd = token => getTokenValue(token).charCodeAt(0) === SLASH.charCodeAt(0);
|
||||||
const isTagStart = token => !isTagEnd(token);
|
const isTagStart = token => !isTagEnd(token);
|
||||||
const isAttrNameToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
|
const isAttrNameToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
|
||||||
const isAttrValueToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
|
const isAttrValueToken = token => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
|
||||||
@@ -40,14 +39,14 @@ const getTagName = (token) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const convertTagToText = (token) => {
|
const convertTagToText = (token) => {
|
||||||
let text = getChar(OPEN_BRAKET);
|
let text = OPEN_BRAKET;
|
||||||
|
|
||||||
if (isTagEnd(token)) {
|
if (isTagEnd(token)) {
|
||||||
text += getChar(SLASH);
|
text += SLASH;
|
||||||
}
|
}
|
||||||
|
|
||||||
text += getTokenValue(token);
|
text += getTokenValue(token);
|
||||||
text += getChar(CLOSE_BRAKET);
|
text += CLOSE_BRAKET;
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
@@ -109,15 +108,15 @@ class Token {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Token;
|
export const TYPE_ID = TOKEN_TYPE_ID;
|
||||||
|
export const VALUE_ID = TOKEN_VALUE_ID;
|
||||||
module.exports.TYPE_ID = TOKEN_TYPE_ID;
|
export const LINE_ID = TOKEN_LINE_ID;
|
||||||
module.exports.VALUE_ID = TOKEN_VALUE_ID;
|
export const COLUMN_ID = TOKEN_COLUMN_ID;
|
||||||
module.exports.LINE_ID = TOKEN_LINE_ID;
|
export const TYPE_WORD = TOKEN_TYPE_WORD;
|
||||||
module.exports.COLUMN_ID = TOKEN_COLUMN_ID;
|
export const TYPE_TAG = TOKEN_TYPE_TAG;
|
||||||
module.exports.TYPE_WORD = TOKEN_TYPE_WORD;
|
export const TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME;
|
||||||
module.exports.TYPE_TAG = TOKEN_TYPE_TAG;
|
export const TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE;
|
||||||
module.exports.TYPE_ATTR_NAME = TOKEN_TYPE_ATTR_NAME;
|
export const TYPE_SPACE = TOKEN_TYPE_SPACE;
|
||||||
module.exports.TYPE_ATTR_VALUE = TOKEN_TYPE_ATTR_VALUE;
|
export const TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE;
|
||||||
module.exports.TYPE_SPACE = TOKEN_TYPE_SPACE;
|
export { Token };
|
||||||
module.exports.TYPE_NEW_LINE = TOKEN_TYPE_NEW_LINE;
|
export default Token;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { parse, createTagNode } from './parse';
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
/* eslint-disable no-plusplus,no-param-reassign */
|
/* eslint-disable no-plusplus,no-param-reassign */
|
||||||
const c = require('@bbob/plugin-helper/lib/char');
|
import {
|
||||||
const Token = require('./Token');
|
OPEN_BRAKET,
|
||||||
|
CLOSE_BRAKET,
|
||||||
|
QUOTEMARK,
|
||||||
|
BACKSLASH,
|
||||||
|
SLASH,
|
||||||
|
SPACE,
|
||||||
|
TAB,
|
||||||
|
EQ,
|
||||||
|
N,
|
||||||
|
} from '@bbob/plugin-helper/lib/char';
|
||||||
|
|
||||||
const OPEN_BRAKET = c.getChar(c.OPEN_BRAKET);
|
import { Token, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_NEW_LINE, TYPE_SPACE, TYPE_TAG, TYPE_WORD } from './Token';
|
||||||
const CLOSE_BRAKET = c.getChar(c.CLOSE_BRAKET);
|
|
||||||
const QUOTEMARK = c.getChar(c.QUOTEMARK);
|
|
||||||
const BACKSLASH = c.getChar(c.BACKSLASH);
|
|
||||||
const SLASH = c.getChar(c.SLASH);
|
|
||||||
const SPACE = c.getChar(c.SPACE);
|
|
||||||
const TAB = c.getChar(c.TAB);
|
|
||||||
const EQ = c.getChar(c.EQ);
|
|
||||||
const N = c.getChar(c.N);
|
|
||||||
|
|
||||||
const RESERVED_CHARS = [CLOSE_BRAKET, OPEN_BRAKET, QUOTEMARK, BACKSLASH, SPACE, TAB, EQ, N];
|
const RESERVED_CHARS = [CLOSE_BRAKET, OPEN_BRAKET, QUOTEMARK, BACKSLASH, SPACE, TAB, EQ, N];
|
||||||
const NOT_CHAR_TOKENS = [OPEN_BRAKET, SPACE, TAB, N];
|
const NOT_CHAR_TOKENS = [OPEN_BRAKET, SPACE, TAB, N];
|
||||||
@@ -111,9 +112,9 @@ function createLexer(buffer, options = {}) {
|
|||||||
tagName = attrStr;
|
tagName = attrStr;
|
||||||
} else if (isWhiteSpace(attrCharGrabber.getCurr()) || !attrCharGrabber.hasNext()) {
|
} else if (isWhiteSpace(attrCharGrabber.getCurr()) || !attrCharGrabber.hasNext()) {
|
||||||
const escaped = unquote(trimChar(attrStr, QUOTEMARK));
|
const escaped = unquote(trimChar(attrStr, QUOTEMARK));
|
||||||
attrTokens.push(createToken(Token.TYPE_ATTR_VALUE, escaped, row, col));
|
attrTokens.push(createToken(TYPE_ATTR_VALUE, escaped, row, col));
|
||||||
} else {
|
} else {
|
||||||
attrTokens.push(createToken(Token.TYPE_ATTR_NAME, attrStr, row, col));
|
attrTokens.push(createToken(TYPE_ATTR_NAME, attrStr, row, col));
|
||||||
}
|
}
|
||||||
|
|
||||||
attrCharGrabber.skip();
|
attrCharGrabber.skip();
|
||||||
@@ -136,37 +137,37 @@ function createLexer(buffer, options = {}) {
|
|||||||
col = 0;
|
col = 0;
|
||||||
row++;
|
row++;
|
||||||
|
|
||||||
emitToken(createToken(Token.TYPE_NEW_LINE, char, row, col));
|
emitToken(createToken(TYPE_NEW_LINE, char, row, col));
|
||||||
} else if (isWhiteSpace(char)) {
|
} else if (isWhiteSpace(char)) {
|
||||||
const str = grabber.grabWhile(isWhiteSpace);
|
const str = grabber.grabWhile(isWhiteSpace);
|
||||||
emitToken(createToken(Token.TYPE_SPACE, str, row, col));
|
emitToken(createToken(TYPE_SPACE, str, row, col));
|
||||||
} else if (char === OPEN_BRAKET) {
|
} else if (char === OPEN_BRAKET) {
|
||||||
const nextChar = grabber.getNext();
|
const nextChar = grabber.getNext();
|
||||||
grabber.skip(); // skip [
|
grabber.skip(); // skip [
|
||||||
|
|
||||||
if (isCharReserved(nextChar)) {
|
if (isCharReserved(nextChar)) {
|
||||||
emitToken(createToken(Token.TYPE_WORD, char, row, col));
|
emitToken(createToken(TYPE_WORD, char, row, col));
|
||||||
} else {
|
} else {
|
||||||
const str = grabber.grabWhile(val => val !== CLOSE_BRAKET);
|
const str = grabber.grabWhile(val => val !== CLOSE_BRAKET);
|
||||||
grabber.skip(); // skip ]
|
grabber.skip(); // skip ]
|
||||||
|
|
||||||
if (!(str.indexOf(EQ) > 0) || str[0] === SLASH) {
|
if (!(str.indexOf(EQ) > 0) || str[0] === SLASH) {
|
||||||
emitToken(createToken(Token.TYPE_TAG, str, row, col));
|
emitToken(createToken(TYPE_TAG, str, row, col));
|
||||||
} else {
|
} else {
|
||||||
const parsed = parseAttrs(str);
|
const parsed = parseAttrs(str);
|
||||||
|
|
||||||
emitToken(createToken(Token.TYPE_TAG, parsed.tag, row, col));
|
emitToken(createToken(TYPE_TAG, parsed.tag, row, col));
|
||||||
parsed.attrs.map(emitToken);
|
parsed.attrs.map(emitToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (char === CLOSE_BRAKET) {
|
} else if (char === CLOSE_BRAKET) {
|
||||||
grabber.skip();
|
grabber.skip();
|
||||||
|
|
||||||
emitToken(createToken(Token.TYPE_WORD, char, row, col));
|
emitToken(createToken(TYPE_WORD, char, row, col));
|
||||||
} else if (isCharToken(char)) {
|
} else if (isCharToken(char)) {
|
||||||
const str = grabber.grabWhile(isCharToken);
|
const str = grabber.grabWhile(isCharToken);
|
||||||
|
|
||||||
emitToken(createToken(Token.TYPE_WORD, str, row, col));
|
emitToken(createToken(TYPE_WORD, str, row, col));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -191,5 +192,5 @@ function createLexer(buffer, options = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = createLexer;
|
export const createTokenOfType = createToken;
|
||||||
module.exports.createTokenOfType = createToken;
|
export { createLexer };
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const createLexer = require('./lexer');
|
import TagNode from '@bbob/plugin-helper/lib/TagNode';
|
||||||
const TagNode = require('@bbob/plugin-helper/lib/TagNode');
|
import { createLexer } from './lexer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -227,5 +227,5 @@ const parse = (input, opts = {}) => {
|
|||||||
return nodes;
|
return nodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = parse;
|
export { createTagNode, parse };
|
||||||
module.exports.createTagNode = createTagNode;
|
export default parse;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
const Token = require('../lib/Token');
|
const Token = require('../src/Token');
|
||||||
const lexer = require('../lib/lexer');
|
const { createLexer } = require('../src/lexer');
|
||||||
|
|
||||||
const TYPE = {
|
const TYPE = {
|
||||||
WORD: Token.TYPE_WORD,
|
WORD: Token.TYPE_WORD,
|
||||||
@@ -10,7 +10,7 @@ const TYPE = {
|
|||||||
NEW_LINE: Token.TYPE_NEW_LINE,
|
NEW_LINE: Token.TYPE_NEW_LINE,
|
||||||
};
|
};
|
||||||
|
|
||||||
const tokenize = input => (lexer(input).tokenize());
|
const tokenize = input => (createLexer(input).tokenize());
|
||||||
|
|
||||||
describe('lexer', () => {
|
describe('lexer', () => {
|
||||||
const expectOutput = (output, tokens) => {
|
const expectOutput = (output, tokens) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const parse = require('../lib/parse');
|
import { parse } from '../src'
|
||||||
|
|
||||||
describe('Parser', () => {
|
describe('Parser', () => {
|
||||||
test('parse paired tags tokens', () => {
|
test('parse paired tags tokens', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const render = require('posthtml-render');
|
import {parse} from '../src'
|
||||||
const parse = require('../lib');
|
import render from 'posthtml-render'
|
||||||
|
|
||||||
describe('posthtml-render', () => {
|
describe('posthtml-render', () => {
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
test
|
test
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package-lock.json
|
||||||
|
coverage
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
es
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package-lock.json
|
||||||
|
coverage
|
||||||
|
src
|
||||||
|
!dist
|
||||||
|
!lib
|
||||||
|
!es
|
||||||
|
*.test.js
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
const {
|
|
||||||
getChar, OPEN_BRAKET, CLOSE_BRAKET, SLASH,
|
|
||||||
} = require('./char');
|
|
||||||
const { getNodeLength, appendToNode } = require('./index');
|
|
||||||
|
|
||||||
class TagNode {
|
|
||||||
constructor(tag, attrs, content) {
|
|
||||||
this.tag = tag;
|
|
||||||
this.attrs = attrs;
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
attr(name, value) {
|
|
||||||
if (typeof value !== 'undefined') {
|
|
||||||
this.attrs[name] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.attrs[name];
|
|
||||||
}
|
|
||||||
|
|
||||||
append(value) {
|
|
||||||
return appendToNode(this, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
get length() {
|
|
||||||
return getNodeLength(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
toString() {
|
|
||||||
const OB = getChar(OPEN_BRAKET);
|
|
||||||
const CB = getChar(CLOSE_BRAKET);
|
|
||||||
const SL = getChar(SLASH);
|
|
||||||
|
|
||||||
return OB + this.tag + CB + this.content.reduce((r, node) => r + node.toString(), '') + OB + SL + this.tag + CB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = TagNode;
|
|
||||||
module.exports.create = (tag, attrs = {}, content = []) => new TagNode(tag, attrs, content);
|
|
||||||
module.exports.isOf = (node, type) => (node.tag === type);
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
const N = '\n'.charCodeAt(0);
|
|
||||||
const TAB = '\t'.charCodeAt(0);
|
|
||||||
const F = '\f'.charCodeAt(0);
|
|
||||||
const R = '\r'.charCodeAt(0);
|
|
||||||
|
|
||||||
const EQ = '='.charCodeAt(0);
|
|
||||||
const QUOTEMARK = '"'.charCodeAt(0);
|
|
||||||
const SPACE = ' '.charCodeAt(0);
|
|
||||||
|
|
||||||
const OPEN_BRAKET = '['.charCodeAt(0);
|
|
||||||
const CLOSE_BRAKET = ']'.charCodeAt(0);
|
|
||||||
|
|
||||||
const SLASH = '/'.charCodeAt(0);
|
|
||||||
const BACKSLASH = '\\'.charCodeAt(0);
|
|
||||||
|
|
||||||
const PLACEHOLDER_SPACE_TAB = ' ';
|
|
||||||
const PLACEHOLDER_SPACE = ' ';
|
|
||||||
|
|
||||||
const getChar = String.fromCharCode;
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getChar,
|
|
||||||
N,
|
|
||||||
F,
|
|
||||||
R,
|
|
||||||
TAB,
|
|
||||||
EQ,
|
|
||||||
QUOTEMARK,
|
|
||||||
SPACE,
|
|
||||||
OPEN_BRAKET,
|
|
||||||
CLOSE_BRAKET,
|
|
||||||
SLASH,
|
|
||||||
PLACEHOLDER_SPACE_TAB,
|
|
||||||
PLACEHOLDER_SPACE,
|
|
||||||
BACKSLASH,
|
|
||||||
};
|
|
||||||
@@ -2,31 +2,48 @@
|
|||||||
"name": "@bbob/plugin-helper",
|
"name": "@bbob/plugin-helper",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"description": "Set of utils to help write plugins",
|
"description": "Set of utils to help write plugins",
|
||||||
"main": "lib/index.js",
|
|
||||||
"directories": {
|
|
||||||
"lib": "lib"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/JiLiZART/bbob.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bbob",
|
"bbob",
|
||||||
"plugin",
|
"plugin",
|
||||||
"helper"
|
"helper"
|
||||||
],
|
],
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"module": "es/index.js",
|
||||||
|
"jsnext:main": "es/index.js",
|
||||||
|
"browser": "dist/index.js",
|
||||||
|
"browserName": "BbobPluginHelper",
|
||||||
|
"homepage": "https://github.com/JiLiZART/bbob",
|
||||||
|
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/JiLiZART/bbob/issues"
|
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/JiLiZART/bbob#readme",
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/JiLiZART/bbob.git"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||||
|
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||||
|
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||||
|
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||||
"test": "../../node_modules/.bin/jest --",
|
"test": "../../node_modules/.bin/jest --",
|
||||||
"cover": "../../node_modules/.bin/jest --coverage",
|
"cover": "../../node_modules/.bin/jest --coverage",
|
||||||
"lint": "../../node_modules/.bin/eslint ."
|
"lint": "../../node_modules/.bin/eslint .",
|
||||||
|
"size": "../../node_modules/.bin/size-limit"
|
||||||
},
|
},
|
||||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
"size-limit": [
|
||||||
"license": "MIT",
|
{
|
||||||
|
"path": "lib/index.js"
|
||||||
|
}
|
||||||
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://registry.npmjs.org/"
|
"registry": "https://registry.npmjs.org/"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"lib",
|
||||||
|
"src",
|
||||||
|
"es"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char';
|
||||||
|
import { getNodeLength, appendToNode } from './index';
|
||||||
|
|
||||||
|
class TagNode {
|
||||||
|
constructor(tag, attrs, content) {
|
||||||
|
this.tag = tag;
|
||||||
|
this.attrs = attrs;
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
attr(name, value) {
|
||||||
|
if (typeof value !== 'undefined') {
|
||||||
|
this.attrs[name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.attrs[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
append(value) {
|
||||||
|
return appendToNode(this, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
get length() {
|
||||||
|
return getNodeLength(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
const OB = OPEN_BRAKET;
|
||||||
|
const CB = CLOSE_BRAKET;
|
||||||
|
|
||||||
|
return OB + this.tag + CB + this.content.reduce((r, node) => r + node.toString(), '') + OB + SLASH + this.tag + CB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TagNode.create = (tag, attrs = {}, content = []) => new TagNode(tag, attrs, content);
|
||||||
|
TagNode.isOf = (node, type) => (node.tag === type);
|
||||||
|
|
||||||
|
export { TagNode };
|
||||||
|
export default TagNode;
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
const N = '\n';
|
||||||
|
const TAB = '\t';
|
||||||
|
const F = '\f';
|
||||||
|
const R = '\r';
|
||||||
|
|
||||||
|
const EQ = '=';
|
||||||
|
const QUOTEMARK = '"';
|
||||||
|
const SPACE = ' ';
|
||||||
|
|
||||||
|
const OPEN_BRAKET = '[';
|
||||||
|
const CLOSE_BRAKET = ']';
|
||||||
|
|
||||||
|
const SLASH = '/';
|
||||||
|
const BACKSLASH = '\\';
|
||||||
|
|
||||||
|
const PLACEHOLDER_SPACE_TAB = ' ';
|
||||||
|
const PLACEHOLDER_SPACE = ' ';
|
||||||
|
|
||||||
|
// const getChar = String.fromCharCode;
|
||||||
|
|
||||||
|
export {
|
||||||
|
N,
|
||||||
|
F,
|
||||||
|
R,
|
||||||
|
TAB,
|
||||||
|
EQ,
|
||||||
|
QUOTEMARK,
|
||||||
|
SPACE,
|
||||||
|
OPEN_BRAKET,
|
||||||
|
CLOSE_BRAKET,
|
||||||
|
SLASH,
|
||||||
|
PLACEHOLDER_SPACE_TAB,
|
||||||
|
PLACEHOLDER_SPACE,
|
||||||
|
BACKSLASH,
|
||||||
|
};
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
const { getChar, N } = require('./char');
|
import { N } from './char';
|
||||||
|
|
||||||
const isTagNode = el => typeof el === 'object' && !!el.tag;
|
const isTagNode = el => typeof el === 'object' && !!el.tag;
|
||||||
const isStringNode = el => typeof el === 'string';
|
const isStringNode = el => typeof el === 'string';
|
||||||
|
const isEOL = el => el === N;
|
||||||
const EOL = getChar(N);
|
|
||||||
const isEOL = el => el === EOL;
|
|
||||||
|
|
||||||
const getNodeLength = (node) => {
|
const getNodeLength = (node) => {
|
||||||
if (isTagNode(node)) {
|
if (isTagNode(node)) {
|
||||||
@@ -35,7 +33,7 @@ const attrValue = (name, value) => {
|
|||||||
return types[type] ? types[type]() : '';
|
return types[type] ? types[type]() : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
export {
|
||||||
attrValue,
|
attrValue,
|
||||||
appendToNode,
|
appendToNode,
|
||||||
getNodeLength,
|
getNodeLength,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
const TagNode = require('../lib/TagNode');
|
import TagNode from '../src/TagNode'
|
||||||
|
|
||||||
describe('@bbob/plugin-helper/lib/TagNode', () => {
|
describe('@bbob/plugin-helper/lib/TagNode', () => {
|
||||||
test('create', () => {
|
test('create', () => {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const {
|
import {
|
||||||
attrValue,
|
attrValue,
|
||||||
appendToNode,
|
appendToNode,
|
||||||
getNodeLength,
|
getNodeLength,
|
||||||
isTagNode,
|
isTagNode,
|
||||||
isStringNode,
|
isStringNode,
|
||||||
} = require('../lib');
|
} from '../src';
|
||||||
|
|
||||||
describe('@bbob/plugin-helper', () => {
|
describe('@bbob/plugin-helper', () => {
|
||||||
test('appendToNode', () => {
|
test('appendToNode', () => {
|
||||||
@@ -61,7 +61,7 @@ describe('@bbob/plugin-helper', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('attrValue object', () => {
|
test('attrValue object', () => {
|
||||||
const attrs = { tag: 'test'};
|
const attrs = { tag: 'test' };
|
||||||
|
|
||||||
expect(attrValue('test', attrs)).toBe('test="{"tag":"test"}"');
|
expect(attrValue('test', attrs)).toBe('test="{"tag":"test"}"');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
test
|
test
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
dist
|
dist
|
||||||
|
lib
|
||||||
|
es
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
src
|
src
|
||||||
dist
|
!dist
|
||||||
!lib
|
!lib
|
||||||
|
!es
|
||||||
*.test.js
|
*.test.js
|
||||||
|
|||||||
@@ -2,20 +2,6 @@
|
|||||||
"name": "@bbob/preset-html5",
|
"name": "@bbob/preset-html5",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"description": "HTML5 Preset to transform BBCode to HTML",
|
"description": "HTML5 Preset to transform BBCode to HTML",
|
||||||
"main": "lib/index.js",
|
|
||||||
"directories": {
|
|
||||||
"lib": "lib"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@bbob/plugin-helper": "^1.1.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@bbob/core": "^1.1.0"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/JiLiZART/bbob.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bbcode",
|
"bbcode",
|
||||||
"preset",
|
"preset",
|
||||||
@@ -23,18 +9,51 @@
|
|||||||
"bbode",
|
"bbode",
|
||||||
"transform"
|
"transform"
|
||||||
],
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@bbob/plugin-helper": "^1.1.0",
|
||||||
|
"@bbob/preset": "^1.1.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@bbob/core": "^1.1.0",
|
||||||
|
"@bbob/html": "^1.1.0"
|
||||||
|
},
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"module": "es/index.js",
|
||||||
|
"jsnext:main": "es/index.js",
|
||||||
|
"browser": "dist/index.js",
|
||||||
|
"browserName": "BbobPresetHTML5",
|
||||||
|
"homepage": "https://github.com/JiLiZART/bbob",
|
||||||
|
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/JiLiZART/bbob/issues"
|
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/JiLiZART/bbob#readme",
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/JiLiZART/bbob.git"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||||
|
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||||
|
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||||
|
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||||
"test": "../../node_modules/.bin/jest --",
|
"test": "../../node_modules/.bin/jest --",
|
||||||
"cover": "../../node_modules/.bin/jest --coverage",
|
"cover": "../../node_modules/.bin/jest --coverage",
|
||||||
"lint": "../../node_modules/.bin/eslint ."
|
"lint": "../../node_modules/.bin/eslint .",
|
||||||
|
"size": "../../node_modules/.bin/size-limit"
|
||||||
},
|
},
|
||||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
"size-limit": [
|
||||||
"license": "MIT",
|
{
|
||||||
|
"path": "lib/index.js"
|
||||||
|
}
|
||||||
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://registry.npmjs.org/"
|
"registry": "https://registry.npmjs.org/"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"lib",
|
||||||
|
"src",
|
||||||
|
"es"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable no-plusplus,no-lonely-if */
|
/* eslint-disable no-plusplus,no-lonely-if */
|
||||||
const { isStringNode, isTagNode } = require('@bbob/plugin-helper');
|
import { isStringNode, isTagNode } from '@bbob/plugin-helper';
|
||||||
const TagNode = require('@bbob/plugin-helper/lib/TagNode');
|
import TagNode from '@bbob/plugin-helper/lib/TagNode';
|
||||||
|
|
||||||
const isStartsWith = (node, type) => (node[0] === type);
|
const isStartsWith = (node, type) => (node[0] === type);
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ const asListItems = (content) => {
|
|||||||
return [].concat(listItems);
|
return [].concat(listItems);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
b: node => ({
|
b: node => ({
|
||||||
tag: 'span',
|
tag: 'span',
|
||||||
attrs: {
|
attrs: {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable indent */
|
/* eslint-disable indent */
|
||||||
const { isTagNode } = require('@bbob/plugin-helper');
|
import { isTagNode } from '@bbob/plugin-helper';
|
||||||
const defaultTags = require('./default');
|
import defaultTags from './defaultTags';
|
||||||
|
|
||||||
function process(tags, tree, core) {
|
function process(tags, tree, core) {
|
||||||
tree.walk(node => (isTagNode(node) && tags[node.tag]
|
tree.walk(node => (isTagNode(node) && tags[node.tag]
|
||||||
@@ -20,5 +20,6 @@ function extend(callback) {
|
|||||||
return () => (tree, core) => process(tags, tree, core);
|
return () => (tree, core) => process(tags, tree, core);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = html5Preset;
|
html5Preset.extend = extend;
|
||||||
module.exports.extend = extend;
|
|
||||||
|
export default html5Preset;
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
const preset = require('../lib/index');
|
import core from '@bbob/core'
|
||||||
const core = require('@bbob/core');
|
import { render } from '@bbob/html'
|
||||||
|
import preset from '../src'
|
||||||
|
|
||||||
const parse = input => core([preset()]).process(input).html;
|
const parse = input => core([preset()]).process(input, {render}).html;
|
||||||
|
|
||||||
describe('@bbob/preset-html5', () => {
|
describe('@bbob/preset-html5', () => {
|
||||||
test('[b]bolded text[/b]', () => {
|
test('[b]bolded text[/b]', () => {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
|
test
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package-lock.json
|
||||||
|
coverage
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
es
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package-lock.json
|
||||||
|
coverage
|
||||||
|
src
|
||||||
|
!dist
|
||||||
|
!lib
|
||||||
|
!es
|
||||||
|
*.test.js
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# Change Log
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
<a name="1.1.0"></a>
|
||||||
|
# [1.1.0](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.6...@bbob/preset-html5@1.1.0) (2018-08-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* react render support, move some helper functions to plugin-helper ([1a84968](https://github.com/JiLiZART/bbob/commit/1a84968))
|
||||||
|
* **preset-html5:** add basic preset with tests ([18ab61b](https://github.com/JiLiZART/bbob/commit/18ab61b))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="1.0.6"></a>
|
||||||
|
## [1.0.6](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.5...@bbob/preset-html5@1.0.6) (2018-07-13)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @bbob/preset-html5
|
||||||
|
|
||||||
|
<a name="1.0.5"></a>
|
||||||
|
## [1.0.5](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.4...@bbob/preset-html5@1.0.5) (2018-07-11)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @bbob/preset-html5
|
||||||
|
|
||||||
|
<a name="1.0.4"></a>
|
||||||
|
## [1.0.4](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.3...@bbob/preset-html5@1.0.4) (2018-07-10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @bbob/preset-html5
|
||||||
|
|
||||||
|
<a name="1.0.3"></a>
|
||||||
|
## [1.0.3](https://github.com/JiLiZART/bbob/compare/@bbob/preset-html5@1.0.2...@bbob/preset-html5@1.0.3) (2018-07-10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**Note:** Version bump only for package @bbob/preset-html5
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Preset to render BBCode to HTML tags
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"name": "@bbob/preset-react",
|
||||||
|
"version": "1.1.0",
|
||||||
|
"description": "React preset to transform BBCode to React Components",
|
||||||
|
"keywords": [
|
||||||
|
"bbcode",
|
||||||
|
"preset",
|
||||||
|
"react",
|
||||||
|
"bbode",
|
||||||
|
"transform"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@bbob/preset-html5": "*"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@bbob/core": "^1.1.0"
|
||||||
|
},
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"module": "es/index.js",
|
||||||
|
"jsnext:main": "es/index.js",
|
||||||
|
"browser": "dist/index.js",
|
||||||
|
"browserName": "BbobPresetReact",
|
||||||
|
"homepage": "https://github.com/JiLiZART/bbob",
|
||||||
|
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/JiLiZART/bbob.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||||
|
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||||
|
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||||
|
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||||
|
"test": "../../node_modules/.bin/jest --",
|
||||||
|
"cover": "../../node_modules/.bin/jest --coverage",
|
||||||
|
"lint": "../../node_modules/.bin/eslint .",
|
||||||
|
"size": "../../node_modules/.bin/size-limit"
|
||||||
|
},
|
||||||
|
"size-limit": [
|
||||||
|
{
|
||||||
|
"path": "lib/index.js"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"registry": "https://registry.npmjs.org/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"lib",
|
||||||
|
"src",
|
||||||
|
"es"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const presetHTML5 = require('@bbob/preset-html5');
|
import presetHTML5 from '@bbob/preset-html5';
|
||||||
|
|
||||||
module.exports = presetHTML5.extend(tags => ({
|
export default presetHTML5.extend(tags => ({
|
||||||
...tags,
|
...tags,
|
||||||
|
|
||||||
b: (...args) => ({
|
b: (...args) => ({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import preset from '../src'
|
||||||
|
|
||||||
|
describe('@bbob/preset-react', () => {
|
||||||
|
test('is a function', () => {
|
||||||
|
expect(preset).toBeInstanceOf(Function)
|
||||||
|
})
|
||||||
|
});
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
|
test
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package-lock.json
|
||||||
|
coverage
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
es
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package-lock.json
|
||||||
|
coverage
|
||||||
|
src
|
||||||
|
!dist
|
||||||
|
!lib
|
||||||
|
!es
|
||||||
|
*.test.js
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"name": "@bbob/preset",
|
||||||
|
"version": "1.1.0",
|
||||||
|
"description": "Base preset for creating extensible presets for BBob",
|
||||||
|
"keywords": [
|
||||||
|
"bbcode",
|
||||||
|
"preset",
|
||||||
|
"html5",
|
||||||
|
"bbode",
|
||||||
|
"transform"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@bbob/plugin-helper": "^1.1.0"
|
||||||
|
},
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"module": "es/index.js",
|
||||||
|
"jsnext:main": "es/index.js",
|
||||||
|
"browser": "dist/index.js",
|
||||||
|
"browserName": "BbobPreset",
|
||||||
|
"homepage": "https://github.com/JiLiZART/bbob",
|
||||||
|
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/JiLiZART/bbob.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||||
|
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||||
|
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||||
|
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||||
|
"test": "../../node_modules/.bin/jest --",
|
||||||
|
"cover": "../../node_modules/.bin/jest --coverage",
|
||||||
|
"lint": "../../node_modules/.bin/eslint .",
|
||||||
|
"size": "../../node_modules/.bin/size-limit"
|
||||||
|
},
|
||||||
|
"size-limit": [
|
||||||
|
{
|
||||||
|
"path": "lib/index.js"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"registry": "https://registry.npmjs.org/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"lib",
|
||||||
|
"src",
|
||||||
|
"es"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/* eslint-disable indent */
|
||||||
|
import { isTagNode } from '@bbob/plugin-helper';
|
||||||
|
|
||||||
|
function process(tags, tree, ...rest) {
|
||||||
|
tree.walk(node => (isTagNode(node) && tags[node.tag]
|
||||||
|
? tags[node.tag](node, ...rest)
|
||||||
|
: node));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tags
|
||||||
|
* @return {function(*=, *=)}
|
||||||
|
*/
|
||||||
|
function createPreset(tags) {
|
||||||
|
const instance = (tree, ...rest) => process(tags, tree, ...rest);
|
||||||
|
|
||||||
|
instance.extend = (callback) => {
|
||||||
|
const newTags = callback(tags);
|
||||||
|
|
||||||
|
return () => createPreset(newTags);
|
||||||
|
};
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { createPreset };
|
||||||
|
export default createPreset;
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import {createPreset} from "../src/index";
|
||||||
|
|
||||||
|
describe('@bbob/preset', () => {
|
||||||
|
test('create', () => {
|
||||||
|
const preset = createPreset({ test: true });
|
||||||
|
|
||||||
|
expect(preset.extend).toBeDefined();
|
||||||
|
expect(preset).toBeInstanceOf(Function);
|
||||||
|
});
|
||||||
|
test('extend', () => {
|
||||||
|
const preset = createPreset({ foo: true });
|
||||||
|
const newPreset = preset.extend(props => ({ bar: true }));
|
||||||
|
|
||||||
|
expect(preset).toBeInstanceOf(Function);
|
||||||
|
expect(newPreset).toBeInstanceOf(Function);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"presets": [
|
|
||||||
"react"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
|
es
|
||||||
|
lib
|
||||||
test
|
test
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
dist
|
dist
|
||||||
|
lib
|
||||||
|
es
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
src
|
src
|
||||||
dist
|
!dist
|
||||||
!lib
|
!lib
|
||||||
|
!es
|
||||||
*.test.js
|
*.test.js
|
||||||
|
|||||||
@@ -1,21 +1,41 @@
|
|||||||
# @bbob/react
|
# @bbob/react
|
||||||
|
|
||||||
```js
|
```jsx
|
||||||
|
import React from 'react'
|
||||||
import BBCode from '@bbob/react';
|
import BBCode from '@bbob/react';
|
||||||
import presetHTML5 from '@bbob/react/lib/preset-html5';
|
import presetReact from '@bbob/preset-react';
|
||||||
|
|
||||||
const plugins = [presetHTML5()];
|
const plugins = [presetReact()];
|
||||||
|
|
||||||
<BBCode plugins={plugins}>
|
export default () => (
|
||||||
|
<BBCode plugins={plugins}>
|
||||||
|
[table]
|
||||||
|
[tr]
|
||||||
|
[td]table 1[/td]
|
||||||
|
[td]table 2[/td]
|
||||||
|
[/tr]
|
||||||
|
[tr]
|
||||||
|
[td]table 3[/td]
|
||||||
|
[td]table 4[/td]
|
||||||
|
[/tr]
|
||||||
|
[/table]
|
||||||
|
</BBCode>
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import { render } from '@bbob/react'
|
||||||
|
|
||||||
|
export default () => render(`
|
||||||
[table]
|
[table]
|
||||||
[tr]
|
[tr]
|
||||||
[td]table 1[/td]
|
[td]table 1[/td]
|
||||||
[td]table 2[/td]
|
[td]table 2[/td]
|
||||||
[/tr]
|
[/tr]
|
||||||
[tr]
|
[tr]
|
||||||
[td]table 3[/td]
|
[td]table 3[/td]
|
||||||
[td]table 4[/td]
|
[td]table 4[/td]
|
||||||
[/tr]
|
[/tr]
|
||||||
[/table]
|
[/table]
|
||||||
</BBCode>
|
`)
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
module.exports = require('./Component');
|
|
||||||
|
|
||||||
@@ -2,48 +2,65 @@
|
|||||||
"name": "@bbob/react",
|
"name": "@bbob/react",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "lib/index.js",
|
|
||||||
"directories": {
|
|
||||||
"lib": "lib"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/JiLiZART/bbob.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bbob",
|
"bbob",
|
||||||
"react",
|
"react",
|
||||||
"helper"
|
"helper"
|
||||||
],
|
],
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/JiLiZART/bbob/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/JiLiZART/bbob#readme",
|
|
||||||
"scripts": {
|
|
||||||
"test": "../../node_modules/.bin/jest --",
|
|
||||||
"cover": "../../node_modules/.bin/jest --coverage",
|
|
||||||
"lint": "../../node_modules/.bin/eslint ."
|
|
||||||
},
|
|
||||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
|
||||||
"license": "MIT",
|
|
||||||
"publishConfig": {
|
|
||||||
"registry": "https://registry.npmjs.org/"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bbob/core": "^1.1.0",
|
"@bbob/core": "^1.1.0",
|
||||||
|
"@bbob/html": "^1.1.0",
|
||||||
"@bbob/plugin-helper": "^1.1.0",
|
"@bbob/plugin-helper": "^1.1.0",
|
||||||
"@bbob/preset-html5": "^1.1.0",
|
"@bbob/preset-react": "^1.1.0",
|
||||||
"prop-types": "^15.6.1"
|
"prop-types": "^15.6.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": "15.x"
|
"react": "15.x"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-preset-react": "^6.24.1",
|
|
||||||
"enzyme": "^3.4.0",
|
"enzyme": "^3.4.0",
|
||||||
"enzyme-adapter-react-15": "^1.0.6",
|
"enzyme-adapter-react-15": "^1.0.6",
|
||||||
"react": "15.x",
|
"react": "15.x",
|
||||||
"react-dom": "^15.6.2",
|
"react-dom": "^15.6.2",
|
||||||
"react-test-renderer": "^15.6.2"
|
"react-test-renderer": "^15.6.2"
|
||||||
}
|
},
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"module": "es/index.js",
|
||||||
|
"jsnext:main": "es/index.js",
|
||||||
|
"browser": "dist/index.js",
|
||||||
|
"browserName": "BbobReact",
|
||||||
|
"homepage": "https://github.com/JiLiZART/bbob",
|
||||||
|
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/JiLiZART/bbob.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||||
|
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||||
|
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||||
|
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||||
|
"test": "../../node_modules/.bin/jest --",
|
||||||
|
"cover": "../../node_modules/.bin/jest --coverage",
|
||||||
|
"lint": "../../node_modules/.bin/eslint .",
|
||||||
|
"size": "../../node_modules/.bin/size-limit"
|
||||||
|
},
|
||||||
|
"size-limit": [
|
||||||
|
{
|
||||||
|
"path": "lib/index.js"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"registry": "https://registry.npmjs.org/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist",
|
||||||
|
"lib",
|
||||||
|
"src",
|
||||||
|
"es"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const PropTypes = require('prop-types');
|
const PropTypes = require('prop-types');
|
||||||
const core = require('@bbob/core');
|
|
||||||
const render = require('./render');
|
|
||||||
|
|
||||||
const toAST = (source, plugins) => core(plugins).process(source).tree;
|
const { render } = require('./render');
|
||||||
|
|
||||||
const content = (children, plugins) => React.Children.map(children, child =>
|
const content = (children, plugins) => React.Children.map(children, child =>
|
||||||
(typeof child === 'string' ? render(toAST(child, plugins)) : child));
|
(typeof child === 'string' ? render(child, plugins) : child));
|
||||||
|
|
||||||
const Component = props =>
|
const Component = props =>
|
||||||
React.createElement(props.container, {}, content(props.children, props.plugins));
|
React.createElement(props.container, {}, content(props.children, props.plugins));
|
||||||
@@ -24,4 +22,4 @@ Component.defaultProps = {
|
|||||||
plugins: [],
|
plugins: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Component;
|
export default Component;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { default } from './Component';
|
||||||
|
export { render } from './render';
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const { isTagNode, isStringNode } = require('@bbob/plugin-helper');
|
import core from '@bbob/core';
|
||||||
|
import html from '@bbob/html';
|
||||||
|
|
||||||
|
import { isTagNode, isStringNode } from '@bbob/plugin-helper';
|
||||||
|
|
||||||
|
const toAST = (source, plugins) => core(plugins)
|
||||||
|
.process(source, {
|
||||||
|
render: input => html(input, { stripTags: true }),
|
||||||
|
}).tree;
|
||||||
|
|
||||||
function tagToReactElement(node) {
|
function tagToReactElement(node) {
|
||||||
if (node.content === null) {
|
if (node.content === null) {
|
||||||
@@ -14,11 +22,11 @@ function tagToReactElement(node) {
|
|||||||
node.tag,
|
node.tag,
|
||||||
node.attrs,
|
node.attrs,
|
||||||
// eslint-disable-next-line no-use-before-define
|
// eslint-disable-next-line no-use-before-define
|
||||||
render(node.content),
|
renderToReactNodes(node.content),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function render(nodes) {
|
function renderToReactNodes(nodes) {
|
||||||
const els = nodes.reduce((arr, node) => {
|
const els = nodes.reduce((arr, node) => {
|
||||||
if (isTagNode(node)) {
|
if (isTagNode(node)) {
|
||||||
arr.push(tagToReactElement(node));
|
arr.push(tagToReactElement(node));
|
||||||
@@ -32,4 +40,9 @@ function render(nodes) {
|
|||||||
return els;
|
return els;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = render;
|
function render(source, plugins) {
|
||||||
|
return renderToReactNodes(toAST(source, plugins));
|
||||||
|
}
|
||||||
|
|
||||||
|
export { render };
|
||||||
|
export default render;
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const { shallow } = require('enzyme');
|
import preset from '@bbob/preset-react';
|
||||||
const BBCode = require('../lib');
|
|
||||||
const presetHTML5 = require('../lib/preset-html5');
|
|
||||||
const Enzyme = require('enzyme');
|
|
||||||
const Adapter = require('enzyme-adapter-react-15');
|
|
||||||
|
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
import Enzyme from 'enzyme';
|
||||||
|
import Adapter from 'enzyme-adapter-react-15';
|
||||||
|
|
||||||
|
import BBCode from '../src';
|
||||||
Enzyme.configure({ adapter: new Adapter() });
|
Enzyme.configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
const renderBBCode = input => shallow(
|
const renderBBCode = input => shallow(
|
||||||
<BBCode plugins={[presetHTML5()]}>{input}</BBCode>
|
<BBCode plugins={[preset()]}>{input}</BBCode>
|
||||||
).html();
|
).html();
|
||||||
|
|
||||||
describe('@bbob/react', () => {
|
describe('@bbob/react', () => {
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||||
|
import babel from 'rollup-plugin-babel';
|
||||||
|
import replace from 'rollup-plugin-replace';
|
||||||
|
import commonjs from 'rollup-plugin-commonjs';
|
||||||
|
import { uglify } from 'rollup-plugin-uglify';
|
||||||
|
|
||||||
|
const pkg = require(`${process.cwd()}/package.json`);
|
||||||
|
const env = process.env.NODE_ENV;
|
||||||
|
|
||||||
|
const globals = {
|
||||||
|
react: 'React',
|
||||||
|
vue: 'Vue',
|
||||||
|
};
|
||||||
|
const external = ['react', 'vue'];
|
||||||
|
|
||||||
|
const input = 'src/index.js';
|
||||||
|
|
||||||
|
const plugins = [
|
||||||
|
nodeResolve(),
|
||||||
|
babel({
|
||||||
|
exclude: '**/node_modules/**',
|
||||||
|
}),
|
||||||
|
replace({
|
||||||
|
'process.env.NODE_ENV': JSON.stringify(env),
|
||||||
|
}),
|
||||||
|
commonjs(),
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
input,
|
||||||
|
external,
|
||||||
|
output: {
|
||||||
|
file: pkg.browser,
|
||||||
|
format: 'umd',
|
||||||
|
name: pkg.browserName,
|
||||||
|
globals: {
|
||||||
|
react: 'React',
|
||||||
|
vue: 'Vue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input,
|
||||||
|
external,
|
||||||
|
output: {
|
||||||
|
file: pkg.browser.replace('.js', '.min.js'),
|
||||||
|
format: 'umd',
|
||||||
|
name: pkg.browserName,
|
||||||
|
globals,
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
...plugins,
|
||||||
|
uglify({
|
||||||
|
compress: {
|
||||||
|
pure_getters: true,
|
||||||
|
unsafe: true,
|
||||||
|
unsafe_comps: true,
|
||||||
|
warnings: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user