Skip to content
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

CodeMirror 6 / beta editor support #93

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ node_modules/
publish/

dist/*
*.jpl

src/katex/
*.jpl
86 changes: 80 additions & 6 deletions api/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable multiline-comment-style */

// =================================================================
// Command API types
// =================================================================
Expand Down Expand Up @@ -221,6 +223,12 @@ export enum ModelType {
Command = 16,
}

export interface VersionInfo {
version: string;
profileVersion: number;
syncVersion: number;
}

// =================================================================
// Menu types
// =================================================================
Expand Down Expand Up @@ -351,6 +359,18 @@ export interface DialogResult {
formData?: any;
}

export interface Size {
width?: number;
height?: number;
}

export interface Rectangle {
x?: number;
y?: number;
width?: number;
height?: number;
}

// =================================================================
// Settings types
// =================================================================
Expand Down Expand Up @@ -499,6 +519,57 @@ export interface ContentScriptContext {
postMessage: PostMessageHandler;
}

export interface ContentScriptModuleLoadedEvent {
userData?: any;
}

export interface ContentScriptModule {
onLoaded?: (event: ContentScriptModuleLoadedEvent)=> void;
plugin: ()=> any;
assets?: ()=> void;
}

export interface MarkdownItContentScriptModule extends Omit<ContentScriptModule, 'plugin'> {
plugin: (markdownIt: any, options: any)=> any;
}

type EditorCommandCallback = (...args: any[])=> any;

export interface CodeMirrorControl {
/** Points to a CodeMirror 6 EditorView instance. */
editor: any;
cm6: any;

/** `extension` should be a [CodeMirror 6 extension](https://codemirror.net/docs/ref/#state.Extension). */
addExtension(extension: any|any[]): void;

supportsCommand(name: string): boolean;
execCommand(name: string, ...args: any[]): any;
registerCommand(name: string, callback: EditorCommandCallback): void;

joplinExtensions: {
/**
* Returns a [CodeMirror 6 extension](https://codemirror.net/docs/ref/#state.Extension) that
* registers the given [CompletionSource](https://codemirror.net/docs/ref/#autocomplete.CompletionSource).
*
* Use this extension rather than the built-in CodeMirror [`autocompletion`](https://codemirror.net/docs/ref/#autocomplete.autocompletion)
* if you don't want to use [langaugeData-based autocompletion](https://codemirror.net/docs/ref/#autocomplete.autocompletion^config.override).
*
* Using `autocompletion({ override: [ ... ]})` causes errors when done by multiple plugins.
*/
completionSource(completionSource: any): any;

/**
* Creates an extension that enables or disables [`languageData`-based autocompletion](https://codemirror.net/docs/ref/#autocomplete.autocompletion^config.override).
*/
enableLanguageDataAutocomplete: { of: (enabled: boolean)=> any };
};
}

export interface MarkdownEditorContentScriptModule extends Omit<ContentScriptModule, 'plugin'> {
plugin: (editorControl: CodeMirrorControl)=> void;
}

export enum ContentScriptType {
/**
* Registers a new Markdown-It plugin, which should follow the template
Expand All @@ -508,7 +579,7 @@ export enum ContentScriptType {
* module.exports = {
* default: function(context) {
* return {
* plugin: function(markdownIt, options) {
* plugin: function(markdownIt, pluginOptions) {
* // ...
* },
* assets: {
Expand All @@ -518,6 +589,7 @@ export enum ContentScriptType {
* }
* }
* ```
*
* See [the
* demo](https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script)
* for a simple Markdown-it plugin example.
Expand All @@ -530,17 +602,19 @@ export enum ContentScriptType {
*
* - The **required** `plugin` key is the actual Markdown-It plugin - check
* the [official doc](https://github.com/markdown-it/markdown-it) for more
* information. The `options` parameter is of type
* [RuleOptions](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml.ts),
* which contains a number of options, mostly useful for Joplin's internal
* code.
* information.
*
* - Using the **optional** `assets` key you may specify assets such as JS
* or CSS that should be loaded in the rendered HTML document. Check for
* example the Joplin [Mermaid
* plugin](https://github.com/laurent22/joplin/blob/dev/packages/renderer/MdToHtml/rules/mermaid.ts)
* to see how the data should be structured.
*
* ## Getting the settings from the renderer
*
* You can access your plugin settings from the renderer by calling
* `pluginOptions.settingValue("your-setting-key')`.
*
* ## Posting messages from the content script to your plugin
*
* The application provides the following function to allow executing
Expand Down Expand Up @@ -671,4 +745,4 @@ export enum ContentScriptType {
*
*/
CodeMirrorPlugin = 'codeMirrorPlugin',
}
}
Loading