github-style-page
v0.1.2
Published
Converting markdown content into HTML file with Github styles (GFW)
Downloads
14
Maintainers
Readme
github-style-page
Converting markdown content into HTML file with Github styles (GFW).
Installation
npm install github-style-page
Quick Start
var githubStylePage = require('github-style-page');
githubStylePage('path/to/example.md', 'path/to/', function() {
console.log('path/to/example.html generated!');
});
githubStylePage('## Options', 'path/to/', {
isContent: true
}, function() {
console.log('path/to/index.html generated!');
});
API
var githubStylePage = require('github-style-page');
githubStylePage(path, targetDir [, options], callback)
- path: the path where the markdown file.
- targetDir: the directory path where the converted file will be saved.
- options: deal with some optional parameters, see options for detail.
- callback: a function to be executed when converting is complete.
Note: if
targetDir
set to null, the converted content will not be saved as a file, but will be passed to the callback.
Below is an example:
githubStylePage('path/to/example.md', 'path/to/', function() {
console.log('path/to/example.html generated!');
});
githubStylePage('path/to/example.md', null, function(html) {
console.log('converted html content:', html);
});
githubStylePage(markdownString, targetDir [, options], callback)
Provide a markdown string exactly.
Note: set
isContent
to true to tellgithub-style-page
current is a markdown string.
Below is an example:
githubStylePage('## Options', 'path/to/', {
isContent: true
}, function() {
console.log('path/to/index.html generated!');
});
Options
vars
Template variables. Make sure that all variables used in the template where the customizeTemplatePath
have been passed by the vars
.
isContent
Indicate that currently is a markdown string.
githubStylePage('## Options', 'path/to/', {
isContent: true
}, function() {
console.log('path/to/index.html generated!');
});
template
A string to indicate the template will be used to render the markdown content.
Currently built-in templates:
- simple the default template theme.
- project NPM project style.
simple
Screen shot:
project
Below is an project
example, note that pkg
should be provided and at least contains name
and version
:
githubStylePage('path/to/example.md', 'path/to/', {
template: 'project',
vars: {
pkg: {
name: 'github-style-page',
version: '0.1.1'
},
examples: ['simple', 'complex']
}
}, function() {
console.log('path/to/example.html generated!');
});
Screen shot:
If the above templates does not meet your needs, you can customize one and add it in this list. Then create a Pull Request without hesitate.
customizeTemplatePath
Provide a customize template path to render the parsed markdown content.
Note: if provided, the
template
option will take no effect.
githubStylePage('path/to/example.md', 'path/to/', {
customizeTemplatePath: 'path/to/customTemplate.html',
vars: {
a: 'xxx',
b: 'xxx'
}
}, function() {
console.log('path/to/example.html generated!');
});
markedOptions
Configuration for markdown parser, see marked#options for detail.
Default value:
{
gfm: true,
tables: true,
breaks: false
}
Below is an example:
githubStylePage('## Options', 'path/to/', {
markedOptions: {
tables: true,
breaks: false
}
}, function() {
console.log('path/to/index.html generated!');
});
fileName
Specify the name of the converted file will be saved.
githubStylePage('path/to/example.md', 'path/to/', {
fileName: 'readme'
}, function() {
console.log('path/to/readme.html generated!');
});
Testing
npm test
License
MIT, see the LICENSE file for detail.