-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathmd_editor.js
34 lines (26 loc) · 1.15 KB
/
md_editor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function editCurrentMarkdownDocument () {
var objApp = WizExplorerApp;
var objWindow = objApp.Window;
var objDocument = objWindow.CurrentDocument;
if (objDocument == null) {
return;
}
var objCommon = objApp.CreateWizObject("WizKMControls.WizCommonUI");
var tempPath = objCommon.GetSpecialFolder("TemporaryFolder");
tempPath += "editor_md_temp/";
objCommon.CreateDirectory(tempPath);
tempPath += objDocument.GUID + "/";
objCommon.CreateDirectory(tempPath);
objCommon.CreateDirectory(tempPath + "index_files/");
var tempFile = tempPath + "index.html";
objDocument.SaveToHtml(tempFile, 0);
var pluginPath = objApp.GetPluginPathByScriptFileName("md_editor.js");
objCommon.CopyFile(pluginPath + "index.html", tempFile);
var tempText = objCommon.LoadTextFromFile(tempFile);
tempText = tempText.replace(/(<script src=")/g, "$1" + pluginPath)
.replace(/(<link rel="stylesheet" href=")/g, "$1" + pluginPath);
objCommon.SaveTextToFile(tempFile, tempText, "utf-8-bom");
var editorFileName = tempFile + "?guid=" + objDocument.GUID + "&kbguid=" + objDocument.Database.KbGUID;
objWindow.ViewHtml(editorFileName, true);
}
editCurrentMarkdownDocument();