Commit 8e31049e authored by carlosperate's avatar carlosperate

Removes unnecessary HTML scape chars sanitation on Arduino code generation.

Originally placed before the code diff feature was added, it is no longer required. This was also causing issues with code being displayed with the scape characters instead of HTML unsafe symbols.

Fixes #47.
parent b2882aee
...@@ -609,8 +609,7 @@ Ardublockly.XmlTextareaToBlocks = function() { ...@@ -609,8 +609,7 @@ Ardublockly.XmlTextareaToBlocks = function() {
* @type {!String} * @type {!String}
* @private * @private
*/ */
Ardublockly.PREVIOUS_ARDUINO_CODE_ = Ardublockly.PREV_ARDUINO_CODE_ = 'void setup() {\n\n}\n\n\nvoid loop() {\n\n}';
'void setup() {\n\n}\n\n\nvoid loop() {\n\n}';
/** /**
* Populate the Arduino Code and Blocks XML panels with content generated from * Populate the Arduino Code and Blocks XML panels with content generated from
...@@ -618,20 +617,12 @@ Ardublockly.PREVIOUS_ARDUINO_CODE_ = ...@@ -618,20 +617,12 @@ Ardublockly.PREVIOUS_ARDUINO_CODE_ =
*/ */
Ardublockly.renderContent = function() { Ardublockly.renderContent = function() {
// Only regenerate the code if a block is not being dragged // Only regenerate the code if a block is not being dragged
if (Ardublockly.blocklyIsDragging()) { if (Ardublockly.blocklyIsDragging()) return;
return;
}
// Render Arduino Code with latest change highlight and syntax highlighting // Render Arduino Code with latest change highlight and syntax highlighting
var arduinoCode = Ardublockly.generateArduino(); var arduinoCode = Ardublockly.generateArduino();
if (arduinoCode !== Ardublockly.PREVIOUS_ARDUINO_CODE_) { if (arduinoCode !== Ardublockly.PREV_ARDUINO_CODE_) {
var arduinoContent = document.getElementById('content_arduino'); var diff = JsDiff.diffWords(Ardublockly.PREV_ARDUINO_CODE_, arduinoCode);
// Sets content in case of no pretify and serves as a fast way to scape html
arduinoContent.textContent = arduinoCode;
arduinoCode = arduinoContent.innerHTML;
if (typeof prettyPrintOne == 'function') {
var diff = JsDiff.diffWords(Ardublockly.PREVIOUS_ARDUINO_CODE_,
arduinoCode);
var resultStringArray = []; var resultStringArray = [];
for (var i = 0; i < diff.length; i++) { for (var i = 0; i < diff.length; i++) {
if (diff[i].added) { if (diff[i].added) {
...@@ -641,15 +632,13 @@ Ardublockly.renderContent = function() { ...@@ -641,15 +632,13 @@ Ardublockly.renderContent = function() {
resultStringArray.push(diff[i].value); resultStringArray.push(diff[i].value);
} }
} }
var codeHtml = prettyPrintOne(resultStringArray.join(''), 'cpp', false); document.getElementById('content_arduino').innerHTML =
arduinoContent.innerHTML = codeHtml; prettyPrintOne(resultStringArray.join(''), 'cpp', false);
} Ardublockly.PREV_ARDUINO_CODE_ = arduinoCode;
Ardublockly.PREVIOUS_ARDUINO_CODE_ = arduinoCode;
} }
// Generate plain XML into element // Generate plain XML into element
var xmlContent = document.getElementById('content_xml'); document.getElementById('content_xml').value = Ardublockly.generateXml();
xmlContent.value = Ardublockly.generateXml();
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment