A Fastify plugin to add markdown support
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example v0.2.0 May 25, 2018
fastify (v0.3.0)add .d.ts May 27, 2018
test v0.2.0 May 25, 2018
.gitignore v0.2.0 May 25, 2018
.travis.yml v0.2.0 May 25, 2018
LICENSE v0.2.0 May 25, 2018
Readme.md see wiki May 30, 2018
index.js v0.4.0 Decrease code Jun 6, 2018
package-lock.json v0.2.0 May 25, 2018
package.json v0.4.0 Decrease code Jun 6, 2018

Readme.md

fastify-markdown

Greenkeeper badge

js-standard-style Build Status

fastify-markdown is a plugin for Fastify parse markdown code or file.

Install

npm install --save fastify-markdown

Usage

const path = require('path')
const fastify = require('fastify')({ logger: { level: 'trace' } })

/**
 * using opts.src read markdown from file
 */
fastify
  .register(require('fastify-markdown'), { src: true })
  .get('/', (req, reply) => {
    return reply.markdown(path.join(__dirname, '..', 'Readme.md'))
  })
  .listen(3000, err => {
    if (err) throw err
    else console.log('server running on http://localhost:3000 ...')
  })

/* -- or --*/

/**
 * async using opts.src from file
 */
fastify
  .register(require('../'), {
    src: true, markedOptions: { gfm: false }
  })
  .get('/', async (req, reply) => {
    const md = await reply.markdown(path.join(__dirname, '..', 'Readme.md'))
    return md
  })
  .listen(3000, err => {
    if (err) throw err
    else console.log('server running on http://localhost:3000 ...')
  })

/**
 * using opts.data parse markdown direct literal
 */
fastify
  .register(require('fastify-markdown'), { data: true })
  .get('/', (req, reply) => {
      const md = reply.markdown(`**BOLD**`)
      reply.send(md)
  })
  .listen(3000, err => {
      if (err) throw err
      else console.log('server running on http://localhost:3000 ...')
  })

/**
 * using internal marked's options
 */
const testOptions = {
  gfm: false
}

fastify
  .register(require('fastify-markdown'), { markedOptions: testOptions })
  .get('/', (req, reply) => {
      const md = reply.markdown('**BOLD**')
      reply.send(md)
  })
  .listen(3000, err => {
      if (err) throw err
      else console.log('server running on http://localhost:3000 ...')
  })

/**
 * using marked as object see:https://marked.js.org/
 */
fastify
  .register(require('fastify-markdown'), /*non options or other*/)
  .get('/', (req, reply) => {
      const md = reply.markdown().parse('**bold title**')
      reply.send(md)
  })
  .listen(3000, err => {
      if (err) throw err
      else console.log('server running on http://localhost:3000 ...')
  })

Options (Optional)

  • src (boolean | string)
    • true: Means to resolve the markdown file.
    • string(deprecated): the .md file path.If the data option is set, this option will be ignored.
  • data (boolean | string)
    • true: Means to resolve the markdown data.
    • string(deprecated): or a string that conforms to the markdown syntax.
  • markedOptions (object)
    • marked options used

See marked and fastify for more options

All options are optional. in this case as if using opts.data.

Note Can be set to any option other than those listed above, in which case the internal markdown parser will be returned.

Typescript usage see wiki

License

Licensed under MIT.