Class: MarkdownFile

MarkdownFile

new MarkdownFile(file)

Represents a Markdown file.

This object cannot be instantiated directly, but is returned as a result of MarkdownServer.get() or MarkdownServer.save(). It is also made available as the markdownFile view model object passed to view when used as a simple middleware.

Members with name starting with an underscore (_) are designed to be used internally.

In typical usage, the parsed Markdown content (HTML) is available as an additional step (call to MarkdownFile.parseContent()), rather than as a string property on the object. The reasoning behind this is for performance reasons, sometimes you do not need to get at the HTML content straight away and need to apply some custom logic to specify front-matter variables (MarkdownFile.meta) first, eg. implementing a "draft publishing" feature.

However, in some situations (eg. when using the hbs view engine - the view doesn't support calling methods on the view model object passed to it. In this case, when used as a middleware, you can set the preParse option to true and the parsed HTML content will be available as the MarkdownFile.parseContent() string property.

Parameters:
Name Type Description
file string

Full path to file on the physical file system. File does not have to exist, as MarkdownFile.saveChanges() can be called to create the file

Properties:
Name Type Argument Description
_file string

Gets the full path to file on the physical file system. Designed to be used internally & is set from the file parameter value when instantiated. NOTE: This property is deleted and not available when used in simple middleware scenario as exposing it could potentially be a security risk.

meta Object <nullable>

Gets or sets the Javascript option that is serialized/de-serialized to/from the YAML front-matter in the file header. If set, the property will be serialized to YAML when MarkdownFile.saveChanges() is called.

rawContent string

Gets or sets the raw Markdown text content of file

_markedOptions Object <nullable>

Gets the options that is passed to the marked module used for Markdown processing. This is a reference to MarkdownServer.markedOptions.

stats Object <optional>

Gets the Node fs.Stats object containing properties of file

created Date <optional>

Gets the date file was created

modified Date <optional>

Gets the date file was last modified

size number <optional>

Gets the size in bytes of file

checksum string <optional>

Gets the SHA1 checksum of file contents (can be used as an ETag)

parsedContent string <optional>

Gets the result from MarkdownFile.parseContent(). This property is only made available when used in the simple middleware scenario and when the preParse option is set to true. It is also set when no view option is specified.

Source:

Methods

parseContent(callback) → {string}

Parses MarkdownFile.rawContent & returns HTML

Parameters:
Name Type Description
callback parseContentCallback

parseContentCallback

Source:
Returns:

Converted HTML string

Type
string

saveChanges(callback) → {boolean}

Writes changes back to file on disk, overwriting existing file if it exists

Parameters:
Name Type Description
callback saveChangesCallback

saveChangesCallback

Source:
Returns:

Success indicator

Type
boolean

Type Definitions

parseContentCallback(err, result)

Parameters:
Name Type Argument Description
err Object <nullable>

Errors if any

result string

Converted HTML string

Source:

saveChangesCallback(err, result)

MarkdownFile.saveChanges() method callback

Parameters:
Name Type Argument Description
err Object <nullable>

Errors if any

result boolean

Success indicator

Source: