Paste Without Formatting, But With Link

also you can always use Cmd-K

I should have clarified in my original email that the linked text I'm copying and pasting is not formatted like a URL, but rather as linked text. For example:

So with the above example, I'd like to:

  1. Copy "Google".
  2. Strip out all text styling, but not the associated link.
  3. Paste into an email with no associated typeface, but with the link.

Is that sort of thing possible? I recognize what I might be asking for is "plain text," but that "plain text" can't have an associated link by definition.

Nope, you can't do that because the hyperlink is actually formatted as Rich Text in apps like Mail. And, of course, Rich Text always has some style.
The best you can do is to change the style using the KM Apply Style to Clipboard action to get the style you want (to match what's in Mail).

You may be thinking of the HTML Anchor tag, which has no inheirent style unless set by CSS. Otherwise it generally takes on the font of the element where it is placed.

I have just tried out Hello's suggested solution and it seems to work perfectly for what you are after.

In my case my email default font is Helvetica 12pt. So, I set the action to format the clipboard that way and then paste (exactly like you have done).

The result is that a section of text copied from Safari pastes into Mail in Helvetica 12pt but keeps the link. The one thing I see I have done differently to you is check the boxes for "size" at 12pt and "foreground" as black.


Paste Without Formatting, But With Link.kmmacros (2.7 KB)

1 Like

Here the text from Safari pasted normally, without using the Macro:

And here using the Macro to paste:

1 Like

This is working for pasting from Safari into Mail, except for line-spacing: if the lines on a website have space between them, they'll be spaced out when pasted via this method. For example, this text from a forum post has spacing between the lines because of the margin styling (specifically, the margin-block-start and margin-block-end properties):

It looks like this when pasted into Mail with a macro that uses the "Apply Style to Clipboard" action, with the font set to 14 point Georgia:

And, in Mail, it is impossible to adjust line-spacing, so I'm stuck with it. You mention that Mail uses Rich Text for stying, and indeed, when I paste the above into TextEdit, the "Line and paragraph spacing" information looks like this:

Does anyone have an idea about how to address this? It would be great if the "Apply Style to Clipboard" action had options for line-spacing, but it doesn't seem to.

Hey Phil,

You realize @JMichaelTX will not be replying...

The Passing of JMichaelTX

JMichaelTX – Unforgettable Generosity With His Time and Knowledge


As for your problem – did you try removing styles from the clipboard?

image

See: Filter Action.

-Chris

1 Like

Oh…. I'm sorry to learn that!

Thank you for stepping in to help! The trouble is, if you remove styles, you also remove the hyperlink, and the goal is to remove all the styling except hyperlinks. Or, rather—since that doesn't seem possible—the goal is to re-style the text to otherwise match the default style for message composition in one's Mail app.

The Apply Style to Clipboard action suggested earlier in the thread would address my scenario if it enabled line-spacing to be specified, but it doesn't seem to.

Two things:

  1. Try Paste Matching Style from Mail's Edit menu.
     
  2. Convert the RTF on the Clipboard to HTML.
    • Edit the HTML.
    • Put the HTML back on the Clipboard as RTF.

Adjusting RTF on the clipboard is not exactly simple. Personally I have no idea of how tough it would be to regulate or remove paragraph spacing, but that said it's a feature I wouldn't mind having myself. I regularly encounter text in which I want to keep the style but need to squash unwanted paragraph spacing.

@peternlewis?

You can manage this now, but it's a bit convoluted.

Here's how you get HTML from the RTF on the Clipboard:

Convert RTF on the Clipboard to HTML v1.00.kmmacros (5.4 KB)

I'd have to see a sample of your problem text to have an idea of how to massage the HTML to fix it. Upload a zipped RTF file if you want help with that.

-Chris

No idea, sorry. “With Link” generally means it has to have formatting, so “Without Formatting, But With Link”, I don't know if that is possible.

You could try replacing spaces in a URL to its URL encoding %20

Would you be consider, in a future release, adding to the Apply Style to Clipboard action the ability to alter line-spacing and paragraph-spacing?

This would not meet the original request in the thread, but for quoting multiple lines from webpages in Mail messages—which is my use-case (and, it seems, that of a few others in this thread)—it would work fine. You'd just set up the Apply Style to Clipboard action to apply the default message-composition font, font-size, line-spacing, and paragraph-spacing.

I just came up with a wild and wacky (and different) way to solve your problem. Perhaps you won't be happy with my solution, but it's really different and merits a mention.

Most browsers have a status bar (which may not be on by default, so you may have to turn it on) that shows the URL of the link that your mouse is hovering over. The text in this URL is unformatted, which is what you are looking for. It should be easy for someone who knows JavaScript (which I don't) to fetch the contents of the status bar using JavaScript when you click a KM hotkey. There should be no formatting to this string so you can paste it (into the email you are composing, or any other app) without worrying about copying formatting! Bazinga!

I'd also like to see someone write a KM macro that runs in a loop asynchronously and constantly appends any string that pops up in the status bar to some KM variable. I doubt that there is a trigger for this, so it will probably have to use polling in a loop to accomplish this. It would not append the string if the string is already the last line in the variable.

Thanks!

Paste Matching Style doesn't do it, unfortunately. However, I have been messing around with the macro you kindly provided, and so far I can get the html as I want it by saving the results of the macro to the system clipboard and setting all "margin" properties to 0.0px:

I am making some other changes too, such as inserting blank lines between paragraphs:

(It may seem odd to remove top and bottom margins from paragraphs only to then space them out with blank lines, but since Mail doesn't allow control of line- and paragraph-spacing, this at least gives me something predictable.)

Anyhow, my question now is, how do I get the HTML that this creates into RTF?

That would for extracting a link from hypertext, but the challenge here is copying hypertext from a browser and then, when pasting (into Mail, for example), retaining the fact that the text has a link but otherwise adopting the styling of the surrounding text.

Oh. I thought they wanted the link, not the displayed text for the link. My bad. The reason I thought that was because the subject of this thread said "With Link."

Hey Phil,

I'm using the Clipboard in this, but you can use any available source of HTML text.

-Chris


Convert HTML to RTF on the Clipboard v1.00.kmmacros (5.4 KB)

Thanks! I am having trouble with it, though—I try to paste and nothing happens. I'm putting the HTML in the Trigger Clipboard, then displaying it to make sure it's make sure it's there, then I use your shell script with input from the Trigger Clipboard and display the results. That display comes up blank. From my macro:

The results of the first action in the above:

The results of the final action:

I have also tried this using the System Clipboard for everything—same results. Any thoughts would be much appreciated!

Hey Phil,

Use the system clipboard.

Don't save to the clipboard – the script does that.

-Chris

Perfect—thanks so much!

1 Like