Skip to content

amio/serve-marked

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serve-marked

version repo

Serve marked rendered README.md file with elegant style.

Usage

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!

Example

License

ISC