Opened 7 years ago

Closed 4 years ago

#9504 closed New feature (duplicate)

Extension for restructuredtext filter a django.contrib.markup

Reported by: jjconti Owned by: nobody
Component: contrib.markup Version: 1.0
Severity: Normal Keywords: markup restructuredtext
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As suggested at 0 I browserd markup sorce code1 to see how does restructuredtext filter work. I founded that it returns only the fragment part instead on other contet. I suggest an argument fot the filter to be used in parts[arg].

The suggested implementation is, as follow (two small changes):

def restructuredtext(value, arg="fragment"):
    try:
        from docutils.core import publish_parts
    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 mark_safe(force_unicode(parts[arg]))
restructuredtext.is_safe = True

[0] http://docs.djangoproject.com/en/dev/ref/contrib/#ref-contrib-markup

[1] http://code.djangoproject.com/browser/django/trunk/django/contrib/markup/templatetags/markup.py

Attachments (1)

9504.patch (892 bytes) - added by aaugustin 4 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 7 years ago by jjconti

  • Component changed from Uncategorized to Contrib apps
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 6 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:3 Changed 6 years ago by jacob

  • Triage Stage changed from Unreviewed to Design decision needed

comment:4 Changed 6 years ago by SmileyChris

See also: #11342

comment:5 Changed 4 years ago by gabrielhurley

  • Component changed from Contrib apps to contrib.markup

comment:6 Changed 4 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

Changed 4 years ago by aaugustin

comment:7 Changed 4 years ago by aaugustin

  • Easy pickings unset
  • Resolution set to duplicate
  • Status changed from new to closed
  • UI/UX unset

I just turned the snippet into a diff for ease of reviewing. This ticket conflicts with #11342 which has a much better explanation of the issue at hand. I'll close it as a duplicate of #11342 and leave a note over there.

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