For batch-rendering an array of Markdown strings via GitHub's API (using Octokit/REST).
Uses only 1 GitHub-API request to render all the markdown strings.
Useful for mitigating GitHub's API's request rate-limit.
npm i github-markdown-batch-render
Basic usage:
const markdowns = [
'**bold** _italic_',
'# Title\n\nParagrapgh',
'```\nCodeblock\n```'
]
const renderedMarkdowns = await ghMdBatchRender(markdowns)
/**
* 'renderedMarkdowns' will be: [
* '<p><strong>bold</strong> <em>italic</em></p>',
* '<h1>Title</h1>\n<p>Paragrapgh</p>',
* '<pre class="notranslate"><code class="notranslate">Codeblock\n</code></pre>'
* ]
*/
Force use an Octokit
instance:
const octokit = new Octokit({ auth: 'personalaccesstoken' })
const renderedMarkdowns = await ghMdBatchRender(markdowns, { octokit })
Passing mode
/ context
option(s) to the Octokit.rest.markdown.render
method:
Note:
ghMdBatchRender
'smode
option defaults to"gfm"
unlike Octokit, which defaults to"markdown"
.
const renderedMarkdowns = await ghMdBatchRender(markdowns, {
mode: 'markdown', // default is "gfm"
context: 'github/linguist',
})