Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f50c5ea93 | ||
|
|
aeb26aaccb | ||
|
|
8059112810 |
@@ -4,7 +4,7 @@ import * as loadLanguages from 'prismjs/components/index.js';
|
|||||||
loadLanguages();
|
loadLanguages();
|
||||||
|
|
||||||
const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
|
const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
|
||||||
if(req.method === "GET") {
|
if (req.method === "GET") {
|
||||||
context.res = {
|
context.res = {
|
||||||
// status: 200, /* Defaults to 200 */
|
// status: 200, /* Defaults to 200 */
|
||||||
body: "Ok"
|
body: "Ok"
|
||||||
@@ -12,7 +12,7 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = req.rawBody;
|
const data = req.rawBody;
|
||||||
if(!data.startsWith('```')) {
|
if (!data.startsWith('```')) {
|
||||||
context.res = {
|
context.res = {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: req.rawBody
|
body: req.rawBody
|
||||||
@@ -20,24 +20,32 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const regex = data.match(/^```([a-zA-Z]*)$/m)
|
const regex = data.match(/^```([a-zA-Z]*)$/m)
|
||||||
const lang = regex[1]
|
const lang = regex[1]?.toLowerCase()
|
||||||
if(!lang) {
|
if (!lang) {
|
||||||
context.res = {
|
context.res = {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: req.rawBody
|
body: req.rawBody
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const highlighted = Prism.highlight(data.replace(/```[a-zA-Z]*/m, '').replace('```', ''), Prism.languages[lang], lang)
|
try {
|
||||||
|
const highlighted = Prism.highlight(data.replace(/```[a-zA-Z]*/m, '').replace('```', ''), Prism.languages[lang], lang)
|
||||||
// remove any backticks and the language
|
|
||||||
const highlightedCleaned = highlighted.trim()
|
// remove any backticks and the language
|
||||||
context.res = {
|
const highlightedCleaned = highlighted.trim()
|
||||||
status: 200,
|
context.res = {
|
||||||
body: `<pre><code>${highlightedCleaned}</code></pre>`
|
status: 200,
|
||||||
|
body: `<pre class="language-${lang}"><code class="language-${lang}">${highlightedCleaned}</code></pre>`
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
context.res = {
|
||||||
|
status: 200,
|
||||||
|
body: req.rawBody
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default httpTrigger;
|
export default httpTrigger;
|
||||||
Reference in New Issue
Block a user