Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions blocks/convert-markdown-to-html/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { post } = require('../../helpers/http')
const { Block } = require('node-webpipe')

new Block()
.name('Convert Markdown to HTML')
.description('Determine whether or not a hostname exists.')
.input(
'text',
'string',
'Required. The Markdown text to render in HTML. Markdown content must be 400 KB or less.'
)
.input(
'mode',
'string',
'The rendering mode. Can be either: [`gfm`,`markdown`]'
)
.input(
'context',
'string',
'The repository context to use when creating references in gfm mode. Omit this parameter when using markdown mode.'
)
.output(
'html',
'string',
'Returns an HTML version preferred flavor of Markdown.'
)
.handle(async function (inputs, cb) {
const options = {
hostname: 'api.github.com',
path: '/markdown',
method: 'POST'
}
const html = await post(options, inputs)
cb(null, { html })
})
.listen()
35 changes: 35 additions & 0 deletions helpers/http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const https = require('https')

const post = (options, params) => {
const paramsified = JSON.stringify(params)
options.headers = {
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength(paramsified),
'User-Agent': 'WebPipes-Block-Examples'
}
return new Promise((resolve, reject) => {
const req = https.request(options, res => {
let body = ''
res.setEncoding('utf8')
res.on('data', chunk => (body += chunk.toString()))
res.on('error', reject)
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode <= 299) {
resolve(body)
} else {
reject(`Request failed. status: ${res.statusCode}, body: ${body}`)
}
})
})

req.on('error', e => {
console.error(`problem with request: ${e.message}`)
})

req.write(paramsified)
req.end()
})
}
const get = (options, params) => {}

module.exports = { get, post }