Paste rich text from clipboard in rtf file

This is what I'm trying to achieve:

  • Copy text from a website to the clipboard (incl headings, lists, formatting etc)
  • Save this as a temporary .rtf file
  • Convert this file to a markdown file
  • Delete the temporary .rtf file

Issue: the clipboard content isn't pasted as rich text into the rtf file.

This is my code:

Clipboard PASTE AS "{sourcepath}{file|noext}.md.rtf"
pandoc "{sourcepath}{file|noext}.md.rtf" -f rtf -o "{sourcepath}{file|noext}.md"
Delete "{sourcepath}{file|noext}.md.rtf"

So the main question is: can I paste rich text into a file?

The built-in clipboard support only handles images and plain text for that type of thing.

If there's a utility with a command line that can paste rich text into a new .rtf (or .md) file, or a way to make pandoc read from the clipboard directly, then that would be easy to automate from within Opus, but there's no understanding of RTF clipboard data built-in.

Thanks Leo, I figured that much.

I created (using ■■■■■■■) something that works in powershell, but I don't want to create a separate PS1 file.
What I want to do on the fly is: create this file in the sourcefolder using Dopus, then execute this file. And then delete the file.
But I don't know how to paste the code into the file. The code contains double and single quotes and multiple lines and I don't know how to handle that with Dopus.
I guess quotes can be escaped, but I can't get it to work.

// Dummy code
// 1. Set variable for temp file
set ps1file="{sourcepath}{file|noext}.ps1

// 2. Set varable with the complete code I need to run
set file_content="this is multiline
content 'using single' and "double quotes" and
this is the code I want to run in {sourcepath}"

// 3. Create a temporary file with this content
echo %file_content% >> %ps1file%

// 4. Execute file
powershell.exe %ps1file%

//5. Delete temp file
Delete FORCE QUIET %ps1file%

Let's say the code is this:

# Demo.ps1

# Variabelen
$naam = "Bart"
$leeftijd = 42
$map = "C:\Temp"

# Single quotes: letterlijk weergeven
Write-Host 'Hallo $naam, 'je bent' $leeftijd jaar oud.'
# Output: Hallo $naam, 'je bent' $leeftijd jaar oud.

# Double quotes: variabelen worden ingevuld (interpolatie)
Write-Host "Hallo $naam, je bent $leeftijd jaar oud."
# Output: Hallo Bart, je bent 42 jaar oud.

# Strings samenplakken met +
Write-Host "Je bestanden staan in " + $map

# Of interpoleren in één keer
Write-Host "Je bestanden staan in $map"

# Curly braces voor veiligheid bij plakken
Write-Host "Volgende jaar ben je $($leeftijd + 1)"

# Bestandsnaam bouwen met variabelen
$bestandsNaam = "$naam-log-$leeftijd.txt"
Write-Host "Bestandsnaam wordt: $bestandsNaam"

Properly converting web snippets is a job probably best left to word processors.

I would feed the website URL to Pandoc, have it generate a .md file, and then edit the resulting Markdown document.

If you must use the clipboard, a script should be able to feed its content to Pandoc.