From a32169518ac3d3b10f8667e6788aa079c50dccac 2014-02-22 07:38:13 From: MinRK Date: 2014-02-22 07:38:13 Subject: [PATCH] add ascii_only filter --- diff --git a/IPython/nbconvert/exporters/templateexporter.py b/IPython/nbconvert/exporters/templateexporter.py index 98d3772..dd6a7b7 100644 --- a/IPython/nbconvert/exporters/templateexporter.py +++ b/IPython/nbconvert/exporters/templateexporter.py @@ -62,6 +62,7 @@ default_filters = { 'citation2latex': filters.citation2latex, 'path2url': filters.path2url, 'add_prompts': filters.add_prompts, + 'ascii_only': filters.ascii_only, } #----------------------------------------------------------------------------- diff --git a/IPython/nbconvert/filters/strings.py b/IPython/nbconvert/filters/strings.py index 0558ec1..c0223a2 100755 --- a/IPython/nbconvert/filters/strings.py +++ b/IPython/nbconvert/filters/strings.py @@ -43,7 +43,8 @@ __all__ = [ 'ipython2python', 'posix_path', 'path2url', - 'add_prompts' + 'add_prompts', + 'ascii_only', ] @@ -213,3 +214,8 @@ def path2url(path): """Turn a file path into a URL""" parts = path.split(os.path.sep) return '/'.join(quote(part) for part in parts) + +def ascii_only(s): + """ensure a string is ascii""" + s = py3compat.cast_unicode(s) + return s.encode('ascii', 'replace').decode('ascii') \ No newline at end of file