I have a rich text that I copied from somewhere else. The text contains a title (in bold) and some quotes.
They are extracted from a PDF file by Zotero.
I'd like to convert the rich text into markdown.
Zotero has an extension to generate a markdown file, but I'd like to use Keyboard Maestro to do the conversion, if it is possible.
I am attaching the sample PDF file (which is not necessary), the rtf file (which I simply copied from the extracted notes created by Zotero. It is the source. The real source is the clipboard, but I have to paste it into an rtf file to upload), and the output markdown file (which is my desired outcome. I'd also like to put it in the clipboard).
files.zip (45.9 KB)
Edit (2021/10/13 11:31):
- I did more tests. I found out that if I run @ccstone's script after copying from Zotero extracted notes, it says no "rtf" text. But if I copy from Word, Scrivener, or Nisus Writer Pro, the script works as intended.
- I pasted the text that I copied from Zotero extracted notes to Nisus Writer Pro, and then copy the text from Nisus Writer Pro, the script works well.
- It looks like Zotero's notes are in HTML format, when I copy and paste to Nisus Writer Pro, the text is converted into RTF. Therefore, the text I uploaded here as RTF does not accurately represent the text I copied from Zotero notes (HTML format). This also explains why I had to use
After copying the extracted notes from Zotero (the content is essentially what shows in the rtf file), execute the KM macro, and it will put the markdown text to my clipboard.
I don't know if pandoc can do it or not. I have tried something like:
# with input from the clipboard in KM Shell action iconv -t utf-8 | /usr/local/bin/pandoc -f rtf -t markdown | iconv -f utf-8
export LC_CTYPE=UTF-8 /usr/local/bin/pandoc -f rtf -t markdown /path/to/source.rtf
The links are simply stripped off.