Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.
Otstar Lin edited this page May 11, 2019 · 2 revisions

XK Editor开放的一些函数方法,若您未找到想要的函数方法,可以提交issues请求添加或者自行添加。

window.XKEditor

获取Markdown格式的内容

window.XKEditor.getMarkdown();

获取HTML格式的内容

window.XKEditor.getHTML();

设置Markdown内容

//window.XKEditor.setMarkdown(val, valueType = 'markdown')
window.XKEditor.setMarkdown("Hello world!", "markdown");
window.XKEditor.setMarkdown("Hello world!", "html");

设置HTML内容

//window.XKEditor.setHTML(val, valueType = 'html')
window.XKEditor.setHTML("Hello world!", "markdown");
window.XKEditor.setHTML("Hello world!", "html");

切换编辑器

window.XKEditor.switchEditor();

切换实时预览

window.XKEditor.switchPreview();

切换全窗口预览

window.XKEditor.switchFullPreview();

切换全屏预览

window.XKEditor.switchFullScreen();

跳转到指定行

window.XKEditor.toLine();

显示/隐藏TOC侧边栏

window.XKEditor.toc();

显示/隐藏工具栏

window.XKEditor.toolbar();

重置编辑器窗口大小

window.XKEditor.resize();

添加快捷键

var keys = [
    {
        name: "copy",
        win: "Ctrl-C",
        mac: "Command-C",
        exec: fucntion() {
            //do something
        }
    },
    {
        name: "paste",
        win: "Ctrl-V",
        mac: "Command-V",
        exec: function() {
            //do something
        }
    }
];
window.XKEditor.addKeys(keys);

删除快捷键

var keys = [
    "copy",
    "paste"
];
window.XKEditor.removeKeys(keys);

获取指定的编辑器对象

//window.XKEditor.getEditor(name);
window.XKEditor.getEditor("ace");
window.XKEditor.getEditor("tinymce");

开启/关闭打字机模式

window.XKEditor.switchTypewriter();

将内容存储至本地存储

//window.XKEditor.setLocalStorage(filename);
window.XKEditor.setLocalStorage("text1");

从本地读取内容

//window.XKEditor.getLocalStorage(filename);
window.XKEditor.getLocalStorage("text2");

列出本地存储中所有的内容

window.XKEditor.listLocalStorage();

删除本地存储中的内容

//window.XKEditor.removeLocalStorage(filename);
window.XKEditor.removeLocalStorage("text1");

下载

//window.XKEditor.download(filename, type = 'markdown');
window.XKEditor.download("download1", type = 'markdown');
window.XKEditor.download("download1", type = 'html');
window.XKEditor.download("download1", type = 'fullhtml');

window.XKEditorAPI

上传图片

//window.XKEditorAPI.imgUpload(file, success, failure);
let file = document.getElementById('img-upload').files[0];
var success = function(response) {
    //do something
}
var failure = function(error) {
    //do something
}
window.XKEditorAPI.imgUpload(file, success, failure);

API还在扩充中,敬请期待。