This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository scmwebeditor. See http://git.nuiton.org/scmwebeditor.git commit ea937baddcc1da76bfc3133e9e667b2cc515af0e Author: Hugo PIGEON <hpigeon@codelutin.com> Date: Fri Jun 12 11:33:35 2015 +0200 Add the support of Markdown files for the preview --- pom.xml | 6 +++ swe-ui-web/pom.xml | 5 +++ .../scmwebeditor/uiweb/actions/BrowseAction.java | 4 +- .../scmwebeditor/uiweb/actions/PreviewAction.java | 50 ++++++++++++++-------- .../i18n/scmwebeditor-ui-web_en_GB.properties | 3 ++ .../i18n/scmwebeditor-ui-web_fr_FR.properties | 3 ++ .../webapp/WEB-INF/content/modificationViewer.jsp | 46 ++++++++++++++++++-- swe-ui-web/src/main/webapp/css/main.css | 8 ++-- 8 files changed, 98 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index f3be8ee..75b41df 100644 --- a/pom.xml +++ b/pom.xml @@ -254,6 +254,12 @@ </dependency> <dependency> + <groupId>com.github.rjeschke</groupId> + <artifactId>txtmark</artifactId> + <version>0.13</version> + </dependency> + + <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> diff --git a/swe-ui-web/pom.xml b/swe-ui-web/pom.xml index 8f12d37..f08a1f2 100644 --- a/swe-ui-web/pom.xml +++ b/swe-ui-web/pom.xml @@ -101,6 +101,11 @@ </dependency> <dependency> + <groupId>com.github.rjeschke</groupId> + <artifactId>txtmark</artifactId> + </dependency> + + <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </dependency> diff --git a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/BrowseAction.java b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/BrowseAction.java index 9853afe..9152076 100644 --- a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/BrowseAction.java +++ b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/BrowseAction.java @@ -211,8 +211,8 @@ public class BrowseAction extends AbstractScmWebEditorAction implements ServletR node.setIcon("ui-icon-java"); } else if (fileName.endsWith(".css")) { node.setIcon("ui-icon-css"); - } else if (fileName.endsWith(".rst")) { - node.setIcon("ui-icon-rst"); + } else if (fileName.endsWith(".rst") || fileName.endsWith(".md")) { + node.setIcon("ui-icon-preview"); } else if (fileName.endsWith(".tex")) { node.setIcon("ui-icon-tex"); } else if (fileName.endsWith(".txt")) { diff --git a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/PreviewAction.java b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/PreviewAction.java index 4568f17..7007ca6 100644 --- a/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/PreviewAction.java +++ b/swe-ui-web/src/main/java/org/nuiton/scmwebeditor/uiweb/actions/PreviewAction.java @@ -21,6 +21,7 @@ */ package org.nuiton.scmwebeditor.uiweb.actions; +import com.github.rjeschke.txtmark.Processor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.interceptor.ServletRequestAware; @@ -32,7 +33,7 @@ import javax.servlet.http.HttpServletRequest; import java.io.StringReader; /** - * Gives a preview of the edited RST file + * Gives a preview of the edited RST or Markdown file */ public class PreviewAction extends AbstractScmWebEditorAction implements ServletRequestAware { @@ -47,9 +48,12 @@ public class PreviewAction extends AbstractScmWebEditorAction implements Servlet /** the HTML code to display for the preview */ protected String htmlPreview; - /** the RST text to preview */ + /** the text to preview */ protected String newText; + /** the file's format */ + protected String format; + public String getNewText() { return newText; } public void setNewText(String newText) { this.newText = newText; } @@ -58,6 +62,10 @@ public class PreviewAction extends AbstractScmWebEditorAction implements Servlet public void setHtmlPreview(String htmlPreview) { this.htmlPreview = htmlPreview; } + public String getFormat() { return format; } + + public void setFormat(String format) { this.format = format; } + /** * Execution of the preview action @@ -69,26 +77,34 @@ public class PreviewAction extends AbstractScmWebEditorAction implements Servlet log.debug("Enter in preview action"); } - if (log.isDebugEnabled()) { - log.debug(newText); - } htmlPreview = ""; - //Using jrst to generate html document - try { - JRSTReader jrst = new JRSTReader(); - Document doc = jrst.read(new StringReader(newText)); - Document generatedDoc = JRST.generateXml(doc, JRST.TYPE_HTML); - htmlPreview = generatedDoc.asXML(); - if (log.isDebugEnabled()) { - log.debug("RST generate"); + if (format.equals("rst")) { + + // Using jrst to generate html document + try { + JRSTReader jrst = new JRSTReader(); + Document doc = jrst.read(new StringReader(newText)); + Document generatedDoc = JRST.generateXml(doc, JRST.TYPE_HTML); + htmlPreview = generatedDoc.asXML(); + + if (log.isDebugEnabled()) { + log.debug("RST generate"); + } + + } catch (Exception eee) { + if (log.isWarnEnabled()) { + log.warn("RST generate fail", eee); + } + htmlPreview = "<h4>Parsing error, please read RST specification<h4>"; } + } else if (format.equals("md")) { - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn("RST generate fail", eee); + if (log.isDebugEnabled()) { + log.debug("Markdown generate"); } - htmlPreview = "<h4>Parsing error, please read RST specification<h4>"; + + htmlPreview = Processor.process(newText); } return SUCCESS; diff --git a/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_en_GB.properties b/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_en_GB.properties index a543e4d..6b19237 100644 --- a/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_en_GB.properties +++ b/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_en_GB.properties @@ -43,7 +43,10 @@ scm.forceSave=Force save scm.formTransferred=You should be transferred automatically to the form page. If not please scm.help=Help scm.homepage=the homepage +scm.info.ProblemWithMd=For any problem with Markdown visit scm.info.ProblemWithRst=For any problem with RestructuredText visit +scm.info.mdFile=Information about Markdown files +scm.info.mdWebsite=Markdown documentation website scm.info.rstFile=Information about RST files scm.info.rstWebsite=RST documentation website scm.jumpToLine=Jump to line \# diff --git a/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_fr_FR.properties b/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_fr_FR.properties index 4dee912..5ab6372 100644 --- a/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_fr_FR.properties +++ b/swe-ui-web/src/main/resources/i18n/scmwebeditor-ui-web_fr_FR.properties @@ -43,7 +43,10 @@ scm.forceSave=Forcer la sauvegarde scm.formTransferred=Vous devriez être redirigé vers la page du formulaire. si non scm.help=Aide scm.homepage=la page d'accueil +scm.info.ProblemWithMd=Si vous rencontrez des problèmes avec Markdown, visitez le scm.info.ProblemWithRst=Si vous rencontrez des problèmes avec RestructuredText, visitez le +scm.info.mdFile=Information sur les fichiers Markdown +scm.info.mdWebsite=site de la documentation Markdown scm.info.rstFile=Information sur les fichiers RST scm.info.rstWebsite=site de la documentation RST scm.jumpToLine=Aller à la ligne n° diff --git a/swe-ui-web/src/main/webapp/WEB-INF/content/modificationViewer.jsp b/swe-ui-web/src/main/webapp/WEB-INF/content/modificationViewer.jsp index 85edd79..962de85 100644 --- a/swe-ui-web/src/main/webapp/WEB-INF/content/modificationViewer.jsp +++ b/swe-ui-web/src/main/webapp/WEB-INF/content/modificationViewer.jsp @@ -124,7 +124,7 @@ </script> </s:if> - <s:if test="format == 'rst'"> + <s:if test="format == 'rst' || format == 'md'"> <script type="text/javascript" src="js/preview.js"></script> </s:if> @@ -396,7 +396,7 @@ </li> - <s:if test="format == 'rst'"> + <s:if test="format == 'rst' || format == 'md'"> <li> @@ -577,7 +577,7 @@ <li> <s:a - id="infoRstButton" + cssClass="infoButton" href="#" title="%{scm.info.rstFile}" onClick="javascript:openPopin('rstInfoPopin');" @@ -591,7 +591,34 @@ </ul> </div> + </s:if> + <s:elseif test="format == 'md'"> + + <div class="menuDescription"> + + <p><s:text name="scm.help"/></p> + + <ul class="buttonsGroup"> + <li> + + <s:a + cssClass="infoButton" + href="#" + title="%{scm.info.mdFile}" + onClick="javascript:openPopin('mdInfoPopin');" + name="infoMdButton"> + <span class="fa-stack fa-lg"> + MD ? + </span> + </s:a> + + </li> + </ul> + + </div> + + </s:elseif> </li> </ul> @@ -616,7 +643,7 @@ </script> - <s:if test="format == 'rst'"> + <s:if test="format == 'rst' || format == 'md'"> <script type="text/javascript"> var htmlcontentPreview = document.createElement("div"); @@ -824,6 +851,17 @@ name="scm.info.rstWebsite"/></a>.</h4> </div> </s:if> +<s:elseif test="format=='md'"> + <div id="mdInfoPopin" class="popin"> + <span class="closePopin" onclick="closePopin('mdInfoPopin')"> + X + </span> + + <h4><s:text name="scm.info.ProblemWithMd"/> <a + href="http://daringfireball.net/projects/markdown/syntax"><s:text + name="scm.info.mdWebsite"/></a>.</h4> + </div> +</s:elseif> <div id="popinBackground"></div> diff --git a/swe-ui-web/src/main/webapp/css/main.css b/swe-ui-web/src/main/webapp/css/main.css index ad48558..77b2d49 100644 --- a/swe-ui-web/src/main/webapp/css/main.css +++ b/swe-ui-web/src/main/webapp/css/main.css @@ -83,7 +83,7 @@ ul.flags li { background-position: 0 1px !important ; } -.ui-icon-rst { +.ui-icon-preview { background-image:url("../img/icons/rst.png") !important; background-position: 0 1px !important ; } @@ -314,7 +314,7 @@ ul.flags li { width: 90%; } -#rstInfoPopin { +#rstInfoPopin, #mdInfoPopin { height: 50%; top: 25%; left: 25%; @@ -543,13 +543,13 @@ ul.buttonsGroup li { bottom: 10px; } -#infoRstButton { +#sweMenu .infoButton { font-weight: bold; text-align: center; text-decoration: none; } -#infoRstButton span.fa-stack { +#sweMenu .infoButton span.fa-stack { width: 30px; } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.