How to remove new line styling from copied web text, whilst retaining all other styling?

This has been bugging me for the longest time and I haven't been able to figure it out, so I thought I'd reach out.

For context, I'm grabbing text from websites and pasting it into Notion. A good example of what I'm talking about is this paragraph on this url: Entity Types - EF Core | Microsoft Learn

Screenshot 2024-06-11 at 11.19.08 AM

As you can see, it has a highlighted word and the text is broken into various lines.

When I do a normal copy and paste of this paragraph into Notion, it seems to copy over most of the styling. This is what it looks like:

What I'm wanting to do, is keep all the styling except the broken lines. So it looks like this:

The problem I'm having is that I'm unable to remove only select styles via Keyboard Maestro. Instead, it will remove all styles. Which is to say currently I can get it to paste this:

Screenshot 2024-06-11 at 11.43.09 AM

However, I would like to retain the styling on that OnModelCreating text.

I've tried using the Filter System Clipboard action, but it seems to remove all styles. I've tried using the Search and Replace action, but the problem is that action removes all styles by default, so it doesn't achieve what I want it to.

Basically all I want to do is remove the new lines (I assume that's the directive) from the text, and retain everything else.

Any help appreciated!

Your post is well explained, in my opinion, with clear examples, so congratulations on that. But I'm still not 100% certain that I understand because I don't see any "broken lines" in your example.

You are right that KM removes "all" styles. But I may have two possible ways to proceed. One is to use AppleScript to manipulate the styles in some app that supports AppleScript. I'm very weak with AppleScript so someone else will have to address that idea. I think it should be possible to change specific styles without affecting the others. But I have no experience doing that.

Another possible way may require a compromise on your part. I think it should be possible, if you know the exact styles that you want in absolute terms, rather than talking about relative styles, you could probably place the unstylized text (which you can get from the KM Remove Styles action) into a clipboard, and then used the following actions (see image) to set all the text in that clipboard into the style of your choice. The reason this is a compromise is that it forces you to deal with styles in absolute terms, rather than talking about "modifying specific styles only."

If you look closely, three of the options in the above action can be set to "Unchanged". So with regard to these three attributes only, this action does work in "relative" changes, not just absolute changes. But it seems like a slight omission that this action doesn't allow "unchanged" for features like the font size, colour, background, and font name.

In my opinion, my second solution is most likely the easiest one that you can try. But it does require that you start thinking in terms of "absolute styles" rather than "modifications to styles."

My record lately for helping people has been lower than 80% successful, so I may not have the best or right answers for you.

Thank you for responding.

The lines are broken because they are not continuous. I think there is a new line character where it is "broken". Basically what I have to do is go to the start of a line and hit backspace, and then that line with snap to the start of the other word.

For example:

and if I hit delete before the specified word:

Unfortunately I don't think your suggestions are useful for what I'm trying to achieve. It might just be a limitation with KM removing all styles, which is unfortunate.

As you wish.

I tested the text on the source page, and there are no line breaks in it—I pasted it into TextEdit, and the text is continuous. Same thing in BBEdit, and there aren't any line breaks when I tell it to show invisible characters. Same thing using a formatted word processor like Word or Pages: No line breaks.

It seems that Notion is adding those line breaks, somehow. This makes your request nearly impossible to fulfill, because you can't do any processing to the text in Keyboard Maestro before sending it on to Notion: There's nothing there to edit in terms of line breaks to remove, at least not that I can see.

So then I installed the Notion demo, and when I pasted in the copied text, there aren't any line breaks there, either:

I just pasted it into a new note. Keeping in mind I've never used Notion before, where would I paste the text to see the problem you're seeing?

-rob.

Very, very interesting that you're not getting any line breaks in Notion.

I can confirm your behaviour with TextEdit, and furthermore it does seem to keep the other styling I want to keep as well. However when I copy and paste from TextEdit to Notion, it gets rid of that additional text styling which I find odd.

Here is a demo video of what I'm seeing. At the end, I paste the block using a keyboard maestro macro to demonstrate what KM is doing.

Screen Recording 2024-06-11 at 1.24.45 PM.mov.zip (1.8 MB)

Question: Which browser / OS are you using? I'm using firefox, maybe that affects how the text is copied.

Okay, it looks like this behaviour might be specific to Firefox? Seems like it works fine with Chrome.

Pasteboard handling is certainly app-specific.

You should be able to inspect what pasteboard contents the two different browsers are creating by using a macro like this:


Applications typically create more than one kind of clipboard content when they copy, and it's up to each pasting applications to select which of the available pasteboard formats they use.

If you find that one of Firefox's clipboard elements works better than others, and Notion is making a choice which doesn't work well for you, then it may be possible to write a script (for a KM Execute JavaScript for Automation action, which intervenes by pruning out the unwanted format from the pasteboard.

(public.html vs public.rtf pasteboards, for example)


Taking a quick look, the Firefox clipboard does look a bit impoverished when we copy from the page you link to. Unlike Safari, for example, it doesn't create a public.rtf pasteboard, and the style of its its public.html clipboard is quite puritan and reduced.

Simplest approach may be to use a different browser ?