Repository navigation
Conversation
## Description
The Rust port had no `@lexical/markdown`. A new `markdown` feature (on
`rich-text`, `list`, `link` and `code`) ports it file by file from
`packages/lexical-markdown/src`:
- `MarkdownTransformers.ts`: the four transformer types, the built-in
transformers (`HEADING`, `QUOTE`, `CODE`, the lists, `CHECK_LIST`, the
text formats, `LINK`, `TRANSFORMERS`), the markdown NodeStates,
`normalizeMarkdown` and `isTableRowDivider`.
- `MarkdownImport.ts`, `importTextTransformers.ts`,
`importTextFormatTransformer.ts`, `importTextMatchTransformer.ts`.
- `MarkdownExport.ts`, with selection export.
- `utils.ts`, and `convert_from_markdown_string`,
`convert_to_markdown_string` and `convert_selection_to_markdown_string`.
Upstream's transformers are JS `RegExp`s whose sources are public API,
and the `regex` crate has no lookaround or backreferences, so the module
has its own small backtracking JS `RegExp` engine over UTF-16 code units.
That keeps the default build free of third-party crates. Its Unicode
tables (`\p{P}`, `\p{S}`, `\p{L}`, `\p{N}`, `\p{Zs}`, and the `i` flag's
case folding) are generated from Node by
`rust/scripts/generate-reg-exp-tables.mjs`. PARITY.md lists its two
approximations, which no upstream pattern reaches.
The conformance runner replays `markdown/import-export` (149 cases). It
uses upstream's five custom transformers, ported as Swift's runner ports
them, and also checks the Markdown field of `property/documents`.
Not ported: `registerMarkdownShortcuts` (next), and
`$generateNodesFromMarkdownString`, which needs `ArtificialNode`. The
mdast converter is not ported either, as in Swift. The `importHtml` field
waits for `@lexical/html`. Export cases read JS's state from
`exportState` instead of building it from HTML.
## Test plan
### Before
```
$ cargo run -p lexical-conformance -- markdown
| `markdown/import-export` | – | – | – | – | – | not implemented |
```
### After
```
$ cargo run -p lexical-conformance
| `markdown/import-export` | 149 | 149 | 0 | 0 | 0 | pass |
| `property/documents` (JSON, text and Markdown) | 121 | 121 | 0 | 0 | 0 | pass |
| **Total** | 637 | 637 | 0 | 0 | 0 | |
```
To confirm the checks run, I made each comparison fail on purpose. 147
cases failed on the imported state and 119 on the exported markdown,
which is every import and export case.
`cargo fmt --all --check`, `cargo clippy --workspace --all-targets
--all-features --locked -- -D warnings`, `cargo test --workspace
--all-features --locked` and `RUSTDOCFLAGS='-D warnings' cargo doc
--workspace --all-features --no-deps --locked` pass. So does
`cargo +1.88 check -p lexical-editor --all-features --locked`.
`cargo tree -p lexical-editor --features markdown` lists no dependencies.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1daf1-150e-709b-aaed-996443a64459
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The Rust port had no
@lexical/markdown. A newmarkdownfeature (onrich-text,list,linkandcode) ports it file by file frompackages/lexical-markdown/src:MarkdownTransformers.ts: the four transformer types, the built-intransformers (
HEADING,QUOTE,CODE, the lists,CHECK_LIST, thetext formats,
LINK,TRANSFORMERS), the markdown NodeStates,normalizeMarkdownandisTableRowDivider.MarkdownImport.ts,importTextTransformers.ts,importTextFormatTransformer.ts,importTextMatchTransformer.ts.MarkdownExport.ts, with selection export.utils.ts, andconvert_from_markdown_string,convert_to_markdown_stringandconvert_selection_to_markdown_string.Upstream's transformers are JS
RegExps whose sources are public API,and the
regexcrate has no lookaround or backreferences, so the modulehas its own small backtracking JS
RegExpengine over UTF-16 code units.That keeps the default build free of third-party crates. Its Unicode
tables (
\p{P},\p{S},\p{L},\p{N},\p{Zs}, and theiflag'scase folding) are generated from Node by
rust/scripts/generate-reg-exp-tables.mjs. PARITY.md lists its twoapproximations, which no upstream pattern reaches.
The conformance runner replays
markdown/import-export(149 cases). Ituses upstream's five custom transformers, ported as Swift's runner ports
them, and also checks the Markdown field of
property/documents.Not ported:
registerMarkdownShortcuts(next), and$generateNodesFromMarkdownString, which needsArtificialNode. Themdast converter is not ported either, as in Swift. The
importHtmlfieldwaits for
@lexical/html. Export cases read JS's state fromexportStateinstead of building it from HTML.Test plan
Before
After
To confirm the checks run, I made each comparison fail on purpose. 147
cases failed on the imported state and 119 on the exported markdown,
which is every import and export case.
cargo fmt --all --check,cargo clippy --workspace --all-targets --all-features --locked -- -D warnings,cargo test --workspace --all-features --lockedandRUSTDOCFLAGS='-D warnings' cargo doc --workspace --all-features --no-deps --lockedpass. So doescargo +1.88 check -p lexical-editor --all-features --locked.cargo tree -p lexical-editor --features markdownlists no dependencies.