File tree 3 files changed +47
-1
lines changed
3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change
1
+ web : node support/babelmark-responder.js
Original file line number Diff line number Diff line change 16
16
"markdown-it" : " bin/markdown-it.js"
17
17
},
18
18
"scripts" : {
19
- "test" : " make test"
19
+ "test" : " make test" ,
20
+ "heroku-postbuild" : " npm install express"
20
21
},
21
22
"files" : [
22
23
" index.js" ,
39
40
"chai" : " ^3.4.1" ,
40
41
"coveralls" : " ~2.11.9" ,
41
42
"eslint" : " ^3.5.0" ,
43
+ "express" : " ^4.14.0" ,
42
44
"highlight.js" : " ^9.2.0" ,
43
45
"istanbul" : " ^0.4.5" ,
44
46
"jade" : " ~1.11.0" ,
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+
3
+ /* eslint-env es6 */
4
+ /* eslint-disable no-console */
5
+ 'use strict' ;
6
+
7
+ const md = require ( '../' ) ( 'commonmark' ) ;
8
+ const app = require ( 'express' ) ( ) ;
9
+
10
+ const version = require ( '../package.json' ) . version ;
11
+
12
+ const banner = `<!doctype html>
13
+ <html lang="en">
14
+ <head>
15
+ <meta charset="utf-8">
16
+ <title>markdown-it responder for babelmark</title>
17
+ </head>
18
+ <body>
19
+ <p><a href="https://github.com/markdown-it/markdown-it" target="_blank">markdown-it</a>
20
+ responder for <a href="http://johnmacfarlane.net/babelmark2/" target="_blank">Babelmark2</a></p>
21
+ <p>Usage: /?text=...</p>
22
+ </body>
23
+ </html>
24
+ ` ;
25
+
26
+ app . set ( 'port' , ( process . env . PORT || 5000 ) ) ;
27
+
28
+ app . get ( '/' , function ( req , res ) {
29
+ if ( typeof req . query . text === 'string' ) {
30
+ res . json ( {
31
+ name : 'markdown-it' ,
32
+ html : md . render ( req . query . text . slice ( 0 , 1000 ) ) ,
33
+ version
34
+ } ) ;
35
+ return ;
36
+ }
37
+ res . setHeader ( 'Content-Type' , 'text/html' ) ;
38
+ res . send ( banner ) ;
39
+ } ) ;
40
+
41
+ app . listen ( app . get ( 'port' ) , function ( ) {
42
+ console . log ( `Node app is running on port ${ app . get ( 'port' ) } ` ) ;
43
+ } ) ;
You can’t perform that action at this time.
0 commit comments