Commit dc8d020e by Mushtaq Ali Committed by GitHub

Merge pull request #13875 from edx/revert-13242-ekafeel/TNL-5256-prettify-xml

Revert "format xml before displaying"
parents 6c37e282 d337da74
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
## and attach them to the global context manually. ## and attach them to the global context manually.
define(["jquery", "underscore", "codemirror", "tinymce", define(["jquery", "underscore", "codemirror", "tinymce",
"jquery.tinymce", "jquery.qtip", "jquery.scrollTo", "jquery.flot", "jquery.tinymce", "jquery.qtip", "jquery.scrollTo", "jquery.flot",
"jquery.cookie", "pretty-print", "utility"], "jquery.cookie",
function($, _, CodeMirror) { "utility"],
function($, _, CodeMirror, tinymce) {
window.$ = $; window.$ = $;
window._ = _; window._ = _;
require(['mathjax']); require(['mathjax']);
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
'mustache': 'js/vendor/mustache', 'mustache': 'js/vendor/mustache',
'codemirror': 'js/vendor/codemirror-compressed', 'codemirror': 'js/vendor/codemirror-compressed',
'codemirror/stex': 'js/vendor/CodeMirror/stex', 'codemirror/stex': 'js/vendor/CodeMirror/stex',
'pretty-print': 'js/lib/pretty-print',
'jquery': 'common/js/vendor/jquery', 'jquery': 'common/js/vendor/jquery',
'jquery-migrate': 'common/js/vendor/jquery-migrate', 'jquery-migrate': 'common/js/vendor/jquery-migrate',
'jquery.ui': 'js/vendor/jquery-ui.min', 'jquery.ui': 'js/vendor/jquery-ui.min',
......
...@@ -21,8 +21,7 @@ var options = { ...@@ -21,8 +21,7 @@ var options = {
{pattern: 'common_static/coffee/src/ajax_prefix.js', included: true}, {pattern: 'common_static/coffee/src/ajax_prefix.js', included: true},
{pattern: 'common_static/common/js/vendor/underscore.js', included: true}, {pattern: 'common_static/common/js/vendor/underscore.js', included: true},
{pattern: 'common_static/common/js/vendor/backbone.js', included: true}, {pattern: 'common_static/common/js/vendor/backbone.js', included: true},
{pattern: 'common_static/js/vendor/codemirror-compressed.js', included: true}, {pattern: 'common_static/js/vendor/CodeMirror/codemirror.js', included: true},
{pattern: 'common_static/js/lib/pretty-print.js', included: true},
{pattern: 'common_static/js/vendor/draggabilly.js'}, {pattern: 'common_static/js/vendor/draggabilly.js'},
{pattern: 'common_static/common/js/vendor/jquery.js', included: true}, {pattern: 'common_static/common/js/vendor/jquery.js', included: true},
{pattern: 'common_static/common/js/vendor/jquery-migrate.js', included: true}, {pattern: 'common_static/common/js/vendor/jquery-migrate.js', included: true},
......
...@@ -5,7 +5,7 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -5,7 +5,7 @@ describe 'MarkdownEditingDescriptor', ->
@descriptor = new MarkdownEditingDescriptor($('.problem-editor')) @descriptor = new MarkdownEditingDescriptor($('.problem-editor'))
saveResult = @descriptor.save() saveResult = @descriptor.save()
expect(saveResult.metadata.markdown).toEqual('markdown') expect(saveResult.metadata.markdown).toEqual('markdown')
expect(saveResult.data).toEqual('<problem>\n <p>markdown</p>\n</problem>') expect(saveResult.data).toXMLEqual('<problem>\n <p>markdown</p>\n</problem>')
it 'clears markdown when xml editor is selected', -> it 'clears markdown when xml editor is selected', ->
loadFixtures 'problem-with-markdown.html' loadFixtures 'problem-with-markdown.html'
@descriptor = new MarkdownEditingDescriptor($('.problem-editor')) @descriptor = new MarkdownEditingDescriptor($('.problem-editor'))
...@@ -101,7 +101,7 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -101,7 +101,7 @@ describe 'MarkdownEditingDescriptor', ->
describe 'markdownToXml', -> describe 'markdownToXml', ->
it 'converts raw text to paragraph', -> it 'converts raw text to paragraph', ->
data = MarkdownEditingDescriptor.markdownToXml('foo') data = MarkdownEditingDescriptor.markdownToXml('foo')
expect(data).toEqual('<problem>\n <p>foo</p>\n</problem>') expect(data).toXMLEqual('<problem>\n <p>foo</p>\n</problem>')
# test default templates # test default templates
it 'converts numerical response to xml', -> it 'converts numerical response to xml', ->
data = MarkdownEditingDescriptor.markdownToXml("""A numerical response problem accepts a line of text input from the student, and evaluates the input for correctness based on its numerical value. data = MarkdownEditingDescriptor.markdownToXml("""A numerical response problem accepts a line of text input from the student, and evaluates the input for correctness based on its numerical value.
...@@ -133,7 +133,7 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -133,7 +133,7 @@ describe 'MarkdownEditingDescriptor', ->
If you look at your hand, you can count that you have five fingers. If you look at your hand, you can count that you have five fingers.
[Explanation] [Explanation]
""") """)
expect(data).toEqual("""<problem> expect(data).toXMLEqual("""<problem>
<p>A numerical response problem accepts a line of text input from the student, and evaluates the input for correctness based on its numerical value.</p> <p>A numerical response problem accepts a line of text input from the student, and evaluates the input for correctness based on its numerical value.</p>
<p>The answer is correct if it is within a specified numerical tolerance of the expected answer.</p> <p>The answer is correct if it is within a specified numerical tolerance of the expected answer.</p>
<p>Enter the numerical value of Pi:</p> <p>Enter the numerical value of Pi:</p>
...@@ -356,7 +356,7 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -356,7 +356,7 @@ describe 'MarkdownEditingDescriptor', ->
When the student is ready, the explanation appears. When the student is ready, the explanation appears.
[Explanation] [Explanation]
""") """)
expect(data).toEqual(""" expect(data).toXMLEqual("""
<problem> <problem>
<p>bleh</p> <p>bleh</p>
<multiplechoiceresponse> <multiplechoiceresponse>
...@@ -680,7 +680,7 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -680,7 +680,7 @@ describe 'MarkdownEditingDescriptor', ->
Code should be nicely monospaced. Code should be nicely monospaced.
[/code] [/code]
""") """)
expect(data).toEqual(""" expect(data).toXMLEqual("""
<problem> <problem>
<p>Not a header</p> <p>Not a header</p>
<h3 class="hd hd-2 problem-header">A header</h3> <h3 class="hd hd-2 problem-header">A header</h3>
......
...@@ -25,7 +25,7 @@ describe 'Markdown to xml extended hint dropdown', -> ...@@ -25,7 +25,7 @@ describe 'Markdown to xml extended hint dropdown', ->
]] ]]
""") """)
expect(data).toEqual(""" expect(data).toXMLEqual("""
<problem> <problem>
<p>Translation between Dropdown and ________ is straightforward.</p> <p>Translation between Dropdown and ________ is straightforward.</p>
<optionresponse> <optionresponse>
......
/* global CodeMirror, _, XModule, PrettyPrint */ /* global CodeMirror, _, XModule */
// no-useless-escape disabled because of warnings in regexp expressions within the // no-useless-escape disabled because of warnings in regexp expressions within the
// "toXML" code. When the "useless escapes" were removed, some of the unit tests // "toXML" code. When the "useless escapes" were removed, some of the unit tests
// failed, but only in Jenkins, indicating browser-specific behavior. // failed, but only in Jenkins, indicating browser-specific behavior.
...@@ -819,8 +819,8 @@ ...@@ -819,8 +819,8 @@
} }
// make all responsetypes descendants of a single problem element // make all responsetypes descendants of a single problem element
// safe-lint: disable=javascript-concat-html // safe-lint: disable=javascript-concat-html
finalXml = '<problem>' + responseTypesXML.join('\n\n') + finalDemandHints + '</problem>'; finalXml = '<problem>\n' + responseTypesXML.join('\n\n') + finalDemandHints + '\n</problem>';
return PrettyPrint.xml(finalXml); return finalXml;
}; };
return MarkdownEditingDescriptor; return MarkdownEditingDescriptor;
......
/**
* pretty-data - nodejs plugin to pretty-print or minify data in XML, JSON and CSS formats.
*
* Version - 0.40.0
* Copyright (c) 2012 Vadim Kiryukhin
* vkiryukhin @ gmail.com
* http://www.eslinstructor.net/pretty-data/
*
*
* Code extracted for xml formatting only
*/
/* eslint-disable */
(function (root, factory){
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], function (){
return (root.PrettyPrint = factory());
});
} else {
// Browser globals
root.PrettyPrint = factory();
}
}(this, function () {
function PrettyPrint(){
var maxdeep = 100, // nesting level
ix = 0;
this.shift = ['\n']; // array of shifts
this.step = ' '; // 2 spaces
// initialize array with shifts //
for (ix = 0; ix < maxdeep; ix++) {
this.shift.push(this.shift[ix] + this.step);
}
}
PrettyPrint.prototype.xml = function (text) {
var ar = text.replace(/>\s{0,}</g, "><")
.replace(/</g, "~::~<")
.replace(/xmlns\:/g, "~::~xmlns:")
.replace(/xmlns\=/g, "~::~xmlns=")
.split('~::~'),
len = ar.length,
inComment = false,
deep = 0,
str = '',
ix = 0;
for (ix = 0; ix < len; ix++) {
// start comment or <![CDATA[...]]> or <!DOCTYPE //
if (ar[ix].search(/<!/) > -1) {
str += this.shift[deep] + ar[ix];
inComment = true;
// end comment or <![CDATA[...]]> //
if (ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1 || ar[ix].search(/!DOCTYPE/) > -1) {
inComment = false;
}
} else
// end comment or <![CDATA[...]]> //
if (ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1) {
str += ar[ix];
inComment = false;
} else
// <elm></elm> //
if (/^<\w/.exec(ar[ix - 1]) && /^<\/\w/.exec(ar[ix]) &&
/^<[\w:\-\.\,]+/.exec(ar[ix - 1]) == /^<\/[\w:\-\.\,]+/.exec(ar[ix])[0].replace('/', '')) {
str += ar[ix];
if (!inComment) deep--;
} else
// <elm> //
if (ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) == -1 && ar[ix].search(/\/>/) == -1) {
str = !inComment ? str += this.shift[deep++] + ar[ix] : str += ar[ix];
} else
// <elm>...</elm> //
if (ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) > -1) {
str = !inComment ? str += this.shift[deep] + ar[ix] : str += ar[ix];
} else
// </elm> //
if (ar[ix].search(/<\//) > -1) {
str = !inComment ? str += this.shift[--deep] + ar[ix] : str += ar[ix];
} else
// <elm/> //
if (ar[ix].search(/\/>/) > -1) {
str = !inComment ? str += this.shift[deep] + ar[ix] : str += ar[ix];
} else
// <? xml ... ?> //
if (ar[ix].search(/<\?/) > -1) {
str += this.shift[deep] + ar[ix];
} else
// xmlns //
if (ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) {
str += this.shift[deep] + ar[ix];
}
else {
str += ar[ix];
}
}
return (str[0] == '\n') ? str.slice(1) : str;
};
return new PrettyPrint();
}));
describe('XML Formatting Lib', function() {
'use strict';
it('correctly format the xml', function() {
var rawXml = '<breakfast><food><name>Belgian Waffles</name><price>$5.95</price></food></breakfast>',
expectedXml = '<breakfast>\n <food>\n <name>Belgian Waffles</name>' +
'\n <price>$5.95</price>\n </food>\n</breakfast>';
expect(window.PrettyPrint.xml(rawXml)).toEqual(expectedXml);
});
it('correctly handles the whitespaces and newlines', function() {
var rawXml = '<breakfast> <food> <name>Belgian Waffles</name>' +
'\n\n\n<price>$5.95</price></food> </breakfast>',
expectedXml = '<breakfast>\n <food>\n <name>Belgian Waffles</name>' +
'\n <price>$5.95</price>\n </food>\n</breakfast>';
expect(window.PrettyPrint.xml(rawXml)).toEqual(expectedXml);
});
});
...@@ -28,7 +28,6 @@ var options = { ...@@ -28,7 +28,6 @@ var options = {
{pattern: 'js/vendor/URI.min.js', included: true}, {pattern: 'js/vendor/URI.min.js', included: true},
{pattern: 'js/test/add_ajax_prefix.js', included: true}, {pattern: 'js/test/add_ajax_prefix.js', included: true},
{pattern: 'js/test/i18n.js', included: true}, {pattern: 'js/test/i18n.js', included: true},
{pattern: 'js/lib/pretty-print.js', included: true},
{pattern: 'common/js/vendor/underscore.js', included: true}, {pattern: 'common/js/vendor/underscore.js', included: true},
{pattern: 'common/js/vendor/underscore.string.js', included: true}, {pattern: 'common/js/vendor/underscore.string.js', included: true},
......
...@@ -31,7 +31,7 @@ var options = { ...@@ -31,7 +31,7 @@ var options = {
{pattern: 'common/js/xblock/*.js', included: true}, {pattern: 'common/js/xblock/*.js', included: true},
{pattern: 'xmodule_js/common_static/js/src/logger.js', included: true}, {pattern: 'xmodule_js/common_static/js/src/logger.js', included: true},
{pattern: 'xmodule_js/common_static/js/test/i18n.js', included: true}, {pattern: 'xmodule_js/common_static/js/test/i18n.js', included: true},
{pattern: 'xmodule_js/common_static/js/vendor/codemirror-compressed.js', included: true}, {pattern: 'xmodule_js/common_static/js/vendor/CodeMirror/codemirror.js', included: true},
{pattern: 'xmodule_js/common_static/js/vendor/jquery.cookie.js', included: true}, {pattern: 'xmodule_js/common_static/js/vendor/jquery.cookie.js', included: true},
{pattern: 'xmodule_js/common_static/js/vendor/flot/jquery.flot.js', included: true}, {pattern: 'xmodule_js/common_static/js/vendor/flot/jquery.flot.js', included: true},
{pattern: 'xmodule_js/common_static/coffee/src/jquery.immediateDescendents.js', included: true}, {pattern: 'xmodule_js/common_static/coffee/src/jquery.immediateDescendents.js', included: true},
......
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