Пример #1
0
 def index_dictionary(self):
     """
     Return dictionary prepared with module content and type for indexing.
     """
     xblock_body = super(CapaDescriptor, self).index_dictionary()
     # 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
     )
     capa_content = escape_html_characters(capa_content)
     capa_body = {
         "capa_content": capa_content,
         "display_name": self.display_name,
     }
     if "content" in xblock_body:
         xblock_body["content"].update(capa_body)
     else:
         xblock_body["content"] = capa_body
     xblock_body["content_type"] = self.INDEX_CONTENT_TYPE
     xblock_body["problem_types"] = list(self.problem_types)
     return xblock_body
Пример #2
0
 def index_dictionary(self):
     """
     Return dictionary prepared with module content and type for indexing.
     """
     xblock_body = super(CapaDescriptor, self).index_dictionary()
     # 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)
     capa_content = escape_html_characters(capa_content)
     capa_body = {
         "capa_content": capa_content,
         "display_name": self.display_name,
     }
     if "content" in xblock_body:
         xblock_body["content"].update(capa_body)
     else:
         xblock_body["content"] = capa_body
     xblock_body["content_type"] = self.INDEX_CONTENT_TYPE
     xblock_body["problem_types"] = list(self.problem_types)
     return xblock_body
    def test_escape_html_comments(self):
        html_content = """
            <!--This is a comment. Comments are not displayed in the browser-->

            This is a paragraph.
            """
        assert escape_html_characters(html_content) == self.final_content
Пример #4
0
 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
     )
     html_content = escape_html_characters(html_content)
     html_body = {
         "html_content": html_content,
         "display_name": self.display_name,
     }
     if "content" in xblock_body:
         xblock_body["content"].update(html_body)
     else:
         xblock_body["content"] = html_body
     xblock_body["content_type"] = "Text"
     return xblock_body
    def test_escape_html_comments(self):
        html_content = """
            <!--This is a comment. Comments are not displayed in the browser-->

            This is a paragraph.
            """
        self.assertEqual(escape_html_characters(html_content), self.final_content)
    def test_escape_cdata_comments(self):
        html_content = """
            <![CDATA[
                function matchwo(a,b)
                {
                if (a < b && a < 0) then
                  {
                  return 1;
                  }
                else
                  {
                  return 0;
                  }
                }
            ]]>

            This is a paragraph.
            """
        assert escape_html_characters(html_content) == self.final_content
    def test_escape_cdata_comments(self):
        html_content = """
            <![CDATA[
                function matchwo(a,b)
                {
                if (a < b && a < 0) then
                  {
                  return 1;
                  }
                else
                  {
                  return 0;
                  }
                }
            ]]>

            This is a paragraph.
            """
        self.assertEqual(escape_html_characters(html_content), self.final_content)
 def test_escape_non_breaking_space(self):
     html_content = """
         &nbsp;&nbsp;
         &nbsp;
         <![CDATA[
             function matchwo(a,b)
             {
             if (a < b && a < 0) then
               {
               return 1;
               }
             else
               {
               return 0;
               }
             }
         ]]>
         This is a paragraph.&nbsp;
     """
     assert escape_html_characters(html_content) == self.final_content
 def test_escape_non_breaking_space(self):
     html_content = """
         &nbsp;&nbsp;
         &nbsp;
         <![CDATA[
             function matchwo(a,b)
             {
             if (a < b && a < 0) then
               {
               return 1;
               }
             else
               {
               return 0;
               }
             }
         ]]>
         This is a paragraph.&nbsp;
     """
     self.assertEqual(escape_html_characters(html_content), self.final_content)