var fs = require('fs'); var yamlish = require('yamlish'); // npm install yamlish // md文件头部类似下面的注释信息,为了不会于文章里的注释符号冲突,加了>> // 第一行需要时空行,因为yamlish库是从第二行开始解析得,你妹啊 /*<< Title: how to make love with a girl Date: 2014-04-01 12:14:05 Category: love Tags: love, girl Sources: github.com >>*/ // 假设上面得注释信息是在test.md文件里 var md_content = (fs.readFileSync("test.md") + '').split('>>*/'); var md_info = md_content[0].substr(5); // /*<<\n md_info = yamlish.decode(md_info); /** md_info: { Title: 'how to make love with a girl', Date: '2014-04-01 12:14:05', Category: 'love', Tags: 'love, girl', Sources: 'github.com', '': '' } */