Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hyper link within a string of text #168

Closed
phisanti opened this issue Feb 23, 2023 · 0 comments
Closed

Add hyper link within a string of text #168

phisanti opened this issue Feb 23, 2023 · 0 comments

Comments

@phisanti
Copy link

I'm trying to use the dominate python library to create hyperlinks in a text string, but I'm running into an issue where only the first word containing the "@" symbol is being hyperlinked, but then, the rest of the paragraph is omitted.

Here's an example of the function I'm using:

from dominate.tags import p, a
import dominate

def add_hyperlinks(text):
    sentences = text.split('.')
    result = []
    for sentence in sentences:
        words = sentence.split()
        sentence_result = []
        for word in words:
            if "@" in word:
                hyperlink = a(word.replace('@', ''), href='http://www.test.com')
                sentence_result.append(hyperlink)
            else:
                sentence_result.append(word)
            sentence_result.append(' ')
        result.append(p()[:sentence_result])
    return result

strings = ['Here is a citation to Mr @someone who is a very smart person.', 
           'I am tryin to do something very difficul with the help of @mrai, I hope that I can make it better than @you, what you think.']

doc = dominate.document(title='Tweeter Report')
with doc.body:
    for string in strings:
        html = add_hyperlinks(string)
        print(str(html))
Repository owner locked and limited conversation to collaborators Mar 3, 2023
@Knio Knio converted this issue into discussion #169 Mar 3, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant