Skip to content
Permalink
Browse files

加入粘贴时转换Markdown功能

  • Loading branch information
akof1314 committed May 18, 2015
1 parent 7a96675 commit 972ab4c524cf39758f431e7c6e67a2e10442b989
Showing with 30 additions and 15 deletions.
  1. +1 −0 index.html
  2. +2 −2 md_editor.js
  3. +27 −13 md_editor_core.js
@@ -15,6 +15,7 @@
</div>
<script src="Editor.md/examples/js/jquery.min.js"></script>
<script src="Editor.md/editormd.js"></script>
<script src="to-markdown/dist/to-markdown.js"></script>
<script src="md_editor_core.js"></script>
</body>
</html>
@@ -21,10 +21,10 @@ function editCurrentMarkdownDocument () {

var pluginPath = objApp.GetPluginPathByScriptFileName("md_editor.js");
objCommon.CopyFile(pluginPath + "index.html", tempFile);
objCommon.CopyFile(pluginPath + "md_editor_core.js", tempPath + "md_editor_core.js");

var tempText = objCommon.LoadTextFromFile(tempFile);
tempText = tempText.replace(/Editor.md\//g, encodeURI(pluginPath) + "Editor.md/");
tempText = tempText.replace(/(<script src=")/g, "$1" + encodeURI(pluginPath))
.replace(/(<link rel="stylesheet" href=")/g, "$1" + encodeURI(pluginPath));
objCommon.SaveTextToFile(tempFile, tempText, "utf-8-bom");

var editorFileName = tempFile + "?guid=" + objDocument.GUID + "&kbguid=" + objDocument.Database.KbGUID;
@@ -139,18 +139,32 @@ $(function() {
// 剪贴板HTML图片地址
clipboardHTMLImage = function (htmlText) {
if (htmlText != "") {
var txt= htmlText.replace(/<html>\s*<body>/,'<div id="myTest">').replace(/<\/body>\s*<\/html>/,'</div>');
var imgText = "";
$(txt).find("img").each(function (){
$('<p></p>').text("![](" + $(this).attr('src') + ")\n").insertAfter($(this));
imgText += "![](" + $(this).attr('src') + ")\n";
});
console.log($(txt).html());

if (imgText != "") {
wizEditor.insertValue(imgText);
return true;sss
}s
var referencelinkRegEx = /reference-link/;
wizEditor.insertValue(toMarkdown(htmlText, {
gfm: true,
converters:[
{
filter: 'div',
replacement: function(content) {
return content + '\n';
}
},
{
filter: 'span',
replacement: function(content) {
return content;
}
},
{
filter: function (node) {
return node.nodeName === 'A' && referencelinkRegEx.test(node.className);
},
replacement: function(content) {
return "";
}
}]})
);
return true;
}
return false;
};
@@ -206,7 +220,7 @@ $(function() {
imgCopyToFullPath = filesWinPath + imgNameNew;
getObjCommon().CopyFile(imgFullPath, imgCopyToFullPath);
}

imgSrc = filesDirName + imgNameNew;
arrImgTags += "<img src=\"" + imgCopyToFullPath + "\">";
}

0 comments on commit 972ab4c

Please sign in to comment.
You can’t perform that action at this time.