Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: @rocket.chat/message-parser #443

Merged
merged 67 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
73f1b8c
WIP
ggazzo Apr 26, 2021
0fe7aa0
wip
ggazzo Apr 28, 2021
b168c04
wip
ggazzo May 2, 2021
83dc639
Merge branch 'develop' into feat/message-parser
ggazzo May 2, 2021
5e32aa4
Draft done
ggazzo May 3, 2021
b113b8d
Merge branch 'feat/message-parser' of github.com:RocketChat/Rocket.Ch…
ggazzo May 3, 2021
0c487e8
Readme
ggazzo May 3, 2021
9d4d65b
Add ESLint
tassoevan May 3, 2021
a5fa1b2
Ensure array argument to heading()
tassoevan May 3, 2021
1e61e27
Rename package
tassoevan May 3, 2021
d72ccd2
mentions
ggazzo May 3, 2021
a854f09
Merge branch 'feat/message-parser' of github.com:RocketChat/Rocket.Ch…
ggazzo May 3, 2021
47cbcdf
Upgrade some type definitions
tassoevan May 3, 2021
a6ebe27
Build from TypeScript
tassoevan May 3, 2021
195e7f7
Move loaders
tassoevan May 3, 2021
63f68dd
Emoji
ggazzo May 3, 2021
63976b8
Merge branch 'feat/message-parser' of github.com:RocketChat/Rocket.Ch…
ggazzo May 3, 2021
978daec
Enable peg files in Jest on watch mode
tassoevan May 4, 2021
5481d91
uris
ggazzo May 4, 2021
9af386b
Run prettier on *.pegjs files
tassoevan May 4, 2021
e23f435
phone
ggazzo May 4, 2021
1b2cfb4
Merge branch 'feat/message-parser' of github.com:RocketChat/Rocket.Ch…
ggazzo May 4, 2021
ab3abb2
colors
ggazzo May 4, 2021
ec12bca
Use Jest expectations instead of assert package
tassoevan May 4, 2021
a58ba1a
mehh
ggazzo May 4, 2021
ab4b538
Merge branch 'feat/message-parser' of github.com:RocketChat/Rocket.Ch…
ggazzo May 4, 2021
cfe9008
Bundle to multiple formats
tassoevan May 4, 2021
d8f1bf6
Use Babel to transpile JS code from *.pegjs
tassoevan May 4, 2021
5f65c2b
Write tests as tables
tassoevan May 4, 2021
932bddb
Add more test cases do strong emphasis
tassoevan May 4, 2021
778c5bd
Add more test cases to emphasis
tassoevan May 4, 2021
5b8f0ae
Add more test cases to strikethrough
tassoevan May 4, 2021
1adb7f2
Add more test cases to headings
tassoevan May 4, 2021
a64baae
Export a simple type guard
tassoevan May 4, 2021
ac4a676
Refine color rule
tassoevan May 4, 2021
7427d6a
Strike pass
ggazzo May 5, 2021
d79ba9c
Emphasis pass
ggazzo May 5, 2021
1bbab6e
Bold pass
ggazzo May 5, 2021
2a71b3c
Gloria
ggazzo May 5, 2021
1688f09
AEEEEEOO
ggazzo May 5, 2021
38f5446
Code
ggazzo May 5, 2021
6e36d0f
Code lang
ggazzo May 5, 2021
c6c875c
Removed index file
ggazzo May 5, 2021
e850a4d
Extract rgba value from color
tassoevan May 5, 2021
f6964b5
opss
ggazzo May 5, 2021
f2e5052
Merge branch 'feat/message-parser' of github.com:RocketChat/Rocket.Ch…
ggazzo May 5, 2021
9e80724
fix uri
ggazzo May 5, 2021
7b09955
Improve phone links
tassoevan May 5, 2021
287f6c1
Add stricter URL definition
tassoevan May 5, 2021
0a04938
Big Emoji
ggazzo May 5, 2021
366b331
Add test cases for email
tassoevan May 5, 2021
8150988
Prototype email rule
tassoevan May 5, 2021
1d99808
98% sure about domains emails and urls
ggazzo May 6, 2021
52f2d53
Fix big Emoji
ggazzo May 6, 2021
7ed8bf6
codegueira++
ggazzo May 6, 2021
eb3a2b5
Fix Build
ggazzo May 6, 2021
fae85f4
Remove unused rules
tassoevan May 6, 2021
3cc8194
Task list
ggazzo May 6, 2021
4d47ed8
Merge branch 'feat/message-parser' of github.com:RocketChat/Rocket.Ch…
ggazzo May 6, 2021
d1d84f3
missing file
ggazzo May 6, 2021
0fce8ea
Lists
ggazzo May 6, 2021
b9bc8bd
Fix unordered list using *
ggazzo May 6, 2021
b94f78c
quotes
ggazzo May 6, 2021
fa8f0d7
README
ggazzo May 6, 2021
53050a3
Fix typo
tassoevan May 6, 2021
353e0c1
Update READMEs
tassoevan May 6, 2021
61fbb66
Update README
tassoevan May 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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