Copy Markdown to Teams



This content originally appeared on DEV Community and was authored by Alexander Kammerer

I write all my notes at work and also my private notes in Obsidian. I find that it works perfect for my personal workflow and helps me be more organized. When I work on a new project, I like to write out a detailed proposal that highlights a possible plan, any issues that might occur, and any open questions.

I find myself copying that text over to Teams so that my colleagues also have access to these notes. But when I copy the markdown that I have written in Obsidian, the formatting is not correctly copied over.

While Teams does support some markdown (you can use **something** to make some text bold) it does not work well when pasting markdown.

Other people have noticed this issue as well and there are some workarounds but none that really work for me. I just want to copy the markdown and paste it into Teams.

The best workaround I found was pasting the markdown into an editor that supports a rich text preview and the copying the rich text preview. This is quite annoying and I do not want to use any online tool because I do not want to paste possibly sensitive text into a website.

The Plan: Markdown to HTML to Teams

After some research, I found the following workflow that seems to work rather consistently and produce well formatted text:

  1. Copy the markdown from Obsidian.
  2. Translate the markdown into HTML using the markdown package in Python.
  3. Copying and pasting the HTML into Teams.

Teams knows how turn HTML into formatted text.

Nushell

To make this more convenient, I turned this into some shell script that takes the current clipboard content and converts it into html.

I use uv to invoke the CLI of the markdown package in Python. I then copy the output back into the clipboard.

Just put the following function into your nu config (config nu)

# convert markdown to html for Teams / other Microsoft products
def md2html [] {
    let markdown = (powershell -c "Get-Clipboard -Raw")
    let html = ($markdown | uvx --from markdown --with markdown python -m markdown -e utf8)
    $html | powershell -c "Set-Clipboard -AsHtml -Value $input"
}

Powershell

You can do the same thing in Powershell. Just put the following function into your powershell profile Microsoft.PowerShell_profile.ps1.

Function md2html {
    $OutputEncoding = [System.Text.Encoding]::UTF8
    $markdown = Get-Clipboard -Raw
    $html = $markdown | uvx --from markdown --with markdown python -m markdown -e utf8
    $html | Set-Clipboard -AsHtml
}

Usage

Finally, you can use this by copying the notes in Obsidian, opening a terminal, running md2html, and then pasting into Teams.

The result should be properly formatted text in your Teams chat message or channel post.


This content originally appeared on DEV Community and was authored by Alexander Kammerer