Opened 9 years ago

Closed 4 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: master
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 9 years ago.
new version of the markup filter
6526-mardown-html-removed-text.diff (660 bytes) - added by Timothée Peignier <tim@…> 8 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@…> 8 years ago.
Markdown filter accepting options for safe_mode
6526-markdown-with-options-for-safe-mode.diff (948 bytes) - added by girzel@… 8 years ago.
6526-markdown-with-safe-options.diff (4.9 KB) - added by thomaspurchas 4 years ago.
Also includes tests

Download all attachments as: .zip

Change History (22)

Changed 9 years ago by Eric Abrahamsen

Attachment: markup.py added

new version of the markup filter

comment:1 Changed 9 years ago by Eric Abrahamsen

Cc: girzel@… added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 9 years ago by Thomas Güttler

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 Changed 9 years ago by James Bennett

Resolution: invalid
Status: newclosed

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

comment:4 Changed 8 years ago by Timothée Peignier <tim@…>

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.

Changed 8 years ago by Timothée Peignier <tim@…>

Adding settings to customize markdown remove text

Changed 8 years ago by Timothée Peignier <tim@…>

Markdown filter accepting options for safe_mode

Changed 8 years ago by girzel@…

comment:5 Changed 8 years ago by girzel@…

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

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

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 Changed 6 years ago by Łukasz Rekucki

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 Changed 6 years ago by Gabriel Hurley

Component: Contrib appscontrib.markup

comment:9 Changed 5 years ago by Julien Phalip

Type: New feature

comment:10 Changed 5 years ago by d1b

Cc: d1b added
Severity: Normal

comment:11 Changed 5 years ago by Jacob

milestone: 1.4

Milestone 1.4 deleted

comment:12 Changed 5 years ago by anonymous

Easy pickings: unset
UI/UX: unset

+1!

comment:13 Changed 4 years ago by thomaspurchas

Owner: changed from nobody to thomaspurchas
Status: reopenednew

comment:14 Changed 4 years ago by thomaspurchas

Status: newassigned

comment:15 Changed 4 years ago by thomaspurchas

Cc: thomaspurchas added

Changed 4 years ago by thomaspurchas

Also includes tests

comment:16 in reply to:  7 Changed 4 years ago by thomaspurchas

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 Changed 4 years ago by Claude Paroz

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