Table of Contents

Markdown

This module documents the builtin Markdown parser.

Use require( hop.markdown ) to use it.

Hop.js extends the genuine markdown syntax by supporting embedded Hop.js expressions. As JavaScript template strings, expression starting with the prefix ${ are evaluated and the result of this evaluation is added as is in the parsed HTML tree.

Functions

markdown.load( file )

Parse a markdown file. On success, returns an object with the following properties:

The evaluation environment of the embedded expressions contains the following global variables:

markdown.eval( string )

Parse a markdown string. On success the result is an object with the following properties:

HTML

<markdown.MARKDOWN src=file charset fontifier>

A wrapper to the markdown.eval function that let's markdown documents be directly inserted into HTML containers.

Example:

This example shows how to embed markdown elements into HTML.

The example uses a service that returns an HTML document whose sole element is a markdown text. Before being delivered to the client, the markdown text is parsed and automatically compiled into HTML.

mdtag/mdtag.js

var md = require( hop.markdown );

service mdtag( o ) {
   var name = o && "name" in o ? o.name : "bar";
   return <html>
     <md.markdown>
toto n'est pas content

  * toto
  * tutu ${name}
  * titi
  
tutu non plus.
   </md.markdown>
</html>;
}

console.log( "Go to \"http://%s:%d/hop/mtag\"", hop.hostname, hop.port );