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
35e7a733
Commit
35e7a733
authored
Aug 13, 2015
by
Marko Jevtic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addresses design review feedback
parent
67b64a80
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
4 deletions
+52
-4
common/lib/xmodule/xmodule/capa_module.py
+14
-2
common/lib/xmodule/xmodule/html_module.py
+13
-1
common/lib/xmodule/xmodule/tests/test_capa_module.py
+0
-0
common/lib/xmodule/xmodule/tests/test_html_module.py
+25
-1
No files found.
common/lib/xmodule/xmodule/capa_module.py
View file @
35e7a733
...
...
@@ -196,8 +196,20 @@ class CapaDescriptor(CapaFields, RawDescriptor):
Return dictionary prepared with module content and type for indexing.
"""
xblock_body
=
super
(
CapaDescriptor
,
self
)
.
index_dictionary
()
# Removing solution
capa_content
=
re
.
sub
(
re
.
compile
(
r"<solution>.*</solution>"
,
re
.
DOTALL
),
""
,
self
.
data
)
# Removing solutions and hints, as well as script and style
capa_content
=
re
.
sub
(
re
.
compile
(
r"""
<solution>.*?</solution> |
<script>.*?</script> |
<style>.*?</style> |
<[a-z]*hint.*?>.*?</[a-z]*hint>
"""
,
re
.
DOTALL
|
re
.
VERBOSE
),
""
,
self
.
data
)
# Removing HTML-encoded non-breaking space characters
capa_content
=
re
.
sub
(
r"(\s| |//)+"
,
" "
,
html_to_text
(
capa_content
))
# Removing HTML CDATA
...
...
common/lib/xmodule/xmodule/html_module.py
View file @
35e7a733
...
...
@@ -275,8 +275,20 @@ class HtmlDescriptor(HtmlFields, XmlDescriptor, EditingDescriptor): # pylint: d
def
index_dictionary
(
self
):
xblock_body
=
super
(
HtmlDescriptor
,
self
)
.
index_dictionary
()
# Removing script and style
html_content
=
re
.
sub
(
re
.
compile
(
r"""
<script>.*?</script> |
<style>.*?</style>
"""
,
re
.
DOTALL
|
re
.
VERBOSE
),
""
,
self
.
data
)
# Removing HTML-encoded non-breaking space characters
html_content
=
re
.
sub
(
r"(\s| |//)+"
,
" "
,
html_to_text
(
self
.
data
))
html_content
=
re
.
sub
(
r"(\s| |//)+"
,
" "
,
html_to_text
(
html_content
))
# Removing HTML CDATA
html_content
=
re
.
sub
(
r"<!\[CDATA\[.*\]\]>"
,
""
,
html_content
)
# Removing HTML comments
...
...
common/lib/xmodule/xmodule/tests/test_capa_module.py
View file @
35e7a733
This diff is collapsed.
Click to expand it.
common/lib/xmodule/xmodule/tests/test_html_module.py
View file @
35e7a733
...
...
@@ -59,7 +59,7 @@ class HtmlDescriptorIndexingTestCase(unittest.TestCase):
Make sure that HtmlDescriptor can format data for indexing as expected.
"""
def
test_index_dictionary
(
self
):
def
test_index_dictionary
_simple_html_module
(
self
):
sample_xml
=
'''
<html>
<p>Hello World!</p>
...
...
@@ -71,6 +71,7 @@ class HtmlDescriptorIndexingTestCase(unittest.TestCase):
"content_type"
:
"Text"
})
def
test_index_dictionary_cdata_html_module
(
self
):
sample_xml_cdata
=
'''
<html>
<p>This has CDATA in it.</p>
...
...
@@ -83,6 +84,7 @@ class HtmlDescriptorIndexingTestCase(unittest.TestCase):
"content_type"
:
"Text"
})
def
test_index_dictionary_multiple_spaces_html_module
(
self
):
sample_xml_tab_spaces
=
'''
<html>
<p> Text has spaces :) </p>
...
...
@@ -94,6 +96,7 @@ class HtmlDescriptorIndexingTestCase(unittest.TestCase):
"content_type"
:
"Text"
})
def
test_index_dictionary_html_module_with_comment
(
self
):
sample_xml_comment
=
'''
<html>
<p>This has HTML comment in it.</p>
...
...
@@ -106,6 +109,7 @@ class HtmlDescriptorIndexingTestCase(unittest.TestCase):
"content_type"
:
"Text"
})
def
test_index_dictionary_html_module_with_both_comments_and_cdata
(
self
):
sample_xml_mix_comment_cdata
=
'''
<html>
<!-- Beginning of the html -->
...
...
@@ -120,3 +124,23 @@ class HtmlDescriptorIndexingTestCase(unittest.TestCase):
"content"
:
{
"html_content"
:
" This has HTML comment in it. HTML end. "
,
"display_name"
:
"Text"
},
"content_type"
:
"Text"
})
def
test_index_dictionary_html_module_with_script_and_style_tags
(
self
):
sample_xml_style_script_tags
=
'''
<html>
<style>p {color: green;}</style>
<!-- Beginning of the html -->
<p>This has HTML comment in it.<!-- Commenting Content --></p>
<!-- Here comes CDATA -->
<![CDATA[This is just a CDATA!]]>
<p>HTML end.</p>
<script>
var message = "Hello world!"
</script>
</html>
'''
descriptor
=
instantiate_descriptor
(
data
=
sample_xml_style_script_tags
)
self
.
assertEqual
(
descriptor
.
index_dictionary
(),
{
"content"
:
{
"html_content"
:
" This has HTML comment in it. HTML end. "
,
"display_name"
:
"Text"
},
"content_type"
:
"Text"
})
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