Commit 3a98ee58 by David Baumgold

Merge pull request #1295 from IainNZ/patch-1

Added a [code] block to the problem markdown parser
parents 1be7dbe3 a75b764c
...@@ -92,3 +92,4 @@ Felipe Montoya <felipe.montoya@edunext.co> ...@@ -92,3 +92,4 @@ Felipe Montoya <felipe.montoya@edunext.co>
Julia Hansbrough <julia@edx.org> Julia Hansbrough <julia@edx.org>
Pavel Yushchenko <pavelyushchenko@gmail.com> Pavel Yushchenko <pavelyushchenko@gmail.com>
Nicolas Chevalier <nicolas.chevalier@epitech.eu> Nicolas Chevalier <nicolas.chevalier@epitech.eu>
Iain Dunning <idunning@mit.edu>
...@@ -314,6 +314,10 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -314,6 +314,10 @@ describe 'MarkdownEditingDescriptor', ->
bad tests require drivel bad tests require drivel
</div> </div>
[code]
Code should be nicely monospaced.
[/code]
""") """)
expect(data).toEqual("""<problem> expect(data).toEqual("""<problem>
<p>Not a header</p> <p>Not a header</p>
...@@ -382,5 +386,9 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -382,5 +386,9 @@ describe 'MarkdownEditingDescriptor', ->
<p>bad tests require drivel</p> <p>bad tests require drivel</p>
</div> </div>
<pre><code>
Code should be nicely monospaced.
</code></pre>
</problem>""") </problem>""")
# failure tests # failure tests
...@@ -269,17 +269,23 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor ...@@ -269,17 +269,23 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
return selectString; return selectString;
}); });
// split scripts and wrap paragraphs // replace code blocks
var splits = xml.split(/(\<\/?script.*?\>)/g); xml = xml.replace(/\[code\]\n?([^\]]*)\[\/?code\]/gmi, function(match, p1) {
var selectString = '<pre><code>\n' + p1 + '</code></pre>';
return selectString;
});
// split scripts and preformatted sections, and wrap paragraphs
var splits = xml.split(/(\<\/?(?:script|pre).*?\>)/g);
var scriptFlag = false; var scriptFlag = false;
for(var i = 0; i < splits.length; i++) { for(var i = 0; i < splits.length; i++) {
if(/\<script/.test(splits[i])) { if(/\<(script|pre)/.test(splits[i])) {
scriptFlag = true; scriptFlag = true;
} }
if(!scriptFlag) { if(!scriptFlag) {
splits[i] = splits[i].replace(/(^(?!\s*\<|$).*$)/gm, '<p>$1</p>'); splits[i] = splits[i].replace(/(^(?!\s*\<|$).*$)/gm, '<p>$1</p>');
} }
if(/\<\/script/.test(splits[i])) { if(/\<\/(script|pre)/.test(splits[i])) {
scriptFlag = false; scriptFlag = false;
} }
} }
......
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