diff --git a/api/rendering/SyntaxHighlighter.cfc b/api/rendering/SyntaxHighlighter.cfc index bfe77936b..1da4adc2a 100644 --- a/api/rendering/SyntaxHighlighter.cfc +++ b/api/rendering/SyntaxHighlighter.cfc @@ -37,15 +37,53 @@ component { var highlighted = replaceNewLines( highlighter.highlight( arguments.code, arguments.language, "html" ) ); if ( useTryCf ) { - var rawCode = '' & Chr(10); - return rawCode & highlighted; + var codeResult = getCodeResult(arguments.code, arguments.language) + if ( isEmpty( codeResult ) ) + return rawCode & highlighted; + var preview = '
'; + return rawCode & highlighted & preview; } return highlighted; } + private function getCodeResult(code, lang) output=false { + var codeKey = createGUID(); + server["_luceeExamples_#codeKey#"] = arguments.code; + + // alas server.system is read only + //var env = duplicate(server.system.environment); + //var props = duplicate(server.system.properties); + //server.system.properties = {}; + //server.system.environment = {}; + + try { + var res = _internalRequest( + template: "/exampleRunner/index.cfm", + form: { + codeKey: codeKey, + lang: arguments.lang + } + ); + } catch(e){ + //request.logger( e.message ); + //dump(arguments); + //rethrow; + return e.message; + } + + //server.system.environment = env; + //server.system.properties = props; + + if (!structKeyExists(res, "fileContent")) + return ""; + return res.fileContent; + } + // PRIVATE HELPERS private any function _getNextHighlight( required string text, required string startPos=1 ) { var referenceRegex = "```([a-zA-Z\+]+)?\n(.*?)\n```"; diff --git a/builders/html/assets/trycf/js/code-editor3.js b/builders/html/assets/trycf/js/code-editor3.js index cbceaa3d3..c339cbbdd 100644 --- a/builders/html/assets/trycf/js/code-editor3.js +++ b/builders/html/assets/trycf/js/code-editor3.js @@ -125,6 +125,7 @@ angular.module("code.editor", []).directive("codeEditor", function ($timeout) { showError: "@showError", asserts: "@asserts", code: "@code", + preview: "@preview", codeGist: "@codeGist", setupCode: "@setupCode", setupCodeGist: "@setupCodeGist", @@ -135,6 +136,7 @@ angular.module("code.editor", []).directive("codeEditor", function ($timeout) { template: editorTemplate, link: function (scope, element, attrs) { scope.code = attrs.code; + scope.preview = attrs.preview; scope.codeGist = attrs.codeGist; scope.setupCode = attrs.setupCode; scope.setupCodeGist = attrs.setupCodeGist; @@ -329,6 +331,7 @@ angular.module("code.editor", []).directive("codeEditor", function ($timeout) { aceEditor.resize(true); } editor.show(); + resultsDiv.html(attrs.preview); if (scope.fullscreen !== undefined && scope.fullscreen == "true") { toggleFullscreen(); } diff --git a/builders/html/assets/trycf/js/docscodeloader.js b/builders/html/assets/trycf/js/docscodeloader.js index 12c24a7be..835b73138 100644 --- a/builders/html/assets/trycf/js/docscodeloader.js +++ b/builders/html/assets/trycf/js/docscodeloader.js @@ -19,6 +19,13 @@ code = "