• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cwjohan/markdown-to-html: Command-line utility to convert Github Flavored Markdo ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

cwjohan/markdown-to-html

开源软件地址(OpenSource Url):

https://github.com/cwjohan/markdown-to-html

开源编程语言(OpenSource Language):

HTML 54.2%

开源软件介绍(OpenSource Introduction):

markdown-to-html

Command-line utility to convert Github Flavored Markdown to HTML. Output may be to stdout or to your default browser. Also, the underlying Markdown and GithubMarkdown classes are readable stream classes and may be used however you like (e.g., pipe to an http response or to stdout). Includes a demo of a web server app that uses both the classes.

Installation

To use the command line utilities

npm install markdown-to-html -g

To use the Markdown or GithubMarkdown classes in your project

npm install markdown-to-html --save

Example Usage

Command line utility to output HTML to stdout

markdown myfile.md [<options>]

Command line utility to output HTML to default browser

markdownb myfile.md [<options>]

Command line utility to output the Github API results to stdout

github-markdown myfile.md [<options>]

Command line utility to output the Github API results to default browser

github-markdownb myfile.md [<options>]

Run the web demo

git clone https://github.com/cwjohan/markdown-to-html.git
cd markdown-to-html
npm install
npm start

In a web browser address field type localhost:3000.

Use the Markdown class to render markdown text

var Markdown = require('markdown-to-html').Markdown;
var md = new Markdown();
md.bufmax = 2048;
var fileName = 'test/test.md';
var opts = {title: 'File $BASENAME in $DIRNAME', stylesheet: 'test/style.css'};
...
// Write a header.
console.log('===============================');
// Write a trailer at eof.
md.once('end', function() {
  console.log('===============================');
});
md.render(fileName, opts, function(err) {
  if (err) {
    console.error('>>>' + err);
    process.exit();
  }
  md.pipe(process.stdout);
});

Options for markdown and markdownb

--flavor <type>

Format as type 'gfm' or just plain 'markdown'. May be abbreviated -f on the command line. Note that for the github-markdown utility or the GithubMarkdown class it is the 'markdown' flavor that gives you something resembling the README.md format on Github. Whereas, the 'gfm' flavor gives you something resembling the the format of comments and issues on Github. This is due to how the Github Markdown API works. On the other hand, for the markdown utility or the Markdown class it is virtually the opposite. For example, fenced code blocks don't work when using the markdown utility or the Markdown class with the --flavor markdown option. This is due to how the marked markdown parser works. The default value for this option is whichever flavor results in something more like README.md format.

--highlight

Highlight code blocks with style info. Highlight has no effect in github-markdown. May be abbreviated -h on the command line. Defaults to false.

--stylesheet <stylesheet>

Outputs HTML header with link element referring to the given stylesheet. May be abbreviated -s on the command line.

--title <title>

Outputs HTML header with given title. Title string may include special values $FILENAME, $DIRNAME, $BASENAME, or $PATHNAME variables which are replaced by the corresponding .md filename, directory name, base name, or full path, respectively. Alternatively, the title may be any text you wish. May be abbreviated -t on the command line.

--context <context>

Suupply the relevant Github user/project to use with # issue number references. Typically, these are not used in README.md files but, rather, in comments and issue text on Github. May be abbreviated -c on the command line.

--template <filename or path>

Optional HTML template file to be used. You can set this template instead of --title and --stylesheet. The only requirement is that the template should contain a token named {markdown} to indicate where the markdown code will be placed.

Example template:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My own title</title>
    <link rel="stylesheet" href="./mycss.css">
  </head>
  <body>
    <h3>My own header</h3>
    {markdown}
    <h3>My own footer</h3>
  </body>
</html>

--verbose

Verbose output. May be abbreviated -v on the command line. Defaults to false unless debug has been specified, in which case it is set to true. Only used by the command line utilities.

--debug

Debug output to stderr. For example, outputs the individual chunks of data pushed to output. May be abbreviated -d on the command line. Defaults to false. Used only by the command line utilities. However, the Markdown and GithubMarkdown classes both have a debug property.

--help

Output usage info. Only used by the command line utilities.

Markdown and GithubMarkdown class properties

bufmax

The chunk size for streaming -- that is, the maximum amout of data to push to the read operation at any given time. Defaults to 1024.

debug

Debug output to stderr. For example, outputs the individual chunks of data pushed to output. Defaults to false.

Markdown and GithubMarkdown class methods

render(fileName, opts, onDone)

Renders the markdown text in the given file using the given options. Calls the onDone callback function when rendering is finished, if specified. If you are going to pipe the output to another stream, this is best done in the callback function.

The onDone callback takes a single error parameter, which ought to be tested before performing any other operations on the Markdown or GithubMarkdown stream.

Before calling render, you can set up a test for end of file with on('end', cb), which is a good place to write any output that should follow the streamed HTML. See the above code example for how to do that.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Orc/discount: My C implementation of John Gruber&#39;s Markdown markup language ...发布时间:2022-08-18
下一篇:
BreezePython/AlgorithmMarkdown发布时间:2022-08-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap