""" Utilities for dealing with Javascript and JSON. """ import json from django.template.defaultfilters import escapejs from mako.filters import decode from xmodule.modulestore import EdxJSONEncoder def _escape_json_for_html(json_string): """ Escape JSON that is safe to be embedded in HTML. This implementation is based on escaping performed in simplejson.JSONEncoderForHTML. Arguments: json_string (string): The JSON string to be escaped Returns: (string) Escaped JSON that is safe to be embedded in HTML. """ json_string = json_string.replace("&", "\\u0026") json_string = json_string.replace(">", "\\u003e") json_string = json_string.replace("<", "\\u003c") return json_string def escape_json_dumps(obj, cls=EdxJSONEncoder): """ JSON dumps and escapes JSON that is safe to be embedded in HTML. Usage: Can be used inside a Mako template inside a