feat(plugins/code): add new code plugin (#526)
This commit is contained in:
@@ -208,16 +208,15 @@ export async function which(command) {
|
||||
return false
|
||||
}
|
||||
|
||||
/**Code hightlighter */
|
||||
export async function highlight(code, lang) {
|
||||
return lang in prism.languages ? prism.highlight(code, prism.languages[lang]) : code
|
||||
}
|
||||
|
||||
/**Markdown-html sanitizer-interpreter */
|
||||
export async function markdown(text, {mode = "inline", codelines = Infinity} = {}) {
|
||||
//Sanitize user input once to prevent injections and parse into markdown
|
||||
let rendered = await marked(htmlunescape(htmlsanitize(text)), {
|
||||
highlight(code, lang) {
|
||||
return lang in prism.languages ? prism.highlight(code, prism.languages[lang]) : code
|
||||
},
|
||||
silent:true,
|
||||
xhtml:true,
|
||||
})
|
||||
let rendered = await marked(htmlunescape(htmlsanitize(text)), {highlight, silent:true, xhtml:true})
|
||||
//Markdown mode
|
||||
switch (mode) {
|
||||
case "inline": {
|
||||
|
||||
@@ -35,6 +35,7 @@ export default function({faker}, target, that, args) {
|
||||
email:faker.internet.email(),
|
||||
date:`${faker.date.recent(7)}`,
|
||||
},
|
||||
url:"https://api.github.com/repos/lowlighter/metrics/commits/MOCKED_SHA",
|
||||
},
|
||||
author:{
|
||||
login:faker.internet.userName(),
|
||||
|
||||
@@ -336,6 +336,23 @@
|
||||
},
|
||||
})
|
||||
: null),
|
||||
//Code snippet
|
||||
...(set.plugins.enabled.code
|
||||
? ({
|
||||
code: {
|
||||
snippet: {
|
||||
sha: faker.git.shortSha(),
|
||||
message: faker.lorem.sentence(),
|
||||
filename: 'docs/specifications.html',
|
||||
status: "modified",
|
||||
additions: faker.datatype.number(50),
|
||||
deletions: faker.datatype.number(50),
|
||||
patch: `<span class="token coord">@@ -0,0 +1,5 @@</span><br> //Imports<br><span class="token inserted">+ import app from "./src/app.mjs"</span><br><span class="token deleted">- import app from "./src/app.js"</span><br> //Start app<br> await app()<br>\\ No newline at end of file`,
|
||||
repo: `${faker.random.word()}/${faker.random.word()}`,
|
||||
},
|
||||
}
|
||||
})
|
||||
: null),
|
||||
//Languages
|
||||
...(set.plugins.enabled.languages
|
||||
? ({
|
||||
|
||||
Reference in New Issue
Block a user