Opened 16 years ago
Closed 11 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)
Change History (22)
Changed 16 years ago by
comment:1 Changed 16 years ago by
Cc: | girzel@… added |
---|
comment:2 Changed 16 years ago by
Triage Stage: | Unreviewed → Someday/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 16 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Django's Markdown filter already allows you to use any Markdown extensions you have installed, including safe mode.
comment:4 Changed 15 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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 15 years ago by
Attachment: | 6526-mardown-html-removed-text.diff added |
---|
Adding settings to customize markdown remove text
Changed 15 years ago by
Attachment: | 6526-mardown-with-options-for-safe-mode.diff added |
---|
Markdown filter accepting options for safe_mode
Changed 15 years ago by
Attachment: | 6526-markdown-with-options-for-safe-mode.diff added |
---|
comment:5 Changed 15 years ago by
Fixed a typo: line 65 should be a comparison (==) not assignment (=)...
comment:6 Changed 13 years ago by
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 follow-up: 16 Changed 13 years ago by
milestone: | → 1.4 |
---|---|
Needs documentation: | set |
Needs tests: | set |
Patch needs improvement: | set |
Triage Stage: | Someday/Maybe → Accepted |
- The patch needs unittests to show that it works correctly.
- 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 :) - 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 13 years ago by
Component: | Contrib apps → contrib.markup |
---|
comment:9 Changed 13 years ago by
Type: | → New feature |
---|
comment:10 Changed 13 years ago by
Cc: | d1b added |
---|---|
Severity: | → Normal |
comment:13 Changed 11 years ago by
Owner: | changed from nobody to thomaspurchas |
---|---|
Status: | reopened → new |
comment:14 Changed 11 years ago by
Status: | new → assigned |
---|
comment:15 Changed 11 years ago by
Cc: | thomaspurchas added |
---|
comment:16 Changed 11 years ago by
Replying to lrekucki:
- The patch needs unittests to show that it works correctly.
- 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 :)- 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 11 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
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.
new version of the markup filter