Skip to content

Commit

Permalink
feat: @rocket.chat/message-parser (#443)
Browse files Browse the repository at this point in the history
Co-authored-by: Tasso Evangelista <[email protected]>
  • Loading branch information
ggazzo and tassoevan authored May 6, 2021
1 parent 6e19830 commit 4722cdf
Show file tree
Hide file tree
Showing 49 changed files with 3,641 additions and 83 deletions.
11 changes: 9 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"directory": "packages/memo",
"changeProcessCWD": true
},
{
"directory": "packages/message-parser",
"changeProcessCWD": true
},
{
"directory": "packages/mp3-encoder",
"changeProcessCWD": true
Expand All @@ -53,8 +57,11 @@
"source.fixAll.eslint": true
},
"eslint.options": {
"extensions": [".js", ".jsx", ".md", ".mdx", ".ts", ".tsx"]
"extensions": [".js", ".jsx", ".md", ".mdx", ".ts", ".tsx", ".pegjs"]
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[pegjs]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Package |
[`@rocket.chat/fuselage-ui-kit`](/packages/@rocket.chat/fuselage-ui-kit) | UiKit elements for Rocket.Chat Apps built under Fuselage design system | [![npm](https://img.shields.io/npm/v/@rocket.chat/fuselage-ui-kit.svg)](https://www.npmjs.com/package/@rocket.chat/fuselage-ui-kit) | [![David Peer](https://img.shields.io/david/peer/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/fuselage-ui-kit)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/fuselage-ui-kit&type=peer) | [![David Dev](https://img.shields.io/david/dev/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/fuselage-ui-kit)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/fuselage-ui-kit&type=dev) | [![David](https://img.shields.io/david/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/fuselage-ui-kit)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/fuselage-ui-kit)
[`@rocket.chat/icons`](/packages/@rocket.chat/icons) | | [![npm](https://img.shields.io/npm/v/@rocket.chat/icons.svg)](https://www.npmjs.com/package/@rocket.chat/icons) | [![David Peer](https://img.shields.io/david/peer/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/icons)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/icons&type=peer) | [![David Dev](https://img.shields.io/david/dev/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/icons)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/icons&type=dev) | [![David](https://img.shields.io/david/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/icons)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/icons)
[`@rocket.chat/memo`](/packages/@rocket.chat/memo) | Memoization utilities | [![npm](https://img.shields.io/npm/v/@rocket.chat/memo.svg)](https://www.npmjs.com/package/@rocket.chat/memo) | [![David Peer](https://img.shields.io/david/peer/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/memo)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/memo&type=peer) | [![David Dev](https://img.shields.io/david/dev/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/memo)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/memo&type=dev) | [![David](https://img.shields.io/david/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/memo)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/memo)
[`@rocket.chat/message-parser`](/packages/@rocket.chat/message-parser) | Rocket.Chat parser for messages | [![npm](https://img.shields.io/npm/v/@rocket.chat/message-parser.svg)](https://www.npmjs.com/package/@rocket.chat/message-parser) | [![David Peer](https://img.shields.io/david/peer/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/message-parser)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/message-parser&type=peer) | [![David Dev](https://img.shields.io/david/dev/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/message-parser)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/message-parser&type=dev) | [![David](https://img.shields.io/david/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/message-parser)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/message-parser)
[`@rocket.chat/mp3-encoder`](/packages/@rocket.chat/mp3-encoder) | A LAME encoder to be used in web workers | [![npm](https://img.shields.io/npm/v/@rocket.chat/mp3-encoder.svg)](https://www.npmjs.com/package/@rocket.chat/mp3-encoder) | [![David Peer](https://img.shields.io/david/peer/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/mp3-encoder)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/mp3-encoder&type=peer) | [![David Dev](https://img.shields.io/david/dev/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/mp3-encoder)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/mp3-encoder&type=dev) | [![David](https://img.shields.io/david/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/mp3-encoder)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/mp3-encoder)
[`@rocket.chat/prettier-config`](/packages/@rocket.chat/prettier-config) | Prettier configuration for Rocket.Chat repositories | [![npm](https://img.shields.io/npm/v/@rocket.chat/prettier-config.svg)](https://www.npmjs.com/package/@rocket.chat/prettier-config) | [![David Peer](https://img.shields.io/david/peer/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/prettier-config)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/prettier-config&type=peer) | [![David Dev](https://img.shields.io/david/dev/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/prettier-config)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/prettier-config&type=dev) | [![David](https://img.shields.io/david/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/prettier-config)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/prettier-config)
[`@rocket.chat/string-helpers`](/packages/@rocket.chat/string-helpers) | Helper functions for string manipulation | [![npm](https://img.shields.io/npm/v/@rocket.chat/string-helpers.svg)](https://www.npmjs.com/package/@rocket.chat/string-helpers) | [![David Peer](https://img.shields.io/david/peer/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/string-helpers)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/string-helpers&type=peer) | [![David Dev](https://img.shields.io/david/dev/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/string-helpers)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/string-helpers&type=dev) | [![David](https://img.shields.io/david/RocketChat/Rocket.Chat.Fuselage.svg?path=packages/string-helpers)](https://david-dm.org/RocketChat/Rocket.Chat.Fuselage?path=packages/string-helpers)
Expand Down
2 changes: 1 addition & 1 deletion packages/css-in-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-typescript": "^8.1.0",
"@types/jest": "^26.0.22",
"@types/jest": "^26.0.23",
"@types/stylis": "^4.0.0",
"documentation": "^13.2.1",
"eslint": "^7.24.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/emitter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-typescript": "^8.1.0",
"@types/jest": "^26.0.22",
"@types/jest": "^26.0.23",
"documentation": "^13.2.1",
"eslint": "^7.24.0",
"jest": "^26.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/jest": "^26.0.22",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3",
"@types/resize-observer-browser": "^0.1.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/fuselage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@storybook/react": "^6.1.11",
"@storybook/source-loader": "^6.1.11",
"@storybook/theming": "^6.1.11",
"@types/jest": "^26.0.22",
"@types/jest": "^26.0.23",
"autoprefixer": "^10.0.1",
"babel-loader": "^8.1.0",
"caniuse-lite": "^1.0.30001151",
Expand Down
2 changes: 2 additions & 0 deletions packages/message-parser/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/dist
12 changes: 12 additions & 0 deletions packages/message-parser/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: '@rocket.chat/eslint-config-alt/minimal',
env: {
jest: true,
},
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
extends: '@rocket.chat/eslint-config-alt/typescript',
},
],
};
2 changes: 2 additions & 0 deletions packages/message-parser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/dist
1 change: 1 addition & 0 deletions packages/message-parser/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@rocket.chat/prettier-config/fuselage');
34 changes: 34 additions & 0 deletions packages/message-parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @rocket.chat/message-parser

## Description

Rocket.Chat grammar with the purpose of parsing the messages of the rocket chat, converting text to an AST tree.

The grammar provides support for markdown, mentions and emojis.

## Supported markup

- quotes
- bold/italic/strike
- ordered lists
- unordered lists
- task lists
- phone numbers
- mentions
- emoji
- colors
- URI's
- mentions users/channels

## Contributing

Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/RocketChat/Rocket.Chat.Fuselage/issues).

Whenever you find a grammar-related bug, start by inserting the test case.

We are open to other tags/markups, as long as they don't generate unexpected behavior.

## Observations and known issues

- Nested lists are unsupported
- `URL` rule doesn't allow ` `, `(`, or `)`
18 changes: 18 additions & 0 deletions packages/message-parser/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
browsers: [
'Chrome >= 59',
'FireFox >= 44',
'Safari >= 7',
'Explorer 11',
'last 4 Edge versions',
],
},
},
],
],
};
12 changes: 12 additions & 0 deletions packages/message-parser/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const path = require('path');

module.exports = {
coverageReporters: [],
transform: {
'\\.pegjs$': path.resolve(__dirname, './loaders/pegtransform.js'),
},
preset: 'ts-jest',
errorOnDeprecated: true,
testMatch: ['<rootDir>/tests/**/*.(spec|test).ts'],
moduleFileExtensions: ['js', 'ts', 'pegjs'],
};
7 changes: 7 additions & 0 deletions packages/message-parser/loaders/pegloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const pegjs = require('peggy');

module.exports = (content) =>
pegjs.generate(content, {
output: 'source',
format: 'commonjs',
});
9 changes: 9 additions & 0 deletions packages/message-parser/loaders/pegtransform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const pegjs = require('peggy');

module.exports = {
process: (content) =>
pegjs.generate(content, {
output: 'source',
format: 'commonjs',
}),
};
7 changes: 7 additions & 0 deletions packages/message-parser/messageParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable import/no-unresolved */

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/messageParser.production.js');
} else {
module.exports = require('./dist/messageParser.development.js');
}
77 changes: 77 additions & 0 deletions packages/message-parser/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "@rocket.chat/message-parser",
"description": "Rocket.Chat parser for messages",
"version": "0.23.0",
"author": {
"name": "Rocket.Chat",
"url": "https://rocket.chat/"
},
"license": "MIT",
"homepage": "https://github.com/RocketChat/Rocket.Chat.Fuselage#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/RocketChat/Rocket.Chat.Fuselage.git",
"directory": "packages/message-parser"
},
"bugs": {
"url": "https://github.com/RocketChat/Rocket.Chat.Fuselage/issues"
},
"main": "messageParser.js",
"exports": {
".": {
"default": "./messageParser.js"
},
"./index": {
"default": "./messageParser.js"
}
},
"module": "dist/messageParser.mjs",
"unpkg": "dist/messageParser.umd.js",
"types": "dist/index.d.ts",
"files": [
"/dist",
"/messageParser.js"
],
"directories": {
"test": "test"
},
"devDependencies": {
"@babel/core": "^7.14.0",
"@babel/eslint-parser": "^7.13.14",
"@babel/preset-env": "^7.14.1",
"@rocket.chat/eslint-config-alt": "workspace:packages/eslint-config-alt",
"@rocket.chat/prettier-config": "workspace:packages/prettier-config",
"@types/jest": "^26.0.23",
"@types/node": "^14.14.43",
"@typescript-eslint/parser": "^4.22.0",
"babel-loader": "^8.2.2",
"eslint": "^7.25.0",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"npm-run-all": "^4.1.5",
"peggy": "^1.1.0",
"prettier": "^2.2.1",
"prettier-plugin-pegjs": "^0.3.2",
"rimraf": "^3.0.2",
"ts-jest": "^26.5.5",
"ts-loader": "^9.1.1",
"typescript": "^4.2.4",
"webpack": "^5.36.2",
"webpack-cli": "^4.6.0"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "run-s .:build:clean .:build:bundle",
".:build:clean": "rimraf dist",
".:build:bundle": "webpack",
"test": "jest --runInBand --coverage",
"watch": "jest --watch",
"lint": "eslint .",
"lint-fix": "run-p .:lint-fix:eslint .:lint-fix:prettier",
".:lint-fix:eslint": "eslint --fix .",
".:lint-fix:prettier": "prettier --write '**/*.pegjs'",
"lint-staged": "lint-staged"
}
}
Loading

0 comments on commit 4722cdf

Please sign in to comment.