Fix escaping issue in Code demo.

Resolves #1002
This commit is contained in:
Neil Fraser
2019-06-12 00:19:58 -07:00
committed by Neil Fraser
parent f1c73e2244
commit 74f908d77f
2 changed files with 19 additions and 21 deletions

View File

@@ -304,35 +304,33 @@ Code.renderContent = function() {
xmlTextarea.value = xmlText;
xmlTextarea.focus();
} else if (content.id == 'content_javascript') {
Code.attemptCodeGeneration(Blockly.JavaScript, 'js');
Code.attemptCodeGeneration(Blockly.JavaScript);
} else if (content.id == 'content_python') {
Code.attemptCodeGeneration(Blockly.Python, 'py');
Code.attemptCodeGeneration(Blockly.Python);
} else if (content.id == 'content_php') {
Code.attemptCodeGeneration(Blockly.PHP, 'php');
Code.attemptCodeGeneration(Blockly.PHP);
} else if (content.id == 'content_dart') {
Code.attemptCodeGeneration(Blockly.Dart, 'dart');
Code.attemptCodeGeneration(Blockly.Dart);
} else if (content.id == 'content_lua') {
Code.attemptCodeGeneration(Blockly.Lua, 'lua');
Code.attemptCodeGeneration(Blockly.Lua);
}
if (typeof PR == 'object') {
PR.prettyPrint();
}
};
/**
* Attempt to generate the code and display it in the UI, pretty printed.
* @param generator {!Blockly.Generator} The generator to use.
* @param prettyPrintType {string} The file type key for the pretty printer.
*/
Code.attemptCodeGeneration = function(generator, prettyPrintType) {
Code.attemptCodeGeneration = function(generator) {
var content = document.getElementById('content_' + Code.selected);
content.textContent = '';
if (Code.checkAllGeneratorFunctionsDefined(generator)) {
var code = generator.workspaceToCode(Code.workspace);
content.textContent = code;
if (typeof PR.prettyPrintOne == 'function') {
code = content.textContent;
code = PR.prettyPrintOne(code, prettyPrintType);
content.innerHTML = code;
}
// Remove the 'prettyprinted' class, so that Prettify will recalculate.
content.className = content.className.replace('prettyprinted', '');
}
};
@@ -346,7 +344,7 @@ Code.checkAllGeneratorFunctionsDefined = function(generator) {
for (var i = 0; i < blocks.length; i++) {
var blockType = blocks[i].type;
if (!generator[blockType]) {
if (missingBlockGenerators.indexOf(blockType) === -1) {
if (missingBlockGenerators.indexOf(blockType) == -1) {
missingBlockGenerators.push(blockType);
}
}
@@ -354,8 +352,8 @@ Code.checkAllGeneratorFunctionsDefined = function(generator) {
var valid = missingBlockGenerators.length == 0;
if (!valid) {
var msg = 'The generator code for the following blocks not specified for '
+ generator.name_ + ':\n - ' + missingBlockGenerators.join('\n - ');
var msg = 'The generator code for the following blocks not specified for ' +
generator.name_ + ':\n - ' + missingBlockGenerators.join('\n - ');
Blockly.alert(msg); // Assuming synchronous. No callback.
}
return valid;

View File

@@ -66,11 +66,11 @@
</tr>
</table>
<div id="content_blocks" class="content"></div>
<pre id="content_javascript" class="content"></pre>
<pre id="content_python" class="content"></pre>
<pre id="content_php" class="content"></pre>
<pre id="content_lua" class="content"></pre>
<pre id="content_dart" class="content"></pre>
<pre id="content_javascript" class="content prettyprint lang-js"></pre>
<pre id="content_python" class="content prettyprint lang-py"></pre>
<pre id="content_php" class="content prettyprint lang-php"></pre>
<pre id="content_lua" class="content prettyprint lang-lua"></pre>
<pre id="content_dart" class="content prettyprint lang-dart"></pre>
<textarea id="content_xml" class="content" wrap="off"></textarea>
<xml id="toolbox" style="display: none">