Table of Contents
Markdown
This module documents the builtin Markdown language and parser.
Use
require( hop.markdown )
to use it as a library.require( file, hop.markdown )
to use it as a language compiler for loading interning markdown documents.
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.loadDocument( file )
Parse a markdown file and return an return it as an HTML document.
Example:
md.js
const md = require( hop.markdown );
service foo() {
return <HTML>
${ md.loadDocument( require.resolve( "./md.md" ) ) }
</HTML>
}
md.js
title
=====
* A
* B
Parse a markdown file. On success, returns the corresponding XML object.
markdown.load( file )
Parse a markdown file. On success, returns an object with the following properties:
filename
: the markdown source file.charset
: the encoding charset of the source.XML
: the parsed HTML tree.
The evaluation environment of the embedded expressions contains the following global variables:
filename
: the source file.
markdown.eval( string )
Parse a markdown string. On success the result is an object with the following properties:
obj
: the markdown source string.charset
: the encoding charset of the source.XML
: the parsed HTML tree.
HTML
<markdown.MARKDOWN src 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 );