Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/54-invalid-tags-eaten
Browse files Browse the repository at this point in the history
  • Loading branch information
JiLiZART authored Apr 5, 2020
2 parents a491001 + 97ecba0 commit dd7e2bb
Show file tree
Hide file tree
Showing 35 changed files with 224 additions and 52 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25)


### Features

* **core:** allow to pass dynamic data in options for render ([#59](https://github.com/JiLiZART/bbob/issues/59)) ([0b74be7](https://github.com/JiLiZART/bbob/commit/0b74be78304f8206f1b36627206fb517924e08e4))





<a name="2.5.4"></a>
## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ const App = ({ renderProp }) => (
render(<App />) // <span><span style="font-weight: bold;">Super <span style="font-style: italic;">easy</span></span> <span style="text-decoration: underline;">to</span> render</span>
```

[![Edit x7w52lqmzz](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/x7w52lqmzz)
[![Edit x7w52lqmzz](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/jovial-cohen-bvo08)

### PostHTML usage <a name="posthtml"></a>

Expand Down
7 changes: 6 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"lerna": "2.11.0",
"version": "2.5.5",
"packages": [
"packages/bbob-cli",
"packages/bbob-core",
Expand All @@ -15,5 +16,9 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"version": "2.5.4"
"command": {
"version": {
"message": "chore(release): publish %s"
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"scripts": {
"prepublishOnly": "npm run test",
"bootstrap": "lerna bootstrap",
"publish-all": "lerna run --parallel build && lerna publish --conventional-commits --registry=https://registry.npmjs.org/",
"publish-patch": "lerna run --parallel build && lerna publish --conventional-commits --cd-version patch --registry=https://registry.npmjs.org/",
"publish-all": "lerna run --parallel build && lerna publish --include-merged-tags --conventional-commits --create-release github --registry=https://registry.npmjs.org/",
"publish-patch": "lerna run --parallel build && lerna publish --include-merged-tags --conventional-commits --create-release github --cd-version patch --registry=https://registry.npmjs.org/",
"size": "lerna run --parallel size",
"bundlesize": "lerna run --parallel bundlesize",
"test": "npm run build && lerna run --parallel link && lerna run --parallel test",
Expand Down
8 changes: 8 additions & 0 deletions packages/bbob-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25)

**Note:** Version bump only for package @bbob/cli





<a name="2.5.4"></a>
## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25)

Expand Down
2 changes: 1 addition & 1 deletion packages/bbob-cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/bbob-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbob/cli",
"version": "2.5.4",
"version": "2.5.5",
"description": "Comand line bbcode parser",
"main": "lib/cli.js",
"bin": {
Expand All @@ -10,8 +10,8 @@
"lib": "lib"
},
"dependencies": {
"@bbob/html": "^2.5.4",
"@bbob/preset-html5": "^2.5.4",
"@bbob/html": "^2.5.5",
"@bbob/preset-html5": "^2.5.5",
"commander": "^2.15.1"
},
"repository": {
Expand Down
11 changes: 11 additions & 0 deletions packages/bbob-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25)


### Features

* **core:** allow to pass dynamic data in options for render ([#59](https://github.com/JiLiZART/bbob/issues/59)) ([0b74be7](https://github.com/JiLiZART/bbob/commit/0b74be78304f8206f1b36627206fb517924e08e4))





<a name="2.5.4"></a>
## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25)

Expand Down
2 changes: 1 addition & 1 deletion packages/bbob-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/bbob-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbob/core",
"version": "2.5.4",
"version": "2.5.5",
"description": "⚡️Blazing fast BBCode transforming and parsing tool in pure javascript, no dependencies ",
"keywords": [
"bbcode",
Expand All @@ -20,7 +20,7 @@
"core"
],
"dependencies": {
"@bbob/parser": "^2.5.4"
"@bbob/parser": "^2.5.5"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/bbob-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function bbob(plugs) {

const parseFn = options.parser || parse;
const renderFn = options.render;
const data = options.data || null;

if (typeof parseFn !== 'function') {
throw new Error('"parser" is not a function, please pass to "process(input, { parser })" right function');
Expand All @@ -41,6 +42,7 @@ export default function bbob(plugs) {
render: renderFn,
iterate,
match,
data,
}) || tree;
});

Expand Down
8 changes: 8 additions & 0 deletions packages/bbob-html/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25)

**Note:** Version bump only for package @bbob/html





<a name="2.5.4"></a>
## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25)

Expand Down
2 changes: 1 addition & 1 deletion packages/bbob-html/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/bbob-html/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@bbob/html",
"version": "2.5.4",
"version": "2.5.5",
"description": "HTML renderer for @bbob bbcode parser",
"keywords": [],
"dependencies": {
"@bbob/core": "^2.5.4",
"@bbob/plugin-helper": "^2.5.4"
"@bbob/core": "^2.5.5",
"@bbob/plugin-helper": "^2.5.5"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
8 changes: 8 additions & 0 deletions packages/bbob-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25)

**Note:** Version bump only for package @bbob/parser





<a name="2.5.4"></a>
## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25)

Expand Down
2 changes: 1 addition & 1 deletion packages/bbob-parser/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/bbob-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bbob/parser",
"version": "2.5.4",
"version": "2.5.5",
"description": "Just parses BBcode to AST array. Part of @bbob bbcode parser",
"keywords": [
"bbcode",
Expand All @@ -13,7 +13,7 @@
"parse"
],
"dependencies": {
"@bbob/plugin-helper": "^2.5.4"
"@bbob/plugin-helper": "^2.5.5"
},
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
69 changes: 60 additions & 9 deletions packages/bbob-parser/src/Token.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,70 @@ const TOKEN_TYPE_ATTR_VALUE = 'attr-value';
const TOKEN_TYPE_SPACE = 'space';
const TOKEN_TYPE_NEW_LINE = 'new-line';

const getTokenValue = (token) => token[TOKEN_VALUE_ID];
const getTokenLine = (token) => token[TOKEN_LINE_ID];
const getTokenColumn = (token) => token[TOKEN_COLUMN_ID];
/**
* @param {Token} token
* @returns {string}
*/
const getTokenValue = (token) => {
if (token && typeof token[TOKEN_VALUE_ID] !== 'undefined') {
return token[TOKEN_VALUE_ID];
}

return '';
};
/**
* @param {Token}token
* @returns {number}
*/
const getTokenLine = (token) => (token && token[TOKEN_LINE_ID]) || 0;
const getTokenColumn = (token) => (token && token[TOKEN_COLUMN_ID]) || 0;

/**
* @param {Token} token
* @returns {boolean}
*/
const isTextToken = (token) => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE
|| token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE
|| token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
}

const isTextToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_SPACE
|| token[TOKEN_TYPE_ID] === TOKEN_TYPE_NEW_LINE
|| token[TOKEN_TYPE_ID] === TOKEN_TYPE_WORD;
return false;
};

/**
* @param {Token} token
* @returns {boolean}
*/
const isTagToken = (token) => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
}

const isTagToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_TAG;
return false;
};
const isTagEnd = (token) => getTokenValue(token).charCodeAt(0) === SLASH.charCodeAt(0);
const isTagStart = (token) => !isTagEnd(token);
const isAttrNameToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
const isAttrValueToken = (token) => token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
const isAttrNameToken = (token) => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_NAME;
}

return false;
};

/**
* @param {Token} token
* @returns {boolean}
*/
const isAttrValueToken = (token) => {
if (token && typeof token[TOKEN_TYPE_ID] !== 'undefined') {
return token[TOKEN_TYPE_ID] === TOKEN_TYPE_ATTR_VALUE;
}

return false;
};

const getTagName = (token) => {
const value = getTokenValue(token);
Expand Down
12 changes: 10 additions & 2 deletions packages/bbob-parser/src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,23 @@ const parse = (input, opts = {}) => {
const getNodes = () => {
const lastNestedNode = nestedNodes.getLast();

return lastNestedNode ? lastNestedNode.content : nodes.toArray();
if (lastNestedNode && Array.isArray(lastNestedNode.content)) {
return lastNestedNode.content;
}

return nodes.toArray();
};

/**
* @private
* @param {TagNode} tag
*/
const appendNodes = (tag) => {
getNodes().push(tag);
const items = getNodes();

if (Array.isArray(items)) {
items.push(tag);
}
};

/**
Expand Down
26 changes: 23 additions & 3 deletions packages/bbob-parser/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,22 @@ export const createCharGrabber = (source, options) => {

return source.substr(start, cursor.pos - start);
},
getNext: () => source[cursor.pos + 1],
getPrev: () => source[cursor.pos - 1],
getNext: () => {
const nextPos = cursor.pos + 1;

if (nextPos <= (source.length - 1)) {
return source[nextPos];
}
return null;
},
getPrev: () => {
const prevPos = cursor.pos - 1;

if (typeof source[prevPos] !== 'undefined') {
return source[prevPos];
}
return null;
},
getCurr,
getRest,
/**
Expand Down Expand Up @@ -127,7 +141,13 @@ export const createList = (values = []) => {
/**
* @callback getLastCb
*/
const getLast = () => (nodes.length ? nodes[nodes.length - 1] : null);
const getLast = () => {
if (Array.isArray(nodes) && nodes.length > 0 && typeof nodes[nodes.length - 1] !== 'undefined') {
return nodes[nodes.length - 1];
}

return null;
};
/**
* @callback flushLastCb
* @return {*}
Expand Down
8 changes: 8 additions & 0 deletions packages/bbob-plugin-helper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.5.5](https://github.com/JiLiZART/bbob/compare/v2.5.4...v2.5.5) (2020-03-25)

**Note:** Version bump only for package @bbob/plugin-helper





<a name="2.5.4"></a>
## [2.5.4](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.4) (2019-09-25)

Expand Down
Loading

0 comments on commit dd7e2bb

Please sign in to comment.