-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathPygments.cfc
More file actions
41 lines (36 loc) · 1.49 KB
/
Pygments.cfc
File metadata and controls
41 lines (36 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// jython is only python 2.7, pygments 2.6 requires python 3.0
component
javaSettings='{
"maven": [
{ "groupId": "org.python", "artifactId": "jython-standalone", "version": "2.7.4" },
{ "groupId": "org.pygments", "artifactId": "pygments", "version": "2.5.2" }
]
}'
{
import org.python.util.PythonInterpreter;
/**
* Highlights Python code using Pygments via Jython.
* @param code The Python code to highlight.
* @return HTML string with syntax highlighting.
*/
public string function highlight(required string code, string language, string formatter="html") {
var interpreter = new PythonInterpreter();
interpreter.set("code", arguments.code);
interpreter.set("language", arguments.language);
interpreter.set("formatter", arguments.formatter);
var pythonFile = expandPath( getDirectoryFromPath( getCurrentTemplatePath() ) & "/highlighter.py" );
interpreter.execFile( pythonFile );
var result = interpreter.get("result", createObject('java', 'java.lang.String').getClass());
var lexer = interpreter.get("lexer");
// dump(var=lexer.toString(), label="#language#");
return result;
}
public string function getCss() {
var interpreter = new PythonInterpreter();
interpreter.set("style", "default");
var pythonFile = expandPath( getDirectoryFromPath( getCurrentTemplatePath() ) & "pygmentsCss.py" );
interpreter.execFile( pythonFile );
var css = interpreter.get("css", createObject('java', 'java.lang.String').getClass());
return css;
}
}