@@ -37,15 +37,53 @@ component {
37
37
var highlighted = replaceNewLines ( highlighter .highlight ( arguments .code , arguments .language , " html" ) );
38
38
39
39
if ( useTryCf ) {
40
- var rawCode = ' <script type="text/template" id="code-#LCase ( Hash ( highlighted ) ) #" data-trycf="true" data-script="#( arguments .language == ' cfs' ) #">'
40
+ var hashId = " code-#LCase ( Hash ( highlighted ) ) #" ;
41
+ var rawCode = ' <script type="text/template" id="#hashId #" data-trycf="true" data-script="#( arguments .language == ' cfs' ) #">'
41
42
& arguments .code
42
43
& ' </script>' & Chr (10 );
43
- return rawCode & highlighted ;
44
+ var codeResult = getCodeResult (arguments .code , arguments .language )
45
+ if ( isEmpty ( codeResult ) )
46
+ return rawCode & highlighted ;
47
+ var preview = ' <div id="result-#hashId #" style="display:none;">#toBase64 (codeResult ) #</div>' ;
48
+ return rawCode & highlighted & preview ;
44
49
}
45
50
46
51
return highlighted ;
47
52
}
48
53
54
+ private function getCodeResult (code , lang ) output = false {
55
+ var codeKey = createGUID ();
56
+ server [" _luceeExamples_#codeKey #" ] = arguments .code ;
57
+
58
+ // alas server.system is read only
59
+ // var env = duplicate(server.system.environment);
60
+ // var props = duplicate(server.system.properties);
61
+ // server.system.properties = {};
62
+ // server.system.environment = {};
63
+
64
+ try {
65
+ var res = _internalRequest (
66
+ template : " /exampleRunner/index.cfm" ,
67
+ form : {
68
+ codeKey : codeKey ,
69
+ lang : arguments .lang
70
+ }
71
+ );
72
+ } catch (e ){
73
+ // request.logger( e.message );
74
+ // dump(arguments);
75
+ // rethrow;
76
+ return e .message ;
77
+ }
78
+
79
+ // server.system.environment = env;
80
+ // server.system.properties = props;
81
+
82
+ if (! structKeyExists (res , " fileContent" ))
83
+ return " " ;
84
+ return res .fileContent ;
85
+ }
86
+
49
87
// PRIVATE HELPERS
50
88
private any function _getNextHighlight ( required string text , required string startPos = 1 ) {
51
89
var referenceRegex = " ```([a-zA-Z\+]+)?\n(.*?)\n```" ;
0 commit comments