From 8b7eef80b33e68fccd01f30106f00a63050dcece Mon Sep 17 00:00:00 2001 From: Joseph Vaughan Date: Mon, 14 Dec 2015 13:54:03 +0000 Subject: [PATCH] Add definitions for CodeMirror's runmode addon --- codemirror/codemirror-runmode-tests.ts | 6 ++++++ codemirror/codemirror-runmode.d.ts | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 codemirror/codemirror-runmode-tests.ts create mode 100644 codemirror/codemirror-runmode.d.ts diff --git a/codemirror/codemirror-runmode-tests.ts b/codemirror/codemirror-runmode-tests.ts new file mode 100644 index 0000000000..e139e7177b --- /dev/null +++ b/codemirror/codemirror-runmode-tests.ts @@ -0,0 +1,6 @@ +/// +/// + +var query = "SELECT * FROM Table"; + +CodeMirror.runMode(query, "text/x-sql", document.body); diff --git a/codemirror/codemirror-runmode.d.ts b/codemirror/codemirror-runmode.d.ts new file mode 100644 index 0000000000..89f35602f7 --- /dev/null +++ b/codemirror/codemirror-runmode.d.ts @@ -0,0 +1,22 @@ +// Type definitions for CodeMirror +// Project: https://github.com/marijnh/CodeMirror +// Definitions by: Joseph Vaughan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// See docs https://codemirror.net/doc/manual.html#addon_runmode + +declare module CodeMirror { + + /** + * Can be used to run a CodeMirror mode over text without actually opening an editor instance. + * + * @param text The document to run through the highlighter. + * @param mode The mode to use (must be loaded as normal). + * @param output If this is a function, it will be called for each token with + * two arguments, the token's text and the token's style class + * (may be null for unstyled tokens). If it is a DOM node, the + * tokens will be converted to span elements as in an editor, + * and inserted into the node (through innerHTML). + */ + function runMode(text : string, mode : any, output : any): void; +}