Convert Markdown to PDF / DOCX in Devonthink using Pandoc

An absolute fantastic topic!

I tried to download the zip and the converted examples, but only get some “access denied” messages.

Is this only me, or some general problem?

We have corrected the access permissions for a few affected files in the backend. You should now be able to download them again.

@cgrunenberg or @BLUEFROG and others, what is the best current method of converting .md files within DT3 to docx in 2022? Is there any approach you would recommend? I don’t like docx but my work demands it. I have tried a few external apps like Markdown2, and Typora, but they seem to not be able to recognise images that are stored within DT3 and output them. Preferably the output would as closely match the markdown as possible and prevent have to do a lot of reformatting on the word document. Converting to rft then to word look nowhere near as good as the .md files themselves, it works but looks a little rough. Would a combination of script and pandoc be the way to go to?

Create a docx template you like then use Pandoc to convert MD to DOCX using it.

Thanks @Bernardo_V. I will have a. play with it. I gather it’s all done via terminal, which normally I’ve never had reason to look at. Are there any resources/tutorials to get newcomers acquainted that you are aware of? Or is it simpler than imagined?

At least the easiest approach is via File > Export and importing the exported file.

1 Like

I use that command to export to the desktop and get this message:

Word cannot open the file because the file format does not match the file extension.

Is that a known issue?

Which export did you use and which version of DEVONthink?

Hi @cgrunenberg, using 3.8, File > Export > As word 2007 Document (DOCX).

Hi @Bernardo_V, so downloaded Pandoc, checked to see if installed in terminal, put a markdown file on my desktop, open terminal, go to the desktop using cd Desktop, then run this command: pandoc testfile.md -s -o testfile.docx.

I get this message:

pandoc: testfile.md: openBinaryFile: permission denied (Operation not permitted)

Same if use this: pandoc testfile.md -f markdown -t docx -s -o testfile.docx

Changing to rtf output also same message.

Any obvious mistakes?

Other people have mentioned the same problem (as your favorite search engine will tell you). I guess that it has something to do with your shell setup, so typing which pandoc In the terminal might be a sensible first step to resolve the issue.

In any case, you should take this up with the pandoc people since it has nothing to do with DT

2 Likes

I think the -s comes before the first filename, like this:

pandoc -s testfile.md -o testfile.docx

Not sure if that’ll make any difference but that’s how it is in my script!

Alternatively, might want to try Marked 2, which also exports to docx.

1 Like

Thanks for the suggestions by yourself and others, will keep experimenting. I agree @chrillek it’s not a DT problem but was suggested by @Bernardo_V and the DT3 export is not working for me. I have a file that was done in markdown on DT3, with images also stored in DT3, but when these are opened in external editors the images are not recognised as the in DT3, they are linked in the form of ![namefile](x-devonthink-item://…), and that seems to be unrecognised so the pictures are missing. Perhaps @cgrunenberg will have a suggestion to get DT native export function working.

An item link for an image isn’t going to work outside DEVONthink unless the external application had specifically coded to support it.

Thanks @BLUEFROG do you know what’s wrong with the DT3 export option?

Although I can’t speak for the developers, I guess there’s nothing wrong with the export per se. Word did offer the possibility to refer to images by reference in the past, and I guess that this is still possible today. A reference is roughly the same as a link, so translating the latter to the former in export seems obvious.

You could try to convert your file first to a formatted note and than this one to a docx. Formatted notes embed images (and other links, afaik).

Does changing the extension to .doc make a difference? Or is TextEdit or Pages able to open the document?

Thanks for responding. I am not sure if the problem was clear. The exported DOCX from DT3 can’t be opened. Can save it to desktop. But it gives this error when try to open in Word:

Word cannot open the file because the file format does not match the file extension.

So that’s in part why looking at 3rd party apps but as @BLUEFROG states they can’t display item links which they all are in my longish markdown document.

It does open with doc extension but results aren’t good. It was unreadable as the font was black on dark background (am running Monterey 12.0.1 in auto light/dark appearance and it’s night here). When change to light mode in system settings its mostly white font on white background.
It does open in text edit with docx extension, but it is a grey on dark background. Pages similarly can open but white on white background.
With Mellel this message appears:

The document “Cheat sheet.docx” could not be opened. Can’t open zip archive

Hope that helps

Do you use your own stylesheet or the internal one?