added github/table extensions, but still not using
This commit is contained in:
parent
9950e45dee
commit
ade1b4f144
@ -0,0 +1,96 @@
|
|||||||
|
require(["dojo/dom", "dojo/query", "dojo/on", "dojo/request", "showdown", "showdown-github", "showdown-table", "dojo/domReady!"], function(dom, query, on, request, showdown, showdownGithub, showdownTable){
|
||||||
|
|
||||||
|
function resizeFrame(elem) {
|
||||||
|
elem.style.height = (window.innerHeight - 280) + "px";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getURLParameter(name) {
|
||||||
|
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null
|
||||||
|
}
|
||||||
|
|
||||||
|
var nodePath = getURLParameter("nodeRef").replace(":/","");
|
||||||
|
|
||||||
|
request.get(Alfresco.constants.PROXY_URI_RELATIVE + "/slingshot/doclib2/node/" + nodePath,{ handleAs: "json"}).then(function(nodeData) {
|
||||||
|
|
||||||
|
|
||||||
|
var locationPath = Alfresco.constants.PROXY_URI_RELATIVE + "markdown" + nodeData.item.location.repoPath + "/";
|
||||||
|
|
||||||
|
//Once we have the content, let's create a converter and add the html to the div element
|
||||||
|
var converter = new showdown.Converter({
|
||||||
|
extensions: [
|
||||||
|
function() {
|
||||||
|
return [{
|
||||||
|
type: 'output',
|
||||||
|
filter: function(source) {
|
||||||
|
return source.replace(/<img src="([^"]*)"/g, function(match, src) {
|
||||||
|
|
||||||
|
if(src.startsWith("http")) {
|
||||||
|
//if this includes external links, then don't change it.
|
||||||
|
return match;
|
||||||
|
} else {
|
||||||
|
//if it's a relative link, we need to use our webscript
|
||||||
|
return "<img src=\"" + locationPath + src + "\"";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
var editorFrame = dom.byId("md-text");
|
||||||
|
var previewFrame = dom.byId("md-body");
|
||||||
|
var saveBack = dom.byId("markdownSaveback");
|
||||||
|
|
||||||
|
resizeFrame(editorFrame);
|
||||||
|
resizeFrame(previewFrame);
|
||||||
|
|
||||||
|
|
||||||
|
on(window, "resize", function() {
|
||||||
|
resizeFrame(editorFrame);
|
||||||
|
resizeFrame(previewFrame);
|
||||||
|
});
|
||||||
|
|
||||||
|
function updateMarkdown() {
|
||||||
|
|
||||||
|
previewFrame.innerHTML = converter.makeHtml(editorFrame.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
on(editorFrame, "change", updateMarkdown);
|
||||||
|
on(editorFrame, "keyup", updateMarkdown);
|
||||||
|
on(editorFrame, "paste", updateMarkdown);
|
||||||
|
|
||||||
|
request.get(Alfresco.constants.PROXY_URI_RELATIVE + "/api/node/content/" + nodePath).then(function(nodeContent) {
|
||||||
|
editorFrame.value = nodeContent;
|
||||||
|
updateMarkdown();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
on(saveBack, "click", function() {
|
||||||
|
|
||||||
|
var postHeaders = {
|
||||||
|
"Content-Type" : "application/json"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Alfresco.util.CSRFPolicy && Alfresco.util.CSRFPolicy.isFilterEnabled()) {
|
||||||
|
postHeaders[Alfresco.util.CSRFPolicy.getHeader()] = Alfresco.util.CSRFPolicy.getToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
request.post(Alfresco.constants.PROXY_URI_RELATIVE + "api/node/" + nodePath + "/formprocessor", {
|
||||||
|
headers: postHeaders,
|
||||||
|
data : JSON.stringify({
|
||||||
|
prop_cm_content : editorFrame.value
|
||||||
|
})
|
||||||
|
}).then(function() {
|
||||||
|
Alfresco.util.PopupManager.displayMessage({"text": "Update Submitted"});
|
||||||
|
}, function (err) {
|
||||||
|
//Tries to find the exception from the error page and send a prompt
|
||||||
|
Alfresco.util.PopupManager.displayPrompt({"title": "Error Updating Alfresco"});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -0,0 +1,74 @@
|
|||||||
|
(function() {
|
||||||
|
|
||||||
|
Alfresco.WebPreview.prototype.Plugins.MarkDown = function(wp, attributes)
|
||||||
|
{
|
||||||
|
this.wp = wp;
|
||||||
|
this.attributes = YAHOO.lang.merge(Alfresco.util.deepCopy(this.attributes), attributes);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
Alfresco.WebPreview.prototype.Plugins.MarkDown.prototype =
|
||||||
|
{
|
||||||
|
attributes: {},
|
||||||
|
|
||||||
|
report: function() {
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
display: function() {
|
||||||
|
|
||||||
|
var node = this.attributes.node;
|
||||||
|
|
||||||
|
//get the default relative path of the node
|
||||||
|
var locationPath = Alfresco.constants.PROXY_URI_RELATIVE + "/markdown" + this.attributes.location.repoPath + "/";
|
||||||
|
|
||||||
|
//get the Div Element we'll be putting the Markdown
|
||||||
|
var divElem = document.getElementById(this.wp.id + "-body")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Execute Ajax request for content
|
||||||
|
require(["dojo/request", "showdown", "showdown-github", "showdown-table"], function(request, showdown, showdownGithub, showdownTable){
|
||||||
|
|
||||||
|
//Once we have the content, let's create a converter and add the html to the div element
|
||||||
|
converter = new showdown.Converter({
|
||||||
|
extensions: [
|
||||||
|
function() {
|
||||||
|
return [{
|
||||||
|
type: 'output',
|
||||||
|
filter: function(source) {
|
||||||
|
return source.replace(/<img src="([^"]*)"/g, function(match, src) {
|
||||||
|
|
||||||
|
if(src.startsWith("http")) {
|
||||||
|
//if this includes external links, then don't change it.
|
||||||
|
return match;
|
||||||
|
} else {
|
||||||
|
//if it's a relative link, we need to use our webscript
|
||||||
|
return "<img src=\"" + locationPath + src + "\"";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
request.get(Alfresco.constants.PROXY_URI_RELATIVE + node.contentURL).then(function(mdData) {
|
||||||
|
|
||||||
|
|
||||||
|
newHtml = converter.makeHtml(mdData);
|
||||||
|
|
||||||
|
divElem.className = "markdown-body";
|
||||||
|
divElem.innerHTML = converter.makeHtml(mdData);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
Loading…
x
Reference in New Issue
Block a user