Sunday, October 17, 2021

#1 2021-09-17 12:46:33 pm

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 672
Website

Clipboard to Html to md with formatting

I tried my best to convert rtf clipboard data  to html but i get just plain text without formatting, as a result:

Applescript:

set fNex to "docx"
set tmpDir to POSIX path of ((path to desktop folder from user domain as text) & "Html:" as text)
do shell script "mkdir -p '" & POSIX path of tmpDir & "'"

set cmd to "pbpaste -Prefer rtf | textutil -stdin -convert html -output '" & (tmpDir & "Test.html" as text) & "'"
do shell script cmd

of course, i could generate a html file from a rtf, that solution works nicely.
Finally my goal is to convert html to markdown -with nice formatting attributes.

But if i use Pandoc - a universal document converter, all formatting gets lost, converting from html to md. The manual of pandoc is very long - and i tried just some basic commands right now.
The default settings of pandoc are totally insufficient - you get just plain text - in that case i do not need any conversion at all - textutil does it better and preserves formatting from rtf to html. Unluckily, textutil  cannot deal with markdown and maybe won't ever..

Offline

 

#2 2021-09-17 04:42:26 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 898

Re: Clipboard to Html to md with formatting

@Joy
You could modify Shane code from this link.
https://macscripter.net/viewtopic.php?p … 01#p206801

It use ASObjC.


if you are the expert, who will you call if its not your imagination.

Offline

 

#3 2021-09-18 09:57:00 am

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1043

Re: Clipboard to Html to md with formatting

Hi. My understanding is that standard input is plain text, so textutil's source would seemingly have to be a file, rather than stdin.

Applescript:

do shell script "textutil -convert html -input " & ((path to desktop folder as text) & "whatever.rtf")'s POSIX path's quoted form & " -output " & (path to desktop folder as text)'s POSIX path's quoted form

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)