joplin-math-mode
joplin-math-mode copied to clipboard
Draft: Native CodeMirror 6 support
Summary
At present, the Math Mode plugin doesn't work well in the CodeMirror 6-based beta editor. This pull request refactors the CodeMirror plugin to:
- Use CodeMirror 6 APIs when running in CodeMirror 6
- Use CodeMirror 5 APIs when running in CodeMirror 5.
Previously, CodeMirror 6 support was provided by Joplin's compatibility layer.
Why avoid the compatibility layer?
- Bugs
- Currently, only the last line of math seems to be rendered correctly.
- Issues with selection and inline results.
- The compatibility layer may be removed in the future.
Notes and resources
- Tutorial: Creating a Joplin plugin compatible with both CodeMirror 5 and CodeMirror 6 (takes a slightly different approach)
- CodeMirror 6 API documentation
- To allow correctly importing CodeMirror 6 libraries, the plugin build script was updated to the latest version.
- Many of the lines marked as added by
git
were moved fromsrc/mathMode.ts
, which was split into separate files.
To-do
- [ ] Improve refresh logic — currently, math isn't refreshed in some cases:
- [ ] Adding a configuration line to a math block.
- [ ] Converting a math block to a different type of code block.
- [ ] Remove changes to
package-lock.json
from this pull request — such changes are often difficult to review and can be made separately. - [ ] Refactoring, code cleanup, and documentation
- Consider taking the approach outlined in the [CodeMirror 5 compatibility documentation]((https://joplinapp.org/help/api/tutorials/cm6_plugin#codemirror-5-compatibility), where the CodeMirror 5 and CodeMirror 6 content scripts are bundled separately by Webpack. At present, CodeMirror 6
- [ ] More manual testing.