Skip to content

Commit 4722cdf

Browse files
ggazzotassoevan
andauthored
feat: @rocket.chat/message-parser (#443)
Co-authored-by: Tasso Evangelista <tasso.evangelista@rocket.chat>
1 parent 6e19830 commit 4722cdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3641
-83
lines changed

.vscode/settings.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"directory": "packages/memo",
3333
"changeProcessCWD": true
3434
},
35+
{
36+
"directory": "packages/message-parser",
37+
"changeProcessCWD": true
38+
},
3539
{
3640
"directory": "packages/mp3-encoder",
3741
"changeProcessCWD": true
@@ -53,8 +57,11 @@
5357
"source.fixAll.eslint": true
5458
},
5559
"eslint.options": {
56-
"extensions": [".js", ".jsx", ".md", ".mdx", ".ts", ".tsx"]
60+
"extensions": [".js", ".jsx", ".md", ".mdx", ".ts", ".tsx", ".pegjs"]
5761
},
5862
"editor.formatOnSave": true,
59-
"editor.defaultFormatter": "esbenp.prettier-vscode"
63+
"editor.defaultFormatter": "esbenp.prettier-vscode",
64+
"[pegjs]": {
65+
"editor.defaultFormatter": "esbenp.prettier-vscode"
66+
}
6067
}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Package |
1212
[`@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)
1313
[`@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)
1414
[`@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)
15+
[`@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)
1516
[`@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)
1617
[`@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)
1718
[`@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)

packages/css-in-js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@rollup/plugin-json": "^4.1.0",
4646
"@rollup/plugin-node-resolve": "^11.0.1",
4747
"@rollup/plugin-typescript": "^8.1.0",
48-
"@types/jest": "^26.0.22",
48+
"@types/jest": "^26.0.23",
4949
"@types/stylis": "^4.0.0",
5050
"documentation": "^13.2.1",
5151
"eslint": "^7.24.0",

packages/emitter/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@rollup/plugin-json": "^4.1.0",
5252
"@rollup/plugin-node-resolve": "^11.0.1",
5353
"@rollup/plugin-typescript": "^8.1.0",
54-
"@types/jest": "^26.0.22",
54+
"@types/jest": "^26.0.23",
5555
"documentation": "^13.2.1",
5656
"eslint": "^7.24.0",
5757
"jest": "^26.6.3",

packages/fuselage-hooks/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@rollup/plugin-json": "^4.1.0",
5858
"@rollup/plugin-node-resolve": "^9.0.0",
5959
"@rollup/plugin-typescript": "^6.0.0",
60-
"@types/jest": "^26.0.22",
60+
"@types/jest": "^26.0.23",
6161
"@types/react": "^17.0.3",
6262
"@types/react-dom": "^17.0.3",
6363
"@types/resize-observer-browser": "^0.1.5",

packages/fuselage/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"@storybook/react": "^6.1.11",
8484
"@storybook/source-loader": "^6.1.11",
8585
"@storybook/theming": "^6.1.11",
86-
"@types/jest": "^26.0.22",
86+
"@types/jest": "^26.0.23",
8787
"autoprefixer": "^10.0.1",
8888
"babel-loader": "^8.1.0",
8989
"caniuse-lite": "^1.0.30001151",

packages/message-parser/.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/dist

packages/message-parser/.eslintrc.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
extends: '@rocket.chat/eslint-config-alt/minimal',
3+
env: {
4+
jest: true,
5+
},
6+
overrides: [
7+
{
8+
files: ['**/*.ts', '**/*.tsx'],
9+
extends: '@rocket.chat/eslint-config-alt/typescript',
10+
},
11+
],
12+
};

packages/message-parser/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/dist
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@rocket.chat/prettier-config/fuselage');

packages/message-parser/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# @rocket.chat/message-parser
2+
3+
## Description
4+
5+
Rocket.Chat grammar with the purpose of parsing the messages of the rocket chat, converting text to an AST tree.
6+
7+
The grammar provides support for markdown, mentions and emojis.
8+
9+
## Supported markup
10+
11+
- quotes
12+
- bold/italic/strike
13+
- ordered lists
14+
- unordered lists
15+
- task lists
16+
- phone numbers
17+
- mentions
18+
- emoji
19+
- colors
20+
- URI's
21+
- mentions users/channels
22+
23+
## Contributing
24+
25+
Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/RocketChat/Rocket.Chat.Fuselage/issues).
26+
27+
Whenever you find a grammar-related bug, start by inserting the test case.
28+
29+
We are open to other tags/markups, as long as they don't generate unexpected behavior.
30+
31+
## Observations and known issues
32+
33+
- Nested lists are unsupported
34+
- `URL` rule doesn't allow ` `, `(`, or `)`
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
browsers: [
8+
'Chrome >= 59',
9+
'FireFox >= 44',
10+
'Safari >= 7',
11+
'Explorer 11',
12+
'last 4 Edge versions',
13+
],
14+
},
15+
},
16+
],
17+
],
18+
};
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
coverageReporters: [],
5+
transform: {
6+
'\\.pegjs$': path.resolve(__dirname, './loaders/pegtransform.js'),
7+
},
8+
preset: 'ts-jest',
9+
errorOnDeprecated: true,
10+
testMatch: ['<rootDir>/tests/**/*.(spec|test).ts'],
11+
moduleFileExtensions: ['js', 'ts', 'pegjs'],
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const pegjs = require('peggy');
2+
3+
module.exports = (content) =>
4+
pegjs.generate(content, {
5+
output: 'source',
6+
format: 'commonjs',
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const pegjs = require('peggy');
2+
3+
module.exports = {
4+
process: (content) =>
5+
pegjs.generate(content, {
6+
output: 'source',
7+
format: 'commonjs',
8+
}),
9+
};
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint-disable import/no-unresolved */
2+
3+
if (process.env.NODE_ENV === 'production') {
4+
module.exports = require('./dist/messageParser.production.js');
5+
} else {
6+
module.exports = require('./dist/messageParser.development.js');
7+
}

packages/message-parser/package.json

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "@rocket.chat/message-parser",
3+
"description": "Rocket.Chat parser for messages",
4+
"version": "0.23.0",
5+
"author": {
6+
"name": "Rocket.Chat",
7+
"url": "https://rocket.chat/"
8+
},
9+
"license": "MIT",
10+
"homepage": "https://github.com/RocketChat/Rocket.Chat.Fuselage#readme",
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/RocketChat/Rocket.Chat.Fuselage.git",
14+
"directory": "packages/message-parser"
15+
},
16+
"bugs": {
17+
"url": "https://github.com/RocketChat/Rocket.Chat.Fuselage/issues"
18+
},
19+
"main": "messageParser.js",
20+
"exports": {
21+
".": {
22+
"default": "./messageParser.js"
23+
},
24+
"./index": {
25+
"default": "./messageParser.js"
26+
}
27+
},
28+
"module": "dist/messageParser.mjs",
29+
"unpkg": "dist/messageParser.umd.js",
30+
"types": "dist/index.d.ts",
31+
"files": [
32+
"/dist",
33+
"/messageParser.js"
34+
],
35+
"directories": {
36+
"test": "test"
37+
},
38+
"devDependencies": {
39+
"@babel/core": "^7.14.0",
40+
"@babel/eslint-parser": "^7.13.14",
41+
"@babel/preset-env": "^7.14.1",
42+
"@rocket.chat/eslint-config-alt": "workspace:packages/eslint-config-alt",
43+
"@rocket.chat/prettier-config": "workspace:packages/prettier-config",
44+
"@types/jest": "^26.0.23",
45+
"@types/node": "^14.14.43",
46+
"@typescript-eslint/parser": "^4.22.0",
47+
"babel-loader": "^8.2.2",
48+
"eslint": "^7.25.0",
49+
"jest": "^26.6.3",
50+
"lint-staged": "^10.5.4",
51+
"npm-run-all": "^4.1.5",
52+
"peggy": "^1.1.0",
53+
"prettier": "^2.2.1",
54+
"prettier-plugin-pegjs": "^0.3.2",
55+
"rimraf": "^3.0.2",
56+
"ts-jest": "^26.5.5",
57+
"ts-loader": "^9.1.1",
58+
"typescript": "^4.2.4",
59+
"webpack": "^5.36.2",
60+
"webpack-cli": "^4.6.0"
61+
},
62+
"publishConfig": {
63+
"access": "public"
64+
},
65+
"scripts": {
66+
"build": "run-s .:build:clean .:build:bundle",
67+
".:build:clean": "rimraf dist",
68+
".:build:bundle": "webpack",
69+
"test": "jest --runInBand --coverage",
70+
"watch": "jest --watch",
71+
"lint": "eslint .",
72+
"lint-fix": "run-p .:lint-fix:eslint .:lint-fix:prettier",
73+
".:lint-fix:eslint": "eslint --fix .",
74+
".:lint-fix:prettier": "prettier --write '**/*.pegjs'",
75+
"lint-staged": "lint-staged"
76+
}
77+
}

0 commit comments

Comments
 (0)