-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Move default language setting to Tokenizer #3368
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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,
]
}) |
@@ -33,7 +33,7 @@ declare export class CodeNode extends ElementNode { | |||
setLanguage(language: string): void; | |||
getLanguage(): string | void; | |||
} | |||
declare export function $createCodeNode(language?: string): CodeNode; | |||
declare export function $createCodeNode(language?: string | null): CodeNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be enough:
declare export function $createCodeNode(language?: string | null): CodeNode; | |
declare export function $createCodeNode(language: ?string): CodeNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thegreatercurve
Thanks. Fixed it.
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.