Задать вопрос

Тел: +7 965 3737 888

464

Просмотров

3

Ответов

typygmentdown

<p>Based heavily on <a href="https://djangosnippets.org/snippets/119/">snippet #119</a>, this is an all-in-one function which applies Markdown and typogrify, and adds Pygments highlighting (selected from a class name or by having Pygments guess the language) to any &lt;code&gt; elements found in the text.</p>
<p>It also adds some niceties for picking up useful arguments to Markdown and Pygments, and registers itself as a markup filter with the template_utils formatter.</p>
<p>Requirements:</p>
<ul><li><a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a></li>
<li><a href="http://pygments.org/">Pygments</a></li>
<li><a href="http://www.freewisdom.org/projects/python-markdown/">python-markdown</a></li>
<li><a href="http://code.google.com/p/django-template-utils/">template_utils</a></li>
<li><a href="http://code.google.com/p/typogrify/">typogrify</a></li>
</ul>

Вопрос полезен? Да0/Нет0
file_3272.py(3.6Кб)
None

Ответы (3):

Ответpanosl:19.01.2010
Ответ полезен? Да0/Нет0

On line 64, you might wanna chage str(soup) to unicode(soup), else if the content you're passing contains characters outside of ASCII, it throws an exception (ordinal not in range).

Ответubernostrum:22.08.2007
Ответ полезен? Да0/Нет0

OK, janky hack in place to remove extraneous p around div. I'll try to Soup this properly later.

Ответubernostrum:22.08.2007
Ответ полезен? Да0/Нет0

Hm.

Looks like the Pygments-highlighted div ends up inside a Markdown-generated p. Going to have to Soup that.