To install this JPSWiki extension, you will need Admin rights; and have the Haddock Template activated.

Markdown Behavior/markdown-solid.png

Markdown is a lightweight markup language, originally created by John Gruber and Aaron Swartz allowing people "to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML)".

Markdown Behavior is a JSPWiki javascript extension which allows to render pages written in markdown.

It is based on marked, a full-featured markdown parser and compiler written in javascript, by Christopher Jeffrey. ( MIT LICENSE ) It supports the original markdown syntax, GFM table extension and smart-lists.

See Markdown Test Page for an example rendered Markdown page.

How to use %%markdown#

%%markdown
{{{
### Hi, now you can include **markdown** in JSPWiki!
}}}
/%

### Hi, now you can include **markdown** in JSPWiki!

How to install the Markdown extension#

Step 1: Copy the markdown parser#

Copy marked.min.js from GitHub to <your-wiki-site>/scripts/ folder.

Step 2: Create JS behavior file#

Create a javascript behavior file Wiki.Behavior.Markdown.js with the following code snippet and save it in <your-wiki-site>/scripts folder.
This script will automatically load and invoke the markdown parser in your browser when it detects %%markdown.

.wrap-pre pre, .wrap-pre .prettyprint { white-space:pre-wrap; }
!function(a,b,c){function d(b){var c="div".slick();c.innerHTML=marked(b.textContent),c.replaces(b),c.getElements("table").addClass("table-fit table-condensed table-bordered"),c.getElements("pre > code[class|=lang] ").each(function(a){a.getParent().addClass("prettify-nonum")});var d=a.PageName.replace(/\s/g,"+");c.getElements("h1,h2,h3,h4,h5,h6").each(function(a){a.id="section-"+d+"-"+a.innerText.replace(/[^\w]+/g,""),a.grab("a.hashlink".slick({href:"#"+a.id,text:"#"}))}),c.getElements("a[href^=http://],a[href^=https://]").addClass("external"),c.getElements("a[class!=wikipage][class!=hashlink][class!=external]").each(function(b){b.href=a.toUrl(b.href.replace(/^.+\//,"").replace(/%20/g," ")),b.addClass("wikipage")}),c.getElements("img:not([src^=http://]):not([src^=https://])").each(function(b){b.src=a.BaseUrl+"/attach/"+b.src.replace(/^.+\/(.+\/)/,"$1").replace(/%20/g," "),b.addClass("inline")})}a.once(c,function(){"script".slick({src:b,events:{load:function(b){$$(c+" pre").each(d),a.update()}} }).inject(document.head)})}(Wiki,"scripts/marked.min.js",".markdown")

Step 3: Update JSP files#

Add following lines to <your-wiki-site>/templates/haddock/commonheader.jsp.

  <!-- existing line -->
  <script async src="<wiki:Link format='url' jsp='scripts/haddock.js'/>"></script>
  <!-- add this line -->
  <script src="<wiki:Link format='url' jsp='scripts/Wiki.Behavior.Markdown.js'/>" ></script>
And do the same in <your-wiki-site>/templates/reader/ViewTemplate.js.

Voila! You can now use markdown from your wiki-pages !
No need to restart your JSPWiki server.


See Category.Haddock Behavior