File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed
blocks/convert-markdown-to-html Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ const { post } = require ( '../../helpers/http' )
2+ const { Block } = require ( 'node-webpipe' )
3+
4+ new Block ( )
5+ . name ( 'Convert Markdown to HTML' )
6+ . description ( 'Determine whether or not a hostname exists.' )
7+ . input (
8+ 'text' ,
9+ 'string' ,
10+ 'Required. The Markdown text to render in HTML. Markdown content must be 400 KB or less.'
11+ )
12+ . input (
13+ 'mode' ,
14+ 'string' ,
15+ 'The rendering mode. Can be either: [`gfm`,`markdown`]'
16+ )
17+ . input (
18+ 'context' ,
19+ 'string' ,
20+ 'The repository context to use when creating references in gfm mode. Omit this parameter when using markdown mode.'
21+ )
22+ . output (
23+ 'html' ,
24+ 'string' ,
25+ 'Returns an HTML version preferred flavor of Markdown.'
26+ )
27+ . handle ( async function ( inputs , cb ) {
28+ const options = {
29+ hostname : 'api.github.com' ,
30+ path : '/markdown' ,
31+ method : 'POST'
32+ }
33+ const html = await post ( options , inputs )
34+ cb ( null , { html } )
35+ } )
36+ . listen ( )
Original file line number Diff line number Diff line change 1+ const https = require ( 'https' )
2+
3+ const post = ( options , params ) => {
4+ const paramsified = JSON . stringify ( params )
5+ options . headers = {
6+ 'Content-Type' : 'text/plain' ,
7+ 'Content-Length' : Buffer . byteLength ( paramsified ) ,
8+ 'User-Agent' : 'WebPipes-Block-Examples'
9+ }
10+ return new Promise ( ( resolve , reject ) => {
11+ const req = https . request ( options , res => {
12+ let body = ''
13+ res . setEncoding ( 'utf8' )
14+ res . on ( 'data' , chunk => ( body += chunk . toString ( ) ) )
15+ res . on ( 'error' , reject )
16+ res . on ( 'end' , ( ) => {
17+ if ( res . statusCode >= 200 && res . statusCode <= 299 ) {
18+ resolve ( body )
19+ } else {
20+ reject ( `Request failed. status: ${ res . statusCode } , body: ${ body } ` )
21+ }
22+ } )
23+ } )
24+
25+ req . on ( 'error' , e => {
26+ console . error ( `problem with request: ${ e . message } ` )
27+ } )
28+
29+ req . write ( paramsified )
30+ req . end ( )
31+ } )
32+ }
33+ const get = ( options , params ) => { }
34+
35+ module . exports = { get, post }
You can’t perform that action at this time.
0 commit comments