Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:14:55+00:00 2026-05-23T23:14:55+00:00

I am building a blog on Google App Engine. I would like to convert

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:14:56+00:00Added an answer on May 23, 2026 at 11:14 pm

    This is roughly what you could do using Beautifulsoup:

    from BeautifulSoup import BeautifulSoup
    
    html_body ="""
    Here is an example link:<a href='http://example.com'>example.com</a>
    """
    soup = BeautifulSoup(html_body)
    for link_tag in soup.findAll('a'):
        link_tag.string = "%s%s%s" % ('|',link_tag.string,'|')
    for text in soup.findAll(text=True):
        text_formatted = ['<a href=""http://example.com"">example</a>'\ 
        if word == 'example' and not (word.startswith('|') and word.endswith('|'))\
        else word for word in foo.split() ]
        text.replaceWith(' '.join(text_formatted))
    for link_tag in soup.findAll('a'):
        link_tag.string = link_tag.string[1:-1]
    print soup
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In some of the previews, there was an HTML-helper method for building mailto-links. http://blog.wekeroad.com/2007/12/05/aspnet-mvc-preview-using-the-mvc-ui-helpers/
i am building a blog and would like to know good tools and plugins
I'm building a blog engine inside an MVC2 app. The URL for each post
I'm building a blog engine to test some concepts such us TDD and using
I'm trying to design a gmail like thread messaging system on Google App Engine
I'm building a blog that should parse bbcode tags like this: Input: <youtube=http://www.youtube.com/watch?v=VIDEO_ID&feature=channel> Output:
So I'm building a blog engine which has /articles/then-the-article-permalink as it's URL structure. I
I'm building a lifestream-esque sort of blog in PHP. It fetches my blog posts
I'm building off the CakePHP tutorial for the blog engine by adding comments to
SOLUTION FOUND: See comment Building a new rails 3.1 app. Started with a basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.