-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Syntax highlighting for code blocks #2
Comments
@littledivy Thanks! Cool, I will look into it. I think it should work as an extension, so its optional. |
@littledivy |
@littledivy import { DefaultTheme } from "https://deno.land/x/[email protected]/themes/mod.ts";
import Typescript from "https://deno.land/x/[email protected]/languages/typescript/typescript.ts";
const CodeBlockExt = {
generateNode(genFn: any, node: Node, parent: Node, options: Options) {
if(node.type === 'code') {
let code: string = node.value;
switch(node.lang) {
case 'ts':
code = new Typescript(node.value, DefaultTheme, { output: "console"}).highlight();
break;
}
// just some formatting
const lineStart = colors.bgWhite(colors.white(' '));
let result =
colors.bgWhite(colors.black(` codeblock [${node.lang}]`) + colors.white(''.padEnd(45, '.'))) +'\r\n'
+ lineStart+'\r\n'
+ code.split(/\r?\n/).map(hl => lineStart + '\t' + hl).join('\r\n') + '\r\n'
+ lineStart+'\r\n'
+ colors.bgWhite(colors.white(''.padEnd(60, '.'))) + '\r\n';
return result;
}
}
}
let md = '';// your markdown text with codeblocks;
console.log(renderMarkdown(md, {extensions: [CodeBlockExt]})) results in: Closing this as extensions provide the possibility to do what you requested as seen above, and currently I dont plan to provide official extensions. |
Awesome module! I've been working on a lightweight syntax highlighter, Hue. Would love to see it being used here :D
The text was updated successfully, but these errors were encountered: