-
Notifications
You must be signed in to change notification settings - Fork 1.2k
add feature: Paragraph.add_hyperlink() #74 #162
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
Conversation
Hi @tanyunshi, I won't be able to commit this pull-request as is because it lacks tests and the API has not been vetted. But I thank you for it nonetheless and will keep it open for when we get back to hyperlinks. I'm sure it will be useful to folks in the meantime and we'll use it as a reference when we get to the implementation. If you're interested in pursuing a commit, the best place to start is with the feature analysis. That's where the discussion that resolves the API happens, and that determines the acceptance tests which in turn of course have a strong impact on the implementation. Let me know if you're interested, happy to help you along the way with any questions on how to get into it. |
Hihi @scanny, I am interested in pursuing commits. In fact I have added some feature analysis for hyperlink in dev\analysis\features. Could you please gives me some advices for the next step? |
Is there a plan to finish/merge this feature back to master? I am interested in inserting hyperlinks via python-docx. Btw, thanks you guys for all your work! |
Hi all, apologies, I seem to have lost track of this one for roughly a year somehow ⭕ We're definitely interested in pursuing this feature. @tanyunshi I'll take a look at your analysis page this evening. On first glance it looks quite good. I'll provide some feedback. Are you still interested in working on this? I know it's been some time :) |
Hi @scanny Glad that you are interested in this feature. ^^ Yes I think the hyperlink is an important feature and I will work on it. Shall we start with the analysis page? :) |
Yes, perfect. I'll take a look at it and provide comments, probably tomorrow, and we can go from there :) |
Hello @scanny, I have taken your advise and improved the feature analysis. Just a few remarks: As in the xml schema, a hyperlink may have multiple runs. In some use cases, we have different styles for the text in the same link(see my response above). I am not sure how much extra work it requires to implement this. However, if we make a bit more effects at the beginning, we have docx api more flexible(as it adapts the xml schema) and we have more possibilties for hyperlink stylings. You are right about the hyperlink access problem. I find I am not sure about the external/anchor link as it refers to a bookmark and so a bookmark should be implemented first. External links may be implemented later. |
@tanyunshi -- Just wanted to mention to procedure for updating pull requests. To make changes, you do not create a new pull request (most folks seem to do this the first time :). What you do is update the branch you created the pull request with and then push that up to GitHub. The pull request is automatically updated. That said, in this case, you'll need to create a new pull request because your pull is based on the master branch, and is also based on a different fork (robertdodd/python-docx). So you'll need to get your work into a new branch named 'feature/hyperlink' that's based on the 'feature/hyperlink' branch I've created on python-openxml. If you need help with the rebasing involved, let me know. There are other challenges with making updates to pull requests, but we can face those when we come to them. How familiar are you with git rebasing and with the GitHub pull process? I don't want to bore you with basics if you've already mastered them :) |
I can see your use case now. It's definitely legitimate, so we'll take a look and see how much work is involved. We'll need to look at the XML Schema for the hyperlink element and then should have an idea.
For the moment I'm thinking .iter_run_level_items() would generate items of three possible types: Run, Hyperlink, and RunLevelItem. The first two would be a run and a hyperlink respectively. The last one would be used for everything else and only give access to the element (probably as .element). As other run-level items were implemented, they could be added explicitly. I'm inclined to think that Run and Hyperlink should inherit from RunLevelItem, but we can get to that later.
I don't get what you're saying here. Can you elaborate? |
Good evening @scanny , A hyperlink may be an external link, such as url, or an anchor link, such as an bookmark. In the second cas, the link does not have an r:id attribute that refers to an element in relationship. However, the link has an attribute anchor, that refers to a name of a bookmark, and the bookmark can be found somewhere in the document. I don't think we have bookmark in python-docx. Therefore, I remove everything about anchor links in the analyses part and think about it later. :) |
I continued robertdodd's work to implement the p.add_hyperlink() method:
Documentations are also available for the dev part.