Class: MarkdownServer

MarkdownServer

new MarkdownServer(rootDirectory)

Create an instance of a Markdown files server. Can be instantiated from the module, and is mainly used in custom middleware scenarios.

Parameters:
Name Type Description
rootDirectory string

Full path to root directory containing Markdown files to serve

Properties:
Name Type Argument Description
rootDirectory string

Gets or sets the full path to root directory containing Markdown files to server. Set to same as rootDirectory parameter when class is instantiated.

markedOptions Object <nullable>

Gets or sets optional global marked module options used for Markdown processing

resolverOptions resolverOptions <nullable>

resolverOptions. Gets or sets optional global options used by the resolver to configure default page name and file extension of Markdown files.

Source:
Example
var path = require('path'),
    mds = require('markdown-serve');

// Instantiate a new instance of MarkdownServer
var server = new mds.MarkdownServer( path.resolve(__dirname, 'content') );

Methods

get(uriPath, callback) → {MarkdownFile}

Resolves & returns MarkdownFile for specified URI path.

Parameters:
Name Type Description
uriPath string

Path (relative to root) with leading / (slash) to Markdown file we want to obtain eg. "/subfolder/file". Note: Do not include ".md" extension.

callback getCallback

getCallback

Source:
Returns:
Type
MarkdownFile
Example
var server = new mds.MarkdownServer( path.resolve(__dirname, 'content') );

server.get('/intro', function(err, result) {
   if (err) return err;

   // result == MarkdownFile instance
   console.log(result.parseContent());   // the parsed HTML result
});

save(uriPath, rawContent, meta, callback) → {MarkdownFile}

Saves MarkdownFile for given uriPath

Parameters:
Name Type Argument Description
uriPath string

Path (relative to root) with leading / (slash) to Markdown file we want to save eg. "/subfolder/file". Will overwrite existing file or create new file if it doesn't exist. Note: Do not include ".md" extension.

rawContent string

Markdown text content to save

meta Object <optional>
<nullable>

Optional Javascript object to serialize as YAML front-matter and saved in file header

callback saveCallback

saveCallback

Source:
Returns:
Type
MarkdownFile
Example
var mdContent = '# Heading\n\n' +
                'Bullets:\n\n' +
                '- one\n' +
                '- two\n' +
                '- three\nn';

// will create any subfolders in hierarchy if it doesn't exist
server.save('/subfolder/new', mdContent, { title: 'New file', draft: true }, function(err, result) {
   if (err) return err;

   // result == MarkdownFile instance
   console.log(result.parseContent());
});

Type Definitions

getCallback(err, result)

Parameters:
Name Type Argument Description
err Object <nullable>

Errors if any

result MarkdownFile
Source:

resolverOptions

Options to pass to the resolver indicating default document name and Markdown file extension

Type:
  • Object
Properties:
Name Type Argument Default Description
defaultPagename string <optional>
index

Name of default document

fileExtension string <optional>
md

File extension of Markdown files

Source:

saveCallback(err, result)

Parameters:
Name Type Argument Description
err Object <nullable>

Errors if any, otherwise null

result MarkdownFile

Saved file returned as a MarkdownFile object

Source: