Skip to content

Commit 0ab8b2c

Browse files
committed
add code highlighting into the console debug
1 parent dedc679 commit 0ab8b2c

File tree

5 files changed

+393
-237
lines changed

5 files changed

+393
-237
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "node",
99
"request": "launch",
1010
"name": "Launch dev",
11-
"program": "${workspaceRoot}\\examples\\cyclic.js"
11+
"program": "${workspaceRoot}\\examples\\next.js"
1212
},
1313
{
1414
"type": "node",

lib/helpers/prettier.js

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
// globals window
2-
let prettier;
2+
let prettier, prettierOpts;
3+
let hljs, hljsOpts;
34

4-
let moduleName = "prettier"; // rollup
5+
let mod1 = "prettier"; // rollup
6+
let mod2 = "cli-highlight"; // rollup
57

68
module.exports = function(source) {
7-
if (!prettier)
8-
prettier = require(moduleName);
9+
if (!prettier) {
10+
prettier = require(mod1);
11+
prettierOpts = {
12+
parser: "babel",
13+
useTabs: false,
14+
printWidth: 120,
15+
trailingComma: "none",
16+
tabWidth: 4,
17+
singleQuote: false,
18+
semi: true,
19+
bracketSpacing: true
20+
};
921

10-
return prettier.format(source, {
11-
parser: "babel",
12-
useTabs: false,
13-
printWidth: 120,
14-
trailingComma: "none",
15-
tabWidth: 4,
16-
singleQuote: false,
17-
semi: true,
18-
bracketSpacing: true
19-
});
22+
hljs = require(mod2);
23+
hljsOpts = {
24+
language: "js",
25+
theme: hljs.fromJson({
26+
keyword: ["white", "bold"],
27+
built_in: "magenta",
28+
literal: "cyan",
29+
number: "magenta",
30+
regexp: "red",
31+
string: ["yellow", "bold"],
32+
symbol: "plain",
33+
class: "blue",
34+
attr: "plain",
35+
function: ["white", "bold"],
36+
title: "plain",
37+
params: "green",
38+
comment: "grey"
39+
})
40+
};
41+
}
42+
43+
const res = prettier.format(source, prettierOpts);
44+
return hljs.highlight(res, hljsOpts);
2045
};

0 commit comments

Comments
 (0)