Copying rich-text from Docx document, and paste as "Rich Text" (in Browser/Word Doc, etc)?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Copying rich-text from Docx document, and paste as "Rich Text" (in Browser/Word Doc, etc)?

21 Jan 2019, 13:25

Dear community,

I have been looking for a way to quickly convert Markdown syntax into "paste-able" contents into Google Docs. I have started this page on Pandoc discussion Google group, but have not received a good answer.

Now, my plan is to have pandoc do its own conversion job and delegate the pasting job to AHK.

Yet, I found this post to be super relevant. However, I can only get the "pure text" from the *.docx file. Only pure/plaintexts were pasted to where I type "ttest".

Code: Select all

::ttest::
myinputfile := "c:\users\llinfeng\somewhere\DOC_with_Headers_and_BOlding_and_otheres.docx" 
clipboard:=ComObjGet(myinputfile).Range.FormattedText.Copy
Send ^v ; paste
Return ; added return
Is pasting the pure text and ignoring the heading/bolding syntax the expected behavior, or am I invoking/defining the shortcut wrongly?

Thank you in advance!
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Re: Copying rich-text from Docx document, and paste as "Rich Text" (in Browser/Word Doc, etc)?

21 Jan 2019, 14:29

I found an alternative Powershell solution. It is nicer as one does not have to open any terminal to execute it. I am almost there :) Still, I need two pieces of input to improve the script.

Need help now with dealing with the flashing black window from Powershell :)

Code: Select all

::togo::
    Run, PowerShell  "paste.exe | pandoc -f markdown -t HTML |  Set-Clipboard -AsHtml ; echo 'Conversion done.' "
    ; send ^v
Return ; added return
Also, I commented out the pasting command as it does not always paste the correctly formatted things into the Browser. Pressing the Ctrl + V button on the keyboard will always work.
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Re: Copying rich-text from Docx document, and paste as "Rich Text" (in Browser/Word Doc, etc)?

28 Jan 2019, 16:42

Note, there is a bug in the script I posted: if one shall type double quotes, the closing doubles will be converted into "�?". I asked the question on StackOverflow, which appeared to be more active than the Google Forum of Pandoc.

* Link: https://stackoverflow.com/questions/54410656/pandoc-powershell-option-to-use-to-avoid-in-place-of-the-closing-double-quot
User avatar
JoeSchmoe
Posts: 129
Joined: 08 Dec 2014, 08:58

Re: Copying rich-text from Docx document, and paste as "Rich Text" (in Browser/Word Doc, etc)?

04 Apr 2023, 19:03

llinfeng wrote:
21 Jan 2019, 14:29
Need help now with dealing with the flashing black window from Powershell :)
Hi llinfeng, I saw your gist when I Googled using Autohotkey with Pandoc. The following code from @swagfag may help with the flashing black Powershell window:
viewtopic.php?style=2&t=59286

Did you ever find a another solution? I'm looking to write some very similar code.

Here is the relevant code from swagfag. Clearly he's using pclip, but I imagine you could swap that out and use paste.exe if you prefer it.

Code: Select all

runHiddenShell(cmd) {
	ComObjCreate("WScript.Shell").Run(cmd, 0, false)
}

runPandoc(markdown) {
	global Path

	clipSaved := ClipboardAll()

	cmd := Format("cmd /c `"`"{}`" | `"{}`" -t `"{}`" -f markdown-smart | clip`"", Path.pclip, Path.pandoc, Path.template)
	runHiddenShell(cmd)

	Sleep(200)
	phpbb := Clipboard

	Clipboard := clipSaved

	return phpbb
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: daiweisc, Sem552 and 187 guests