Search code examples
windowsmarkdownpowerpointcopy-paste

Copy and paste markdown text to correctly formatted text in a PowerPoint presentation


I have the following text in Markdown format.

Hello, check out [this link](https://learn.microsoft.com/en-us/powershell/).
Here is a list of things
- Eggs
- Tomatoes
- Ship

And I would like to copy and paste it in a PowerPoint presentation, such that the link and the unnumbered list are correctly formatted in the target PowerPoint style. Here would be the expected result. https://i.sstatic.net/X8oFY.png

However, by simply copy-pasting, I get something like this. https://i.sstatic.net/9Kktt.png

How to convert from Markdown to formatted text in PowerPoint?

Currently, I am using the following way to achieve this:

  1. Convert the markdown file to .docx using pandoc.
  2. Open the docx file in Word
  3. Copy paste the content to Powerpoint.

This perfectly works, but it is tedious work. Is there any way I could automate this?

I would like for example to convert some text from markdown text to formatted text in the clipboard which I can paste somewhere I want in my PowerPoint presentation.

I tried to use the following one-liner in Powershell:

pandoc -i myfile.md -t docx -o - | Set-Clipboard

But when I paste into Powerpoint, I get a strange result looking like this. https://i.sstatic.net/zWYGl.png

Thanks for ideas and help!

2023-11-01 EDIT: I searched for solution using Powershell and Pandoc, and ended up with the following powershell script which almost works.

$tempfile = ".\deleteme.rtf"
Get-Clipboard | pandoc -t rtf -o $tempfile
Add-Type -AssemblyName "System.Windows.Forms"|Out-Null
[Windows.Forms.Clipboard]::SetDataObject([Windows.Forms.DataObject]::new([Windows.Forms.DataFormats]::Rtf,(Get-Content -Raw $tempfile)))
Remove-Item $tempfile

Only when the copied markdown text is more than one line, it won't work as expected: it will only convert the first line. However the tempfile seems fine, so I am wondering what I am doing wrong with the Get-Content command or somewhere else at the same line.


Solution

  • I found a simple solution to my issue. The following command will convert markdown text in the clipboard to HTML formatted text and set the clipboard with it.

    Get-Clipboard | pandoc -t html -o - | Set-Clipboard -AsHtml
    

    Then I can paste the HTML text in the clipboard to my PowerPoint presentation.

    One caveat is that bullet symbols are not well rendered, but the overall wanted result is obtained. It also works for any multi-line text present in the clipboard.