Repository navigation
Move default language setting to Tokenizer - #3368
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
8cc94e1 to
d28288a
Compare
d28288a to
b986aa8
Compare
b986aa8 to
95c4e4f
Compare
95c4e4f to
23ffa80
Compare
23ffa80 to
f64ce4d
Compare
f64ce4d to
292abd1
Compare
292abd1 to
1c4dabb
Compare
1c4dabb to
e17bca2
Compare
thegreatercurve
left a comment
There was a problem hiding this comment.
@saint1991 The default language changes seems fine, but I think we'd want to leave out the preserve flag. Users can just implement this themselves by extending the CodeNode and overwriting the collapseAtStart method.
e17bca2 to
8699445
Compare
|
Thanks for your kind review! Thank you so much for the great work! export class CodeEditorNode extends CodeNode {
static getType(): string {
return 'code-editor';
}
collapseAtStart(): true {
return true;
}
}
export const $createCodeEditorNode = (language?: string | null | undefined): CodeEditorNode => {
return new CodeEditorNode(language);
}
const editor = createEditor({
nodes: [
CodeEditorNode,
CodeNode: {
replace: CodeNode,
with: (node: CodeNode) => $createCodeEditorNode(node.getLanguage())
},
CodeHighlightNode,
]
}) |
There was a problem hiding this comment.
This should just be enough:
| declare export function $createCodeNode(language?: string | null): CodeNode; | |
| declare export function $createCodeNode(language: ?string): CodeNode; |
8699445 to
727032e
Compare
727032e to
d4176a5
Compare
|
I'm curious if it's better to have default language as a param to |
|
I think it's also OK, but I put the setting here because the supported languages depend on Tokenizer's implementation. The setting 'javascript' is one of the proper choices for PrismTokenizer because Prism supports it. In terms of the use of the library, the difference is that users should specify the default language even when they use PrismTokenizer by default. |
1. Add a preserve feature to CodeNodeIn the original implementation, CodeNode is removed when the backward deletion occurs at the beginning of the Node.In some use cases, implementing a code editor, such behavior is not needed.The "Preserve" setting is for making it controllable.2. Move the default language setting to Tokenizer
The former PR #3243 enabled to use arbitrary Tokenizer other than Prism and 'javascript' is not always appropriate to the default so make it a Tokenizer setting.
This PR contains 2 changes but I'm happy to divide them if required.