Serve marked rendered README.md file with elegant style.
npm i serve-marked
const fs = require('fs')
const http = require('http')
const { serveMarked } = require('serve-marked')
const markdown = fs.readFileSync('./README.md', 'utf8')
const serveReadme = serveMarked(markdown)
http.createServer(serveReadme).listen(3000)
or you can use it with options:
const serveReadme = serveMarked('# Markdown Content', {
title: 'Awesome Project',
preset: 'merri', // Available presets: 'github', 'merri'
contentClassName: 'main-body', // Default: 'markdown-body'
inlineCSS: `
@import url('https://rsms.me/inter/inter-ui.css');
body { color: #333 }
`,
beforeHeadEnd: '<meta name="description" content="...">',
beforeBodyEnd: '<script>/*...*/</script>',
sanitizer: (htmlString) => sanitize(htmlString) // bring your own html sanitizer if needed
})
WARNING: serve-marked does not sanitize the output HTML. Please use a sanitize library, like DOMPurify, sanitize-html or insane on the output HTML!