Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A macro that converts the current WP doc to DOCX (requires pandoc) #17

Open
emendelson opened this issue Aug 27, 2022 · 3 comments
Open

Comments

@emendelson
Copy link
Contributor

emendelson commented Aug 27, 2022

Here is a rough-and-ready WP Unix macro that converts the current document to DOCX format, using the pandoc document converter. It requires pandoc version 2.14.2 or later, and Ubuntu (probably like some other distros) supplies only an earlier version, so you'll need to get the binary here (for debian-based distros, download the .amd64.deb)

https://github.com/jgm/pandoc/releases

The macro assumes that the pandoc executable is /usr/bin/pandoc; if other distributions put it somewhere else, edit the macro for the correct location. The macro tests for the presence of pandoc, but I don't know how to make it test for the correct version.

The macro first saves the current document (without asking you first; maybe I should fix this), then runs the WP-supplied cvt program to create a temporary RTF version of the document; then runs pandoc to convert from RTF to DOCX, and, by default, shows the converted file in the WP List Files screen (this last behavior can be turned off by changing one line in the macro).

The output file has the same path and filename as the original file, with an added .docx extension.

At the moment, the macro does not ask if you want to overwrite an existing docx file - it just goes ahead and overwrites it. I can add that prompt later.

Here's the macro:

https://www.dropbox.com/s/6op1nbrfuc5esi8/wptodocx.wpm?dl=1

I've tested this only in WSL Ubuntu, but I think it should work in non-Windows debian-based Linux.

By the way: in WSL Ubuntu, you should probably create a wpmacros folder somewhere in your home folder, and copy all the files in opt/wp80/wpmacros into that new folder; then go to Shift-F1 Location of Files, and specify the new folder as the location for macro and keyboard files. On my setup, I don't have write access to /opt/wp80/wpmacros and so can't edit or create keyboards and macros there.

EDIT: Fixed the link.

@emendelson
Copy link
Contributor Author

emendelson commented Aug 27, 2022

I've now fixed a few errors in the macro, and added a prompt asking whether to overwrite an existing file. (I forgot how tricky it can be to make WP detect an existing file.) Same download link as before.

@emendelson
Copy link
Contributor Author

And I've now revised this so that, by default, it opens the docx file in the default application in either pure Linux or WSL - but WSL needs the wslview utility installed. In the future, I'll check for this, but this seems pretty good for now.

You can change this feature by editing the macro as described near the top of the file.

@emendelson
Copy link
Contributor Author

Fixed a few mistakes in this macro. If anyone has downloaded it, please replace it with the current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant