The text editor independent part of atom-markdown-table-editor.
You can try it on your browser!
npm i -S @susisu/mte-kernel
Implement an interface to the text editor.
interface ITextEditor {
getCursorPosition(): Point;
setCursorPosition(pos: Point): void;
setSelectionRange(range: Range): void;
getLastRow(): number;
acceptsTableEdit(row: number): boolean;
getLine(row: number): string;
insertLine(row: number, line: string): void;
deleteLine(row: number): void;
replaceLines(startRow: number, endRow: number, lines: Array<string>): void;
transact(func: Function): void;
}
And then you can execute commands through a TableEditor
object.
import { TableEditor, options } from "@susisu/mte-kernel";
const textEditor = ...; // interface to the text editor
const tableEditor = new TableEditor(textEditor);
tableEditor.formatAll(options({}));
See the API reference for more information. It is also good to look into atom-markdown-table-editor as a reference implementation.