Marked は、基本的なマークダウン コンテンツから html コンテンツへの変換のみを処理し、独自のドキュメントとスタイルを持ち込むことを期待しています。これを処理するために、単純なノード スクリプトをまとめることができます。
// convertMd.js
var marked = require('marked')
var fs = require('fs')
const inFile = process.argv[2]
const outFile = process.argv[3]
const inputContent = fs.readFileSync(inFile, 'utf8')
const content = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
${marked(inputContent)}
</body>
</html>`
fs.writeFileSync(outFile, content)
tasks.json は次のようになります。
{
// See http://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "node",
"isShellCommand": true,
"args": ["./convertMd.js", "sample.md", "sample.html"],
"showOutput": "always"
}
他のコマンド ライン ツールを使用すると、より完全な html 出力が得られる場合があります。