-
Notifications
You must be signed in to change notification settings - Fork 13.8k
feat: hand written parser #40717
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
Open
amitkumarashutosh
wants to merge
42
commits into
RocketChat:develop
Choose a base branch
from
amitkumarashutosh:feat/hand-written-parser
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: hand written parser #40717
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
049c995
feat: initial parser implementation (33/634)
amitkumarashutosh 30b187a
feat: implement paragraph and line break parsing (144/634)
amitkumarashutosh b9bb672
feat: introduce scanner-based parsing
amitkumarashutosh 85f8053
feat: add escape sequences and inline code parsing (158/634)
amitkumarashutosh 79fee3d
Merge branch 'RocketChat:develop' into feat/hand-written-parser
amitkumarashutosh 33d22c2
feat: add bold, italic, and strikethrough inline parsing (262/634)
amitkumarashutosh ad257b1
feat: add heading, user and channel mention parsing (311/634)
amitkumarashutosh b96e5a5
feat: add code fence block parsing (319/634)
amitkumarashutosh 5edfaf8
feat: add blockquote parsing with support for > prefix and inline mar…
amitkumarashutosh f3bc070
feat: add inline and block spoiler parsing with || delimiter support …
amitkumarashutosh 5f26623
feat: add markdown and angle bracket link parsing (396/634)
amitkumarashutosh c788f6f
fix: handle Rocket.Cat style tokens as links (401/634)
amitkumarashutosh 411372d
feat: add unordered and ordered list parsing (404/634)
amitkumarashutosh 7425327
feat: add KaTeX block and inline parsing with dollar sign (413/634)
amitkumarashutosh 5193ebc
feat: add auto-link URL detection (462/634)
amitkumarashutosh 9eb1ce6
feat: add emoji shortcode parsing (492/634)
amitkumarashutosh 65fd782
feat: add email autolinking support (508/634)
amitkumarashutosh 84ffcd0
feat: add phone number autolinking (516/634)
amitkumarashutosh c67061d
feat: add timestamp parsing (529/634)
amitkumarashutosh 721fe0f
feat: add emoticon parsing (554/634)
amitkumarashutosh bfb7b12
refactor: clean up message parser structure and typing (573/634)
amitkumarashutosh a21b870
feat: parse raw unicode emoji (600/634)
amitkumarashutosh 225d0bf
fix: treat leading-asterisk and guard @mention after alphanumeric (60…
amitkumarashutosh bfe1220
feat: parse color:#rgb syntax (605/635)
amitkumarashutosh 50f0ec2
Merge branch 'develop' into feat/hand-written-parser
amitkumarashutosh 3a3fc48
refactor: improve timestamp parsing and clean up parser logic (646/688)
amitkumarashutosh 50de391
feat: add image parsing support (649/688)
amitkumarashutosh a93bc2f
feat: add task list support (650/688)
amitkumarashutosh 4686ddb
feat: add horizontal rule support (654/688)
amitkumarashutosh 18cbe96
fix: handle escaped timestamps and reject relative link target (656/688)
amitkumarashutosh 4990d98
feat: add table parsing support (664/688)
amitkumarashutosh 6cde70c
Merge branch 'RocketChat:develop' into feat/hand-written-parser
amitkumarashutosh dadf6b9
fix: reject malformed URL structures in autolink (698/717)
amitkumarashutosh 0efa86b
fix: correct link label parsing and simplify inline parser (704/717)
amitkumarashutosh 76463ce
fix: add skipReferences guard for link labels and fix emoticon neighb…
amitkumarashutosh 5f8f89b
fix: underscore-italic word boundaries and plain-wrapping (717/717)
amitkumarashutosh 62d2249
refactor: address review feedback, fix esLint errors
amitkumarashutosh 0e47bc2
chore: remove peggy loader and cleanup config
amitkumarashutosh a398af3
Merge branch 'RocketChat:develop' into feat/hand-written-parser
amitkumarashutosh 040bc19
fix: parse keycap emoji sequences as single tokens (718/718)
amitkumarashutosh e4d5261
Merge branch 'RocketChat:develop' into feat/hand-written-parser
amitkumarashutosh 908011a
fix: restore inline guards in finally and extract table cellAlignment…
amitkumarashutosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,8 @@ | ||
| import { dirname, resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| import server from '@rocket.chat/jest-presets/server'; | ||
| import type { Config } from 'jest'; | ||
|
|
||
| // Jest 30 loads this config via Node's native type stripping (Node 22.18+), | ||
| // which treats the file as ESM where __dirname is not defined as a global. | ||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| export default { | ||
| preset: server.preset, | ||
| transform: { | ||
| '\\.pegjs$': resolve(__dirname, './loaders/pegtransform.js'), | ||
| }, | ||
| moduleFileExtensions: ['js', 'ts', 'pegjs'], | ||
| moduleFileExtensions: ['js', 'ts'], | ||
| testPathIgnorePatterns: ['/node_modules/', '\\.bench\\.ts$'], | ||
| } satisfies Config; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| export function isNewline(ch: string): boolean { | ||
| return ch === '\n' || ch === '\r'; | ||
| } | ||
|
|
||
| export function isSpace(ch: string): boolean { | ||
| return ch === ' ' || ch === '\t'; | ||
| } | ||
|
|
||
| export function isWhitespace(ch: string): boolean { | ||
| return isSpace(ch) || isNewline(ch); | ||
| } | ||
|
|
||
| export function isDigit(ch: string): boolean { | ||
| return ch >= '0' && ch <= '9'; | ||
| } | ||
|
|
||
| export function isAlpha(ch: string): boolean { | ||
| return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); | ||
| } | ||
|
|
||
| export function isAlphaNum(ch: string): boolean { | ||
| return isAlpha(ch) || isDigit(ch); | ||
| } | ||
|
|
||
| export function isMarkupChar(ch: string): boolean { | ||
| return '*_~`#@:|\\[!<$+()'.includes(ch); | ||
| } | ||
|
|
||
| export function isPlainChar(ch: string): boolean { | ||
| return ch !== '' && !isNewline(ch) && !isMarkupChar(ch) && !isSpace(ch); | ||
| } | ||
|
|
||
| export function isUrlStart(ch: string): boolean { | ||
| return isAlpha(ch) || isDigit(ch); | ||
| } | ||
|
|
||
| export function isEmailStart(ch: string): boolean { | ||
| return isUrlStart(ch) || ch.charCodeAt(0) > 127; | ||
| } | ||
|
|
||
| export function isEmojiStart(ch: string): boolean { | ||
| const code = ch.charCodeAt(0); | ||
| return ( | ||
| code === 0xa9 || | ||
| code === 0xae || | ||
| code === 0x203c || | ||
| code === 0x2049 || | ||
| code === 0x2122 || | ||
| code === 0x2139 || | ||
| (code >= 0x2194 && code <= 0x21aa) || // Arrows | ||
| (code >= 0x231a && code <= 0x23fa) || // Misc Technical | ||
| code === 0x24c2 || | ||
| (code >= 0x25aa && code <= 0x27bf) || // Geometric Shapes, Symbols, Dingbats | ||
| (code >= 0x2934 && code <= 0x2b55) || // Supplemental Arrows | ||
| code === 0x3030 || | ||
| code === 0x303d || | ||
| code === 0x3297 || | ||
| code === 0x3299 || | ||
| (code >= 0xd800 && code <= 0xdbff) || // High surrogates (U+10000+ emoji) | ||
| ch === '#' || // keycap bases | ||
| ch === '*' || | ||
| (ch >= '0' && ch <= '9') | ||
| ); | ||
| } | ||
|
|
||
| export function isHexDigit(ch: string): boolean { | ||
| return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'); | ||
| } | ||
|
|
||
| // ─── Emoticon ────────────────────────────────────────────────────────────── | ||
| export const EMOTICONS: Record<string, string> = { | ||
| ':)': 'slight_smile', | ||
| ':-)': 'slight_smile', | ||
| ':(': 'frowning', | ||
| ':-(': 'frowning', | ||
| 'D:': 'fearful', | ||
| ':D': 'grinning', | ||
| ':-D': 'grinning', | ||
| ':P': 'stuck_out_tongue', | ||
| ':-P': 'stuck_out_tongue', | ||
| ':p': 'stuck_out_tongue', | ||
| ':-p': 'stuck_out_tongue', | ||
| ';)': 'wink', | ||
| ';-)': 'wink', | ||
| ':o': 'open_mouth', | ||
| ':-o': 'open_mouth', | ||
| ':O': 'open_mouth', | ||
| ':-O': 'open_mouth', | ||
| ':|': 'neutral_face', | ||
| ':-|': 'neutral_face', | ||
| ':/': 'confused', | ||
| ':-/': 'confused', | ||
| ':\\': 'confused', | ||
| ':-\\': 'confused', | ||
| ':*': 'kissing_heart', | ||
| '-_-': 'expressionless', | ||
| }; | ||
|
|
||
| // Sorted longest-first so e.g. ":-D" wins over ":D" | ||
| export const EMOTICON_KEYS = Object.keys(EMOTICONS).sort((a, b) => b.length - a.length); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.