Get HTML of selected link in Mac OS X

I am writing a Service that will be associated with my application. The user should be able to right-click the link in Safari (or another web browser) and call my service and process the link (and not just the text that will be selected when the user right-clicks).

The only thing I can not do is get the URL that the link points to. The service method gives you a NSPasteboardread, which we will call pboard.

The obvious thing to try to get the selected HTML will be [pboard stringForType:NSPasteboardTypeHTML], but it returned zero. So I called [pboard types]and it returned "public.utf8-plain-text" and NSStringPboardType. Thus, it looks like this cardboard only supports lines with plain text.

I tried to call [pboard addTypes:types owner:self](where types is an array containing NSPasteboardTypeHTMLnil), but that didn't matter when I called stringForType:.

Is there any way to extract HTML from cardboard when it [pboard types]returns only simple string types? Can I control what gets on the cardboard and / or what is read from it when the service is called?

+3
source share

Source: https://habr.com/ru/post/1789462/