Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

Commit

Permalink
add genOutput method
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Jan 31, 2013
1 parent 023c49a commit 6019032
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
0.1.1 / 2013-01-31
------------------
* add `genOutput()` method

0.1.0 / 2013-01-23 0.1.0 / 2013-01-23
------------------ ------------------
* Fixed null body bug. * Fixed null body bug.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -22,7 +22,7 @@ Installation
Example Example
------ ------


A bit unstable. See tests. Very unstable API. See tests.






Expand Down
38 changes: 21 additions & 17 deletions lib/markdown-page.js
Expand Up @@ -21,6 +21,26 @@
}}); }});
} }


MarkdownPage.prototype.genOutput = function() {
var data = '<!--\n'
, _this = this

Object.keys(this.metadata).forEach(function(key) {
if (_this.metadataConversions[key])
data += key + ': ' + _this.metadataConversions[key].serialize(_this.metadata[key]) + '\n';
else
data += key + ': ' + _this.metadata[key] + '\n'
})

data += '-->\n\n\n'

data += this.title + '\n'
data += S('=').repeat(this.title.length) + '\n\n'

data += this.markdown + '\n'
return data;
}

//this is actually just a sync method, but in the future, may call out to other executables or services //this is actually just a sync method, but in the future, may call out to other executables or services
MarkdownPage.prototype.parse = function(callback) { MarkdownPage.prototype.parse = function(callback) {
this.metadata = mde.metadata(this.text, parseMetadata); this.metadata = mde.metadata(this.text, parseMetadata);
Expand All @@ -40,23 +60,7 @@
} }


MarkdownPage.prototype.writeFile = function(file, callback) { MarkdownPage.prototype.writeFile = function(file, callback) {
var data = '<!--\n' var data = this.genOutput()
, _this = this

Object.keys(this.metadata).forEach(function(key) {
if (_this.metadataConversions[key])
data += key + ': ' + _this.metadataConversions[key].serialize(_this.metadata[key]) + '\n';
else
data += key + ': ' + _this.metadata[key] + '\n'
})

data += '-->\n\n\n'

data += this.title + '\n'
data += S('=').repeat(this.title.length) + '\n\n'

data += this.markdown + '\n'

fs.writeFile(file, data, callback) fs.writeFile(file, data, callback)
} }


Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ {
"name": "markdown-page", "name": "markdown-page",
"version": "0.1.0", "version": "0.1.1",
"description": "Parse a markdown article or page.", "description": "Parse a markdown article or page.",
"homepage": [ "homepage": [
"" ""
Expand Down

0 comments on commit 6019032

Please sign in to comment.