From 14fdd274246e97de44e5b23778fd519540ffebfc 2013-12-16 23:58:53 From: MinRK Date: 2013-12-16 23:58:53 Subject: [PATCH] update patterns for strip_files filter - catch leading '/files' in href/src - support regular links as well as images in markdown --- diff --git a/IPython/nbconvert/filters/strings.py b/IPython/nbconvert/filters/strings.py index 397cd35..77253ca 100755 --- a/IPython/nbconvert/filters/strings.py +++ b/IPython/nbconvert/filters/strings.py @@ -122,8 +122,8 @@ def strip_dollars(text): return text.strip('$') -files_url_pattern = re.compile(r'(src|href)\=([\'"]?)files/') -markdown_url_pattern = re.compile(r'!\[(?P.*?)\]\(/?files/(?P.*?)\)') +files_url_pattern = re.compile(r'(src|href)\=([\'"]?)/?files/') +markdown_url_pattern = re.compile(r'(!?)\[(?P.*?)\]\(/?files/(?P.*?)\)') def strip_files_prefix(text): """ @@ -136,7 +136,7 @@ def strip_files_prefix(text): Text in which to replace 'src="files/real...' with 'src="real...' """ cleaned_text = files_url_pattern.sub(r"\1=\2", text) - cleaned_text = markdown_url_pattern.sub(r'![\1](\2)', cleaned_text) + cleaned_text = markdown_url_pattern.sub(r'\1[\2](\3)', cleaned_text) return cleaned_text