At the moment, it is only possible to replace the link in the href attribute, and not the link text. This is mostly due to the simpler implementation (we can just make use of lxml.html.rewrite_links() instead of some complex regex) and the fact that the URL is identical for all replaced link objects, but the link texts might differ.
Proposed Solution
At least in the case where all link texts are identical, I suggest to go the extra mile and allow the users to replace the link text as well. This would be a little bit more complicated, but can probably also be done with lxml (e.g. iterlinks()), so hopefully no regex matching.
Optionally, we could also think about allowing to "override" the link text even if it differs in the other sources.
Alternatives
Leave it up to the content creators to go through all affected pages and replace the link texts manually. However, since only the first link text is shown in the link checker, it's practically impossible to find the other occurrences of the link.
Probably we could have to at least provide a simpler method of finding all occurrences of a specific link.
User Story
As a region manager or editor, I want to replace not only the links but also the link texts (in case they are URLs) to make sure that the app users see the correct link text for the new link target.
As mentioned in #2307, making the link text editable via the form field led to several problems.
Thus, I suggest to choose a more black-box feature instead:
Try to determine whether the link text should be replaced as well
Automatically replace the link text if it's identical or similar to the URL (e.g. mailto:, tel: links or shortened URL domains etc)
Optionally show a warning if the "magic" method detects an inconsistency between URL and link text that it cannot fix automatically
Motivation
In many cases, links are not only contained in the
href
attribute of the specific link:But also in the link text itself:
At the moment, it is only possible to replace the link in the
href
attribute, and not the link text. This is mostly due to the simpler implementation (we can just make use oflxml.html.rewrite_links()
instead of some complex regex) and the fact that the URL is identical for all replaced link objects, but the link texts might differ.Proposed Solution
At least in the case where all link texts are identical, I suggest to go the extra mile and allow the users to replace the link text as well. This would be a little bit more complicated, but can probably also be done with lxml (e.g.
iterlinks()
), so hopefully no regex matching.Optionally, we could also think about allowing to "override" the link text even if it differs in the other sources.
Alternatives
Leave it up to the content creators to go through all affected pages and replace the link texts manually. However, since only the first link text is shown in the link checker, it's practically impossible to find the other occurrences of the link. Probably we could have to at least provide a simpler method of finding all occurrences of a specific link.
User Story
As a region manager or editor, I want to replace not only the links but also the link texts (in case they are URLs) to make sure that the app users see the correct link text for the new link target.
Additional Context