[How to] Convert .md files to .docx documents directly from your Android phone!

I successfully did that just now to convert one of my files to .docx. Since the converter plugin doesn’t work on Mobile, I think I should probably share the method for you guys!

Do note that the output Word or any other documents types may look different than the .md file preview. Also, doing the conversion on a computer might just be the better option. But if you don’t have access to a computer, then this may be useful!

Steps:
1. Download Termux From Here, and install it.
Do not download Termux from Google Play Store. Termux there is outdated and the devs no longer can update the app due to some Play Store policies that would otherwise ruin the app.
Termux is a terminal emulator app that a lot of people use to run things like Python, Java or even Linux systems.

2. Inside Termux, do termux-setup-storage. Termux will then ask for the storage permission, click Allow.

3. Still in Termux, do pkg install pandoc. It will now grab the Pandoc executables from the Termux servers. This is the Pandoc we’re using!

4. Now we need to do some preparation in your going-to-be-converted markdown note file. Check if your note has any of these:

  1. [[Wikilinks]]. Pandoc doesn’t support Wikilinks, so before converting, you might want to convert the Wikilinks to Markdown links (the Wikilinks to MDLinks plugin is helpful for this). You’ll also need to move every picture you used in that note to the same folder containing the note (since for whatever reason that plugin won’t generate the full path of the pics and Obsidian doesn’t support full path too like WHAT WHY), so Pandoc can find them.
  2. Single line breaks. The basic Markdown doesn’t show single line breaks in preview, but Obsidian gracefully gave us the option to still use single line breaks. Pandoc however won’t allow that, so either make one additional line break every line, or maybe you’ll have to deal with gone line breaks sadly.
    You might want to do a backup of the note before handling these problems as well.
    Or smashing the Undo button afterwards might work too!

Now having your note ready for the conversion, go back to the Termux app again.

5. In Termux, do cd "/path/to/your/note/". On Android, the path should always start with /storage/emulated/0/ or /sdcard/ (These are the same thing, a.k.a. the “Internal Storage”.)
For example, if your note is Internal Storage/Documents/Vault/Note.md, then cd "/sdcard/Documents/Vault/" is what you’ll need to do. This should be the folder containing your note also with the pictures used in the note (Step 4 (1)).
This cd command moves the terminal to the folder with your note.

Note: Don’t forget the quotation marks if your path has spaces inside!

6. Start converting!
Still in Termux, do pandoc -o "Your output file name.docx" -f markdown -t docx "Your Markdown note name.md", replace the name with your actual note. Wait it to process, and once the inputbox appears again, the conversion is done!

7. Enjoy your converted Word document in the same folder as your notes!

Now you can revert your note back to where it was (Wikilinks, line breaks, etc.)

If you have any questions/suggestions/things to add, feel free to comment and let me know.

I hope this helps!

1 Like