Opened 16 years ago

Closed 12 years ago

#6526 closed New feature (wontfix)

Add remove/escape/replace functions to markdown filter

Reported by: Eric Abrahamsen Owned by: thomaspurchas
Component: contrib.markup Version: dev
Severity: Normal Keywords: markup markdown
Cc: girzel@…, d1b, thomaspurchas Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Markdown.py supports a variety of safe_modes, allowing users to replace HTML, escape it, or remove it cleanly. Django's markdown template filter currently doesn't support anything but replacement with a string. This patch to the markdown() function in django.contrib.markup.templatetags provides that ability, allowing users to pass "safe","remove","escape" or "replace" as the first argument in the extension list. Backwards compatibility is maintained.

Improvements to the patch are welcome...

Attachments (5)

markup.py (3.4 KB ) - added by Eric Abrahamsen 16 years ago.
new version of the markup filter
6526-mardown-html-removed-text.diff (660 bytes ) - added by Timothée Peignier <tim@…> 16 years ago.
Adding settings to customize markdown remove text
6526-mardown-with-options-for-safe-mode.diff (947 bytes ) - added by Timothée Peignier <tim@…> 16 years ago.
Markdown filter accepting options for safe_mode
6526-markdown-with-options-for-safe-mode.diff (948 bytes ) - added by girzel@… 15 years ago.
6526-markdown-with-safe-options.diff (4.9 KB ) - added by thomaspurchas 12 years ago.
Also includes tests

Download all attachments as: .zip

Change History (22)

by Eric Abrahamsen, 16 years ago

Attachment: markup.py added

new version of the markup filter

comment:1 by Eric Abrahamsen, 16 years ago

Cc: girzel@… added

comment:2 by Thomas Güttler, 16 years ago

Triage Stage: UnreviewedSomeday/Maybe

I think this is a good snippet. But it is not important to have it in the django source. (my opinion)

comment:3 by James Bennett, 16 years ago

Resolution: invalid
Status: newclosed

Django's Markdown filter already allows you to use any Markdown extensions you have installed, including safe mode.

comment:4 by Timothée Peignier <tim@…>, 16 years ago

Resolution: invalid
Status: closedreopened

In fact, we can use extensions but not passing options to safe_mode extension which are : 'remove', 'escape', 'replace' (see http://www.freewisdom.org/projects/python-markdown/Using_as_a_Module).

At least, it could be great to be able to change markdown.HTML_REMOVED_TEXT cleanup within Django settings.

by Timothée Peignier <tim@…>, 16 years ago

Adding settings to customize markdown remove text

by Timothée Peignier <tim@…>, 16 years ago

Markdown filter accepting options for safe_mode

comment:5 by girzel@…, 15 years ago

Fixed a typo: line 65 should be a comparison (==) not assignment (=)...

comment:6 by Dana Woodman <dana@…>, 13 years ago

This ticket has been sitting around for 2 years. Any chance we can see it implemented?

It is a simple, straightforward fix that works and does not cause any backward-incompatible changes. It enables the use of Markdown's VERY useful HTML replacing, which many (including me) need in our projects.

Is there a reason it hasn't been implemented? If not, when could we expect it integrated?

Who can I bribe with a beer to get this thing put into core?

comment:7 by Łukasz Rekucki, 13 years ago

milestone: 1.4
Needs documentation: set
Needs tests: set
Patch needs improvement: set
Triage Stage: Someday/MaybeAccepted
  1. The patch needs unittests to show that it works correctly.
  2. It needs documentation. Current docs for markup are not very user friendly, but at least the doc string gives you some clue how to use it. Updating the docstring is a minimum. Write proper docs for those template tags for bonus points :)
  3. It needs some more work. My biggest annoyance is markdown.HTML_REMOVED_TEXT - I could live with it's content if it was translatable, but changing it to something more human-friendly is desirable. Also, while there probably are no extensions called "remove", "escape" and "replace" the names are a bit confusing. I propose using something like {{ text|markdown:"safe=replace,more_extensions" }} instead.

comment:8 by Gabriel Hurley, 13 years ago

Component: Contrib appscontrib.markup

comment:9 by Julien Phalip, 13 years ago

Type: New feature

comment:10 by d1b, 13 years ago

Cc: d1b added
Severity: Normal

comment:11 by Jacob, 12 years ago

milestone: 1.4

Milestone 1.4 deleted

comment:12 by anonymous, 12 years ago

Easy pickings: unset
UI/UX: unset

+1!

comment:13 by thomaspurchas, 12 years ago

Owner: changed from nobody to thomaspurchas
Status: reopenednew

comment:14 by thomaspurchas, 12 years ago

Status: newassigned

comment:15 by thomaspurchas, 12 years ago

Cc: thomaspurchas added

by thomaspurchas, 12 years ago

Also includes tests

in reply to:  7 comment:16 by thomaspurchas, 12 years ago

Replying to lrekucki:

  1. The patch needs unittests to show that it works correctly.
  2. It needs documentation. Current docs for markup are not very user friendly, but at least the doc string gives you some clue how to use it. Updating the docstring is a minimum. Write proper docs for those template tags for bonus points :)
  3. It needs some more work. My biggest annoyance is markdown.HTML_REMOVED_TEXT - I could live with it's content if it was translatable, but changing it to something more human-friendly is desirable. Also, while there probably are no extensions called "remove", "escape" and "replace" the names are a bit confusing. I propose using something like {{ text|markdown:"safe=replace,more_extensions" }} instead.

lrekucki I have implemented the safe mode setting using {{ text|markdown:"safe=replace,more_extensions" }} as you suggested, the attached patch also includes some new tests as well.

Also if you can still remember could you clarify what you mean by:

My biggest annoyance is markdown.HTML_REMOVED_TEXT - I could live with it's content if it was translatable, but changing it to something more human-friendly is desirable.

comment:17 by Claude Paroz, 12 years ago

Resolution: wontfix
Status: assignedclosed

contrib.markup has been deprecated (#18504) and will be removed in Django 1.6. We won't add any new feature to it, and we encourage users to create external apps or contribute to an existing one. Closing as obsolete.

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