diff --git a/README.md b/README.md index 6119d1d..a84d0fc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Markdown Preview for Alfresco Share -This module adds a markdown preview to Alfresco Share: +This module adds a markdown preview and edit button to Alfresco Share: ![](markdown-preview.png) @@ -13,12 +13,19 @@ You will need: * Parashift's alfresco amp plugin from here: https://bitbucket.org/parashift/alfresco-amp-plugin * Run `gradle amp` from the `share` and `repo` directories -### Installing to Alfresco +## Installing to Alfresco * Deploy the amp to both the repo and share end using alfresco-mmt or other methods -### Usage +## Usage -The usage is automatic. +### Previewing a Markdown document -Any documents with the mime type `text/x-markdown` will display within the document details view. +* Navigate to the document details page of a markdown document + + +### Editing a Markdown document + +* Find a markdown document within the document library +* Select `Edit Markdown` +* When you are finished, select `Save Markdown` diff --git a/repo/build.gradle b/repo/build.gradle index 581307a..6c0ca66 100644 --- a/repo/build.gradle +++ b/repo/build.gradle @@ -20,7 +20,7 @@ allprojects { } } -version = "1.0.0" +version = "1.1.0" ext { alfresco = [:] diff --git a/share/build.gradle b/share/build.gradle index 79f98e4..e821508 100644 --- a/share/build.gradle +++ b/share/build.gradle @@ -30,7 +30,7 @@ configurations { all*.exclude group: 'maven-plugins' } -version = "1.0.0" +version = "1.1.0" ext { alfresco = [:] diff --git a/share/src/main/resources/META-INF/components/documentlibrary/actions/document-markdown-edit-16.png b/share/src/main/resources/META-INF/components/documentlibrary/actions/document-markdown-edit-16.png new file mode 100644 index 0000000..6cca482 Binary files /dev/null and b/share/src/main/resources/META-INF/components/documentlibrary/actions/document-markdown-edit-16.png differ diff --git a/share/src/main/resources/META-INF/components/images/filetypes/markdown-file-16.png b/share/src/main/resources/META-INF/components/images/filetypes/markdown-file-16.png new file mode 100644 index 0000000..099cb83 Binary files /dev/null and b/share/src/main/resources/META-INF/components/images/filetypes/markdown-file-16.png differ diff --git a/share/src/main/resources/META-INF/components/markdown-edit.css b/share/src/main/resources/META-INF/components/markdown-edit.css new file mode 100644 index 0000000..9fafd10 --- /dev/null +++ b/share/src/main/resources/META-INF/components/markdown-edit.css @@ -0,0 +1,35 @@ +.markdown-section { + overflow: hidden; + border: 1px solid #ccc !important; + background-color: #fff; + margin: 10px 0; + box-shadow: 0.33px 2px 8px rgba(0, 0, 0, 0.1); +} + +.markdown-section .markdown-body { + -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ + -moz-box-sizing: border-box; /* Firefox, other Gecko */ + box-sizing: border-box; /* Opera/IE 8+ */ + border: 0px; + overflow-x: auto; + +} + +.markdown-editor, .markdown-preview { + -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ + -moz-box-sizing: border-box; /* Firefox, other Gecko */ + box-sizing: border-box; /* Opera/IE 8+ */ + float: left; + width: 50%; + padding: 5px; +} + + +.markdown-text { + width: 100% !important; +} + + +.markdown-section h1 { + border-bottom: 3px solid #ccc; +} diff --git a/share/src/main/resources/META-INF/components/markdown-edit.js b/share/src/main/resources/META-INF/components/markdown-edit.js new file mode 100644 index 0000000..9971310 --- /dev/null +++ b/share/src/main/resources/META-INF/components/markdown-edit.js @@ -0,0 +1,96 @@ +require(["dojo/dom", "dojo/query", "dojo/on", "dojo/request", "showdown", "dojo/domReady!"], function(dom, query, on, request, showdown){ + + 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(/ - + + + + + + + markdown-edit?nodeRef={node.nodeRef} + + Write + + evaluator.doclib.action.markdownMimetype + evaluator.doclib.action.editableByCurrentUser + evaluator.doclib.action.isLocked + + + + + + + + + + + + diff --git a/share/src/main/resources/alfresco/messages/mdpreview.properties b/share/src/main/resources/alfresco/messages/mdpreview.properties new file mode 100644 index 0000000..d04b807 --- /dev/null +++ b/share/src/main/resources/alfresco/messages/mdpreview.properties @@ -0,0 +1,2 @@ +create-content.md=Markdown... +actions.document.markdown-edit=Edit Markdown diff --git a/share/src/main/resources/alfresco/site-data/pages/markdown-edit.xml b/share/src/main/resources/alfresco/site-data/pages/markdown-edit.xml new file mode 100644 index 0000000..e09531f --- /dev/null +++ b/share/src/main/resources/alfresco/site-data/pages/markdown-edit.xml @@ -0,0 +1,9 @@ + + + Edit Markdown + page.markdown-edit.title + Edit Markdown + page.markdown-edit.description + markdown-edit + user + diff --git a/share/src/main/resources/alfresco/site-data/template-instances/markdown-edit.xml b/share/src/main/resources/alfresco/site-data/template-instances/markdown-edit.xml new file mode 100644 index 0000000..cc08c86 --- /dev/null +++ b/share/src/main/resources/alfresco/site-data/template-instances/markdown-edit.xml @@ -0,0 +1,13 @@ + + + com/parashift/markdown-edit + + + + + markdown-edit + /components/markdown-edit + + + + diff --git a/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.desc.xml b/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.desc.xml new file mode 100644 index 0000000..7ff2b93 --- /dev/null +++ b/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.desc.xml @@ -0,0 +1,5 @@ + + Markdown Edit + Allows a user to edit Markdown + /components/markdown-edit + diff --git a/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.head.ftl b/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.head.ftl new file mode 100644 index 0000000..56c7097 --- /dev/null +++ b/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.head.ftl @@ -0,0 +1,3 @@ +<#-- PLEASE NOTE: +<#-- Use of .head.ftl WebScript files has now been deprecated from WebScripts that render Share Components. --> +<#-- Dependencies are now loaded through the use of the <@script> and <@link> tags in the main .html.ftl file. --> diff --git a/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.html.ftl b/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.html.ftl new file mode 100644 index 0000000..16fca57 --- /dev/null +++ b/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.html.ftl @@ -0,0 +1,39 @@ +<@markup id="css" > + <#-- CSS Dependencies --> + <@link href="${url.context}/res/components/preview/MarkDown.css" group="markdown"/> + <@link href="${url.context}/res/components/markdown-edit.css" group="markdown"/> + + +<@markup id="js"> + <#-- JavaScript Dependencies --> + <@script src="${url.context}/res/components/markdown-edit.js" group="markdown"/> + + + +<@markup id="html"> + <@uniqueIdDiv> + +
+
+

