Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
164d8a50
Commit
164d8a50
authored
Jan 05, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move toXML code into edit.coffee, create unit test scaffolding.
parent
96bad913
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
2 deletions
+113
-2
common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee
+6
-0
common/lib/xmodule/xmodule/js/src/problem/edit.coffee
+107
-2
No files found.
common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee
0 → 100644
View file @
164d8a50
describe
'MarkdownEditingDescriptor'
,
->
describe
'markdownToXml'
,
->
it
'converts raw text to paragraph'
,
->
data
=
MarkdownEditingDescriptor
.
markdownToXml
(
'foo'
)
expect
(
data
).
toEqual
(
'<p>foo</p>'
)
\ No newline at end of file
common/lib/xmodule/xmodule/js/src/problem/edit.coffee
View file @
164d8a50
...
...
@@ -17,7 +17,7 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
})
@
setCurrentEditor
(
@
markdown_editor
)
onMarkdownEditorUpdate
:
->
onMarkdownEditorUpdate
:
->
console
.
log
(
'update'
)
@
updateXML
()
...
...
@@ -32,7 +32,7 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
# onMarkdownEditorUpdate();
else
@
setCurrentEditor
(
@
xml_editor
)
# xmlEditor.refresh();
# xmlEditor.refresh();
setCurrentEditor
:
(
editor
)
->
$
(
@
current_editor
.
getWrapperElement
()).
hide
()
...
...
@@ -43,3 +43,108 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
save
:
->
$body
.
off
(
'click'
,
'.editor-tabs .tab'
,
@
changeEditor
)
data
:
@
xml_editor
.
getValue
()
@
markdownToXml
:
(
markdown
)
->
toXml
=
`
function
(
markdown
)
{
var
xml
=
markdown
;
//
replace
headers
xml
=
xml
.
replace
(
/(^.*?$)(?=\n\=\=+$)/gm
,
'<h1>$1</h1>'
);
xml
=
xml
.
replace
(
/\n^\=\=+$/gm
,
''
);
//
group
multiple
choice
answers
xml
=
xml
.
replace
(
/(^\s*\(.?\).*?$\n*)+/gm
,
function
(
match
,
p
)
{
var
groupString
=
'<multiplechoiceresponse>
\n
'
;
groupString
+=
' <choicegroup type="MultipleChoice">
\n
'
;
var
options
=
match
.
split
(
'
\n
'
);
for
(
var
i
=
0
;
i
<
options
.
length
;
i
++
)
{
if
(
options
[
i
].
length
>
0
)
{
var
value
=
options
[
i
].
split
(
/^\s*\(.?\)\s*/
)[
1
];
var
correct
=
/^\s*\(x\)/i
.
test
(
options
[
i
]);
groupString
+=
' <choice correct="'
+
correct
+
'">'
+
value
+
'</choice>
\n
'
;
}
}
groupString
+=
' </choicegroup>
\n
'
;
groupString
+=
'</multiplechoiceresponse>
\n\n
'
;
return
groupString
;
});
//
group
check
answers
xml
=
xml
.
replace
(
/(^\s*\[.?\].*?$\n*)+/gm
,
function
(
match
,
p
)
{
var
groupString
=
'<multiplechoiceresponse>
\n
'
;
groupString
+=
' <choicegroup type="MultipleChoiceChecks">
\n
'
;
var
options
=
match
.
split
(
'
\n
'
);
for
(
var
i
=
0
;
i
<
options
.
length
;
i
++
)
{
if
(
options
[
i
].
length
>
0
)
{
var
value
=
options
[
i
].
split
(
/^\s*\[.?\]\s*/
)[
1
];
var
correct
=
/^\s*\[x\]/i
.
test
(
options
[
i
]);
groupString
+=
' <choice correct="'
+
correct
+
'">'
+
value
+
'</choice>
\n
'
;
}
}
groupString
+=
' </choicegroup>
\n
'
;
groupString
+=
'</multiplechoiceresponse>
\n\n
'
;
return
groupString
;
});
//
replace
videos
xml
=
xml
.
replace
(
/\{\{video\s(.*?)\}\}/g
,
'<video youtube="1.0:$1" />
\n\n
'
);
//
replace
string
and
numerical
xml
=
xml
.
replace
(
/^\=\s*(.*?$)/gm
,
function
(
match
,
p
)
{
var
string
;
var
params
=
/(.*?)\+\-\s*(.*?)/
.
exec
(
p
);
if
(
parseFloat
(
p
))
{
if
(
params
)
{
string
=
'<numericalresponse answer="'
+
params
[
1
]
+
'">
\n
'
;
string
+=
' <responseparam type="tolerance" default="'
+
params
[
2
]
+
'" />
\n
'
;
}
else
{
string
=
'<numericalresponse answer="'
+
p
+
'">
\n
'
;
}
string
+=
' <textline />
\n
'
;
string
+=
'</numericalresponse>
\n\n
'
;
}
else
{
string
=
'<stringresponse answer="'
+
p
+
'" type="ci">
\n
<textline size="20"/>
\n
</stringresponse>
\n\n
'
;
}
return
string
;
});
//
replace
selects
xml
=
xml
.
replace
(
/\[\[(.+?)\]\]/g
,
function
(
match
,
p
)
{
var
selectString
=
'
\n
<optionresponse>
\n
'
;
selectString
+=
' <optioninput options="('
;
var
options
=
p
.
split
(
/\,\s*/g
);
for
(
var
i
=
0
;
i
<
options
.
length
;
i
++
)
{
selectString
+=
"'"
+
options
[
i
].
replace
(
/\((.*?)\)/g
,
'$1'
)
+
"'"
+
(
i
<
options
.
length
-
1
?
','
:
''
);
}
selectString
+=
')" correct="'
;
var
correct
=
/\((.*?)\)/g
.
exec
(
p
);
if
(
correct
)
selectString
+=
correct
[
1
];
selectString
+=
'"></optioninput>
\n
'
;
selectString
+=
'</optionresponse>
\n\n
'
;
return
selectString
;
});
//
split
scripts
and
wrap
paragraphs
var
splits
=
xml
.
split
(
/(\<\/?script.*?\>)/g
);
var
scriptFlag
=
false
;
for
(
var
i
=
0
;
i
<
splits
.
length
;
i
++
)
{
if
(
/\<script/
.
test
(
splits
[
i
]))
{
scriptFlag
=
true
;
}
if
(
!
scriptFlag
)
{
splits
[
i
]
=
splits
[
i
].
replace
(
/(^(?!\s*\<|$).*$)/gm
,
'<p>$1</p>'
);
}
if
(
/\<\/script/
.
test
(
splits
[
i
]))
{
scriptFlag
=
false
;
}
}
xml
=
splits
.
join
(
''
);
//
rid
white
space
xml
=
xml
.
replace
(
/\n\n\n/g
,
'
\n
'
);
return
xml
;
}
`
return
toXml
markdown
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment