djangosnippets.org: Latest snippets tagged with 'beautifulsoup'https://djangosnippets.org/tags/beautifulsoup/2010-06-18T18:51:01-05:00urlize HTML2010-06-18T18:51:01-05:00maguspkhttps://djangosnippets.org/snippets/2072/<p>The default Django urlize filter does not work with html nicely so here I've used an HTML parser <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> to quickly search through each text node and run the django urlize filter on it. </p>
<p>Optimizations could be made to include a regex in the soup.findAll() method's text ...</p>
Freely redistributableCode syntax highlighting templatetag2007-09-15T14:42:55-05:00badrunnerhttps://djangosnippets.org/snippets/416/<p>Replaces &lt;code&gt; blocks with syntax highlighted code. Use CSS to actually get the colours you want, look at pygments documentation for extracting css for various styles.</p>
<p>This snippet has the advantage of falling back on &lt;pre&gt; if anything goes wrong, and attempting to guess the syntax of code, falling back ...</p>
Freely redistributableRevisiting Pygments and Markdown2007-08-08T08:29:59-05:00djypsyhttps://djangosnippets.org/snippets/360/<p>A variation on a theme, inspired by <a href="http://www.djangosnippets.org/snippets/39/">snippet 39</a> and <a href="http://www.djangosnippets.org/snippets/119/">snippet 119</a>. The
intent is to provide a more generic and simple mechanism for combining
<a href="http://www.freewisdom.org/projects/python-markdown/Installation">Markdown</a> with <a href="http://pygments.org/">Pygments</a>. Common scenarios could include blogging or commenting. Snippet 119 seemed too specific and perhaps not as
efficient, needing to process the HTML ...</p>
Freely redistributableFind all links in a value and display them separatley2007-02-27T21:49:17-06:00jcrofthttps://djangosnippets.org/snippets/45/<p>This is a simple filter I use to display a list of links from a blog entry off in the sidebar (<a href="http://www2.jeffcroft.com/blog/2007/feb/25/two-new-django-sites-both-source-available/">example</a>).</p>
<p>Requires beautifulsoup. Originally by <a href="http://playgroundblues.com">Nathan Borror</a>, tweaked slightly by me.</p>
Freely redistributableParsing and Highlighting &amp;lt;code&amp;gt; Blocks2007-02-27T17:48:26-06:00joshuahttps://djangosnippets.org/snippets/39/<p>This function takes a string (most likely from a template), searches it for <code>&lt;code&gt;[...]&lt;/code&gt;</code>, highlights it with Pygments, and returns the entire thing back, as a string. (Note: the <code>&lt;code&gt;[...]&lt;/code&gt;</code> must have a class corresponding to the language inside. If it lacks the class, then it's silently ...</p>
Freely redistributable