Editor:

+ +
+
+

Preview:

+
+
+
+
+ +
+
+ + + + + +
+
+ + + diff --git a/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.js b/share/src/main/resources/alfresco/site-webscripts/com/parashift/markdown/edit/markdown-edit.get.js new file mode 100644 index 0000000..e69de29 diff --git a/share/src/main/resources/alfresco/templates/com/parashift/markdown-edit.ftl b/share/src/main/resources/alfresco/templates/com/parashift/markdown-edit.ftl new file mode 100644 index 0000000..4d28683 --- /dev/null +++ b/share/src/main/resources/alfresco/templates/com/parashift/markdown-edit.ftl @@ -0,0 +1,24 @@ +<#include "../../org/alfresco/include/alfresco-template.ftl" /> +<@templateHeader> + + +<@templateBody> + <@markup id="alf-hd"> +
+ <@region scope="global" id="share-header" chromeless="true"/> +
+ + <@markup id="bd"> +
+ <@region id="markdown-edit" scope="template" /> +
+ + + +<@templateFooter> + <@markup id="alf-ft"> +
+ <@region id="footer" scope="global" /> +
+ + diff --git a/share/src/main/resources/alfresco/web-extension/mdpreview-context.xml b/share/src/main/resources/alfresco/web-extension/mdpreview-context.xml index 2cdcd50..0c0c209 100644 --- a/share/src/main/resources/alfresco/web-extension/mdpreview-context.xml +++ b/share/src/main/resources/alfresco/web-extension/mdpreview-context.xml @@ -20,4 +20,20 @@ + + + + alfresco.messages.mdpreview + + + + + + + + text/x-markdown + + + +