Opened 17 years ago

Closed 17 years ago

#4881 closed (fixed)

strange behaviour of rst from django.contrib.markup

Reported by: Rafael Weber Owned by: Adrian Holovaty
Component: Contrib apps Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hoi,

I'm using django svn at revision 5699 and docutils 0.4.

To use rst, i use the template tags from django.contrib.markup with the following code:

{% load markup %}
[...]
{{ flatpage.content|restructuredtext }}

If I write

aa
~~

in flatpage.content, the page has no content (rendered in the browser).

But if I write

asdfjslkdfjlk
lkdjfkl
sdjfsdfsdfjowier

sdfklj


aa
~~

it is rendered as normal <h1>. That's just one strange behaviour.

I already searched through the tickets and asked in the IRC - without any success.

Attachments (2)

rst_django_bug.diff (1.0 KB ) - added by Rafael Weber 17 years ago.
rst_django_bug.2.diff (1.0 KB ) - added by Rafael Weber 17 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by Malcolm Tredinnick, 17 years ago

Resolution: invalid
Status: newclosed

This is normal docutils behaviour. The first heading counts as the page title. See this django-users thread for more information.

by Rafael Weber, 17 years ago

Attachment: rst_django_bug.diff added

in reply to:  1 ; comment:2 by anonymous, 17 years ago

Has patch: set
Resolution: invalid
Status: closedreopened

I patched it. Just use publish_string instead of publish_parts.

Cheers,

Rafael Weber

by Rafael Weber, 17 years ago

Attachment: rst_django_bug.2.diff added

in reply to:  2 comment:3 by anonymous, 17 years ago

Resolution: fixed
Status: reopenedclosed

Hmm -- I uploaded the patch but the trac shows that the file is empty (not correct, the patch is in the file).

So, here is the patch:

Index: django/trunk/django/contrib/markup/templatetags/markup.py
===================================================================
@@ -42,18 +42,17 @@
 
 def restructuredtext(value):
     try:
-        from docutils.core import publish_parts
+        from docutils.core import publish_string
     except ImportError:
         if settings.DEBUG:
             raise template.TemplateSyntaxError, "Error in {% restructuredtext %} filter: The Python docutils library isn't installed."
         return force_unicode(value)
     else:
         docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
-        parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)
-        return force_unicode(parts["fragment"])
+        result = publish_string(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)
+        return force_unicode(result)
 
 register.filter(textile)
 register.filter(markdown)
 register.filter(restructuredtext)
 
-

Sorry for this two attachments but it didn't work though the patch was in the correct file.

Note: See TracTickets for help on using tickets.
Back to Top