diff --git a/blocks/convert-markdown-to-html/index.js b/blocks/convert-markdown-to-html/index.js new file mode 100644 index 0000000..aef1a5c --- /dev/null +++ b/blocks/convert-markdown-to-html/index.js @@ -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() diff --git a/helpers/http.js b/helpers/http.js new file mode 100644 index 0000000..5ab86fb --- /dev/null +++ b/helpers/http.js @@ -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 }