-
Notifications
You must be signed in to change notification settings - Fork 695
Description
Issue
When one has a string
with format markdown
, json-editor automatically chooses the SimpleMDE editor. This is because of this line:
Line 122 in bb387ec
const markdown = schema => schema.type === 'string' && schema.format === 'markdown' && 'simplemde' |
On the other hand, the Ace editor would in principle support markdown, but the markdown
format is not associated with it:
Line 127 in bb387ec
const aceModes = ['actionscript', 'batchfile', 'c', 'c++', 'cpp', 'coffee', 'csharp', 'css', 'dart', 'django', 'ejs', 'erlang', 'golang', 'groovy', 'handlebars', 'haskell', 'haxe', 'html', 'ini', 'jade', 'java', 'javascript', 'json', 'less', 'lisp', 'lua', 'makefile', 'matlab', 'mysql', 'objectivec', 'pascal', 'perl', 'pgsql', 'php', 'python', 'prql', 'r', 'ruby', 'rust', 'sass', 'scala', 'scss', 'sh', 'smarty', 'sql', 'sqlserver', 'stylus', 'svg', 'typescript', 'twig', 'vbscript', 'xml', 'yaml', 'zig'] |
Current situation
To mitigate this, one can do something like this as a workaround:
// Add a resolver function to the beginning of the resolver list
// This will make it run before any other ones
JSONEditor.defaults.resolvers.unshift(schema => {
if(schema.type === "string" && schema.format === "markdown") {
return "ace";
}
});
Proposal
A more general approach, using a newly introduced options.resolver
property:
JSONEditor.defaults.resolvers.unshift(schema => schema.options?.resolver && schema.options.resolver)
This would allow passing a schema like so:
[...]
"foobar": {
"type": "string",
"format": "markdown",
"options": {
"resolver": "ace"
}
}
[...]
Could it be a good addition to let the developer manually override the chosen editor, like e.g. the options.resolver
property mentioned above? This would solve the Ace editor situation, but would also (in future) allow having multiple editors working next to each other for the same format (example: support upgrading SimpleMDE to EasyMDE as discussed here or introducing Monaco editor as discussed here).