diff --git a/CHANGELOG.rst b/CHANGELOG.rst index dfd43ab53a3..49c648d7d0d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -18,6 +18,9 @@ Changes and deprecations https://github.com/ckan/ckanext-dcat#rdf-dcat-endpoints +* The library used to render markdown has been changed to python-markdown. This + introduces both ``python-markdown`` and ``bleach`` as dependencies, as ``bleach`` + is used to clean any HTML provided to the markdown processor. v2.4.1 2015-09-02 ================= @@ -113,8 +116,8 @@ Changes and deprecations Custom templates or users of this API call will need to pass ``include_datasets=True`` to include datasets in the response. -* The ``vocabulary_show`` and ``tag_show`` API calls no longer returns the - ``packages`` key - i.e. datasets that use the vocabulary or tag. +* The ``vocabulary_show`` and ``tag_show`` API calls no longer returns the + ``packages`` key - i.e. datasets that use the vocabulary or tag. However ``tag_show`` now has an ``include_datasets`` option. (#1886) * Config option ``site_url`` is now required - CKAN will not abort during diff --git a/ckan/lib/helpers.py b/ckan/lib/helpers.py index e914778d513..bb6aef68fe1 100644 --- a/ckan/lib/helpers.py +++ b/ckan/lib/helpers.py @@ -23,10 +23,11 @@ from webhelpers.html import escape, HTML, literal, url_escape from webhelpers.html.tools import mail_to from webhelpers.html.tags import * -from webhelpers.markdown import markdown from webhelpers import paginate from webhelpers.text import truncate import webhelpers.date as date +from markdown import markdown +from bleach import clean as clean_html from pylons import url as _pylons_default_url from pylons.decorators.cache import beaker_cache from pylons import config @@ -1723,10 +1724,10 @@ def render_markdown(data, auto_link=True, allow_html=False): if not data: return '' if allow_html: - data = markdown(data.strip(), safe_mode=False) + data = markdown(data.strip()) else: data = RE_MD_HTML_TAGS.sub('', data.strip()) - data = markdown(data, safe_mode=True) + data = markdown(clean_html(data, strip=True)) # tags can be added by tag:... or tag:"...." and a link will be made # from it if auto_link: diff --git a/ckan/tests/legacy/misc/test_format_text.py b/ckan/tests/legacy/misc/test_format_text.py index 9590e3b01be..a1495b8bee1 100644 --- a/ckan/tests/legacy/misc/test_format_text.py +++ b/ckan/tests/legacy/misc/test_format_text.py @@ -10,12 +10,10 @@ def test_markdown(self): *Some italicized text.* ''' exp = '''

Hello World

-

Some bolded text. -

-

Some italicized text. -

''' +

Some bolded text.

+

Some italicized text.

''' out = h.render_markdown(instr) - assert out == exp + assert out == exp, out def test_markdown_blank(self): instr = None @@ -24,13 +22,13 @@ def test_markdown_blank(self): def test_evil_markdown(self): instr = 'Evil