I am building a blog on Google App Engine. I would like to convert some keywords in my blog posts to links, just like what you see in many WordPress blogs.
Here is one WP plugin which do the same thing:http://wordpress.org/extend/plugins/blog-mechanics-keyword-link-plugin-v01/
A plugin that allows you to define keyword/link pairs. The keywords are automatically linked in each of your posts.
I think this is more than a simple Python Replace. What I am dealing with is HTML code. It can be quite complex sometimes.
Take the following code snippet as an example. I want to conver the word example into a link to http://example.com:
Here is an example link:<a href="http://example.com">example.com</a>
By a simple Python replace function which replaces example with <a href="http://example.com">example</a>, it would output:
Here is an <a href="http://example.com">example</a> link:<a href="http://<a href="http://example.com">example</a>.com"><a href="http://example.com">example</a>.com</a>
but I want:
Here is an <a href="http://example.com">example</a> link:<a href="http://example.com">example.com</a>
Is there any Python plugin that capable of this? Thanks a lot!
This is roughly what you could do using Beautifulsoup:
Basically I’m stripping out all the text from the
post_body, replacing the example word with the given link, without touching the links text that are saved by the ‘|’ characters during the parsing.This is not 100% perfect, for example it does not work if the word you are trying to replace ends with a period; with some patience you could fix all the edge cases.