diff --git a/combo/data/models.py b/combo/data/models.py index 692a1c6a..369d9df9 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -742,6 +742,18 @@ class TextCell(CellBase): d[0]['order'] = -1 return d + def get_cell_extra_context(self, context): + extra_context = super(TextCell, self).get_cell_extra_context(context) + extra_context['text'] = self.text + render_skeleton = context.get('render_skeleton') + if render_skeleton: + request = context.get('request') + def sub_src(match): + url = request.build_absolute_uri(match.group(1)) + return 'src="%s"' % url + extra_context['text'] = re.sub(r'src="(.*?)"', sub_src, self.text) + return extra_context + @register_cell_class class FortuneCell(CellBase): diff --git a/combo/public/templates/combo/text-cell.html b/combo/public/templates/combo/text-cell.html index f7cc9865..12fef1d6 100644 --- a/combo/public/templates/combo/text-cell.html +++ b/combo/public/templates/combo/text-cell.html @@ -1,3 +1,3 @@ {% block cell-content %} -{{cell.text|safe}} +{{text|safe}} {% endblock %} diff --git a/tests/test_public.py b/tests/test_public.py index fc9da15d..d1f31f9c 100644 --- a/tests/test_public.py +++ b/tests/test_public.py @@ -275,6 +275,15 @@ def test_page_skeleton(app): resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/')) assert 'http://testserver/plop' in resp.text + # check images in text cell use full URL + cell = TextCell(page=page, placeholder='footer', order=0) + cell.text = ' vs ' + cell.save() + resp = app.get('/__skeleton__/?source=%s' % quote('http://127.0.0.1:8999/')) + assert 'http://testserver/test/foobar.png' in resp.text + # check absolute URIs are not modified + assert 'src="http://www.example.com/test.png"' in resp.text + # add a bad redirection page (don't use it, do not crash) page = Page(title='BadRedirection', slug='badredir', template_name='standard', redirect_url='[foo_bar]')