@@ -37,15 +37,53 @@ component {
3737 var highlighted = replaceNewLines ( highlighter .highlight ( arguments .code , arguments .language , " html" ) );
3838
3939 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' ) #">'
4142 & arguments .code
4243 & ' </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 ;
4449 }
4550
4651 return highlighted ;
4752 }
4853
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+
4987// PRIVATE HELPERS
5088 private any function _getNextHighlight ( required string text , required string startPos = 1 ) {
5189 var referenceRegex = " ```([a-zA-Z\+]+)?\n(.*?)\n```" ;
0 commit comments