Code

Opened 7 years ago

Closed 7 years ago

#4881 closed (fixed)

strange behaviour of rst from django.contrib.markup

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

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 7 years ago.
rst_django_bug.2.diff (1.0 KB) - added by Rafael Weber 7 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 follow-up: Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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

Changed 7 years ago by Rafael Weber

comment:2 in reply to: ↑ 1 ; follow-up: Changed 7 years ago by anonymous

  • Has patch set
  • Resolution invalid deleted
  • Status changed from closed to reopened

I patched it. Just use publish_string instead of publish_parts.

Cheers,

Rafael Weber

Changed 7 years ago by Rafael Weber

comment:3 in reply to: ↑ 2 Changed 7 years ago by anonymous

  • Resolution set to fixed
  • Status changed from reopened to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.