Skip to content

Commit

Permalink
chore: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 22, 2020
1 parent 0d89211 commit 9c3c8f6
Show file tree
Hide file tree
Showing 8 changed files with 774 additions and 124 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ coverage
build
dist
shrinkwrap.yaml
example
examples
46 changes: 46 additions & 0 deletions example/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* @dimerapp/markdown
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import { join } from 'path'
import { readFileSync } from 'fs'
import { createServer } from 'http'

import { template } from './template'
import { MarkdownFile, toHtml, macros } from '../index'

const mdFilePath = join(__dirname, './sample.md')
const mdContents = readFileSync(mdFilePath, 'utf-8')
const routesImage = readFileSync(join(__dirname, './routes.png'))

createServer(async (req, res) => {
if (req.url === '/routes.png') {
res.writeHead(200, { 'content-type': 'image/png' })
res.end(routesImage)
return
}

const md = new MarkdownFile(mdContents, {
filePath: mdFilePath,
allowHtml: req.url?.includes('allowHtml=true'),
enableDirectives: req.url?.includes('enableDirectives=true'),
generateToc: true,
collectAssets: true,
})

macros.codesandbox(md)
macros.youtube(md)
macros.note(md)
macros.tip(md)
macros.warning(md)
macros.video(md)

await md.process()
res.writeHead(200, { 'content-type': 'text/html' })
res.end(template(toHtml(md)))
}).listen(3000, () => console.log(`Listening on http://localhost:3000`))
Binary file added example/routes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9c3c8f6

Please sign in to comment.