MarkdownServer

MarkdownServer

new MarkdownServer(rootDirectory)

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

Source:
Properties:
Name Type Attributes 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.

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

// Instantiate a new instance of MarkdownServer
var server = new mds.MarkdownServer( path.resolve(__dirname, 'content') );
Parameters:
Name Type Description
rootDirectory string

Full path to root directory containing Markdown files to serve

Methods

get(uriPath, callback) → {MarkdownFile}

Description:
Source:
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
});
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

Returns:
Type
MarkdownFile

save(uriPath, rawContent, metaopt, nullable, callback) → {MarkdownFile}

Description:
  • Saves MarkdownFile for given uriPath

Source:
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());
});
Parameters:
Name Type Attributes 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

Returns:
Type
MarkdownFile

Type Definitions

getCallback(errnullable, result)

Description:
Source:
Parameters:
Name Type Attributes Description
err Object <nullable>

Errors if any

result MarkdownFile

resolverOptions

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

Source:
Properties:
Name Type Attributes Default Description
defaultPagename string <optional>
index

Name of default document

fileExtension string <optional>
md

File extension of Markdown files

useExtensionInUrl boolean <optional>
false

If true, the file extension will not be removed from the url when resolving it

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

Type:
  • Object

saveCallback(errnullable, result)

Description:
Source:
Parameters:
Name Type Attributes Description
err Object <nullable>

Errors if any, otherwise null

result MarkdownFile

Saved file returned as a MarkdownFile object