Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#6387 closed (fixed)

Markdown for Python v1.7 support needed in contrib.markup -- handling of unicode data changed

Reported by: Craig Ogg Owned by: Craig Ogg
Component: Contrib apps Version: dev
Severity: Keywords: unicode markdown
Cc: waylan@…, yatiohi@…, jerojasro@…, roderikk@…, django@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In v1.7rc1 Markdown moved to expecting unicode and always returning unicode. This causes the utf-8 encoding method that django.contrib.markup currently uses to generate incorrect encodings.

I am attaching a patch that changes the Markdown version and correctly passes unicode if the version is high enough.

Attachments (3)

markdown-1.7-support.diff (965 bytes ) - added by Craig Ogg 16 years ago.
Support for Markdown for Python v1.7rc1 and later
markdown-1.7-support2.diff (1.0 KB ) - added by jedie 16 years ago.
markdown-1.7-support2.2.diff (1.0 KB ) - added by Dmitri Fedortchenko <zeraien@…> 16 years ago.
Minor syntax error in previous patch, : missing from if statement. Corrected.

Download all attachments as: .zip

Change History (14)

comment:1 by Craig Ogg, 16 years ago

Owner: changed from nobody to Craig Ogg
Status: newassigned

Link to mailing list announcement that describes changes to markdown. Relevant bit:

Additionally, the `encoding` argument has been removed from both `markdown` and
`Markdown`. Markdown expects unicode (or ascii) input and it is the
users responsibility to ensure that's what is provided. Therefore, all
output is in unicode. Only `markdownFromFile` accepts an encoding.

by Craig Ogg, 16 years ago

Attachment: markdown-1.7-support.diff added

Support for Markdown for Python v1.7rc1 and later

comment:2 by Waylan Limberg, 16 years ago

Cc: waylan@… added

There is a duplicate of this at #6577 with some additional comments.

comment:3 by ctrochalakis, 16 years ago

Cc: yatiohi@… added

comment:4 by anonymous, 16 years ago

Cc: jerojasro@… added

comment:5 by anonymous, 16 years ago

Cc: roderikk@… added

The patch works fine. How can we get this implemented?

comment:6 by jedie, 16 years ago

Cc: django@… added

The patch didn't work for older version of markdown!
The version_info added in v1.6.2rc-2 previous versions has no version_info, see: http://python-markdown.svn.sourceforge.net/viewvc/python-markdown/markdown.py?r1=30&r2=31&pathrev=94

I will attached a new patch.

by jedie, 16 years ago

Attachment: markdown-1.7-support2.diff added

by Dmitri Fedortchenko <zeraien@…>, 16 years ago

Minor syntax error in previous patch, : missing from if statement. Corrected.

comment:7 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: assignedclosed

(In [7423]) Fixed #6387 -- Updated markdown filter to handle markdown-1.7 as well as
earlier versions. Patch from cogg, jedie and Dmitri Fedortchenko.

comment:8 by italomaia, 16 years ago

Needs tests: set
Patch needs improvement: set
Resolution: fixed
Status: closedreopened

This last change breaks markdown for me. Using ubuntu hardy, sqlite3 and python-markdown 1.6b1(repository).

return mark_safe(force_unicode(markdown.markdown(smart_str(value), extensions, safe_mode=safe_mode))) 

# unicode support only in markdown v1.7 or above. 
# version_info exist only in markdown v1.6.2rc-2 or above. 
if getattr(markdown, "version_info", None) < (1,7): 
    return mark_safe(force_unicode(markdown.markdown(smart_str(value), extensions, safe_mode=safe_mode))) 
else: 
    return mark_safe(markdown.markdown(force_unicode(value), extensions, safe_mode=safe_mode)) 

If i use

return mark_safe(markdown.markdown(force_unicode(value), extensions, safe_mode=safe_mode)) 

The error occors when i have a string with special characters on it, like ã or ç.

Without

if getattr(markdown, "version_info", None) < (1,7): 
    return mark_safe(force_unicode(markdown.markdown(smart_str(value), extensions, safe_mode=safe_mode))) 
else: 

it works great!

comment:9 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: reopenedclosed

@italomaia: Please open a new ticket with the details of your failure (including an example of how to repeat the problem -- it's a little hard to work out what you're doing in this comment).

The main issue in this ticket has been fixed and you're seeing something that's a bit different: possibly due to a specific version, possibly due to the input you're passing... at the moment, it's hard to tell. But it will just get confusing if we mix up that report with the original issue here.

In the new report, please include what version_info reports for you version of markdown. It's a little annoying to have to support a beta release when the final has been out for ages (and subsequent releases fixed some problems in b1 -- I know because I sent in the patches to markdown). I wish Ubuntu would stop shipping stuff like that, or at least upgrade when the real version comes out. But if there's a way of distinguishing the versions, we'll try to handle it.

comment:10 by Waylan Limberg, 16 years ago

@italomaia: It appears that the issue you are having is discussed in #5663. See my comment (9) on that ticket

comment:11 by italomaia, 16 years ago

Needs tests: unset
Patch needs improvement: unset

Thanks Wayla. That was pretty much what i meant. mtred, i'll send them a email asking for new markdown version. And, by the way, the patch in
ticket 5663 works for me(it was the same solution i did here, but, as it is there, is official! =D)
Sorry if i was not clear.

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