avoid pretty printing of pre tags in course import
This commit is contained in:
committed by
saadyousafarbi
parent
605d4a35df
commit
e306bc74c0
@@ -1,6 +1,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
from lxml import etree
|
||||
from xblock.fields import Scope, String
|
||||
@@ -11,6 +12,8 @@ from .exceptions import SerializationError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
PRE_TAG_REGEX = re.compile(r'<pre>[\s\S]*?</pre>')
|
||||
|
||||
|
||||
class RawMixin(object):
|
||||
"""
|
||||
@@ -22,7 +25,12 @@ class RawMixin(object):
|
||||
|
||||
@classmethod
|
||||
def definition_from_xml(cls, xml_object, system):
|
||||
return {'data': etree.tostring(xml_object, pretty_print=True, encoding='unicode')}, []
|
||||
pre_tag_data = [etree.tostring(pre_tag_info) for pre_tag_info in xml_object.findall('pre')]
|
||||
data = etree.tostring(xml_object, pretty_print=True, encoding='unicode')
|
||||
if pre_tag_data:
|
||||
for index, pre_tag in enumerate(re.findall(PRE_TAG_REGEX, data)):
|
||||
data = re.sub(re.escape(pre_tag), pre_tag_data[index].decode(), data)
|
||||
return {'data': data}, []
|
||||
|
||||
def definition_to_xml(self, resource_fs):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user