Commit a18a95f0 by Mike Chen

convert blank lines to <br>

parent e1288eba
start start
= sections:(StringResponse / NumericalResponse / MultipleChoice / Paragraph / Linebreak+)+ = sections:(StringResponse / NumericalResponse / MultipleChoice / Paragraph / PreservedLinebreaks)+
{
var hasKind = function(o) {
return o.hasOwnProperty('type');
}
return sections.filter(hasKind);
}
StudentProducedResponseIdentifier StudentProducedResponseIdentifier
= '=' = '='
...@@ -76,7 +70,7 @@ Paragraph ...@@ -76,7 +70,7 @@ Paragraph
Line Line
= text:Text terminator:Linebreak = text:Text terminator:Linebreak
{ {
return text + terminator; return text + '\n';
} }
Text Text
...@@ -88,6 +82,12 @@ Text ...@@ -88,6 +82,12 @@ Text
OptionalSpaces OptionalSpaces
= ' '* = ' '*
PreservedLinebreaks
= terminators:('\n')+
{
return {'type': 'linebreaks', 'count': terminators.length}
}
Linebreak Linebreak
= ('\n') = ('\n')
......
...@@ -24,6 +24,7 @@ class @CapaDescriptor ...@@ -24,6 +24,7 @@ class @CapaDescriptor
try try
source = @source_box.val() + "\n" source = @source_box.val() + "\n"
result = @parser.parse (source) result = @parser.parse (source)
console.log result
@outputXML(result) @outputXML(result)
@message_box.css {"display":"none"} @message_box.css {"display":"none"}
catch e catch e
...@@ -37,7 +38,8 @@ class @CapaDescriptor ...@@ -37,7 +38,8 @@ class @CapaDescriptor
dom2capa: (node) -> dom2capa: (node) ->
capa = new XMLSerializer().serializeToString(node) capa = new XMLSerializer().serializeToString(node)
capa = capa + "" capa = capa + ""
return capa.replace(/<startouttext>/g, '<startouttext />').replace(/<\/startouttext>/g, '<endouttext />') return capa.replace(/<startouttext>/g, '<startouttext />')
.replace(/<\/startouttext>/g, '<endouttext />')
buildXML: (parsed) -> buildXML: (parsed) ->
dom_parser = new DOMParser() dom_parser = new DOMParser()
...@@ -54,6 +56,13 @@ class @CapaDescriptor ...@@ -54,6 +56,13 @@ class @CapaDescriptor
newel = create_text_element(section.text) newel = create_text_element(section.text)
problem.append(newel) problem.append(newel)
else if section.type == 'linebreaks'
text = create_text_element('')
for i in [0..section.count] by 1
br = doc.createElement('br')
text.append(br)
problem.append(text)
else if section.type == 'multiple_choice' else if section.type == 'multiple_choice'
newel = $(doc.createElement('choiceresponse')) newel = $(doc.createElement('choiceresponse'))
......
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