TLDR: This is a workaround to export pdf from Obsidian via typora using python script.
Requirement: You need to have python and Typora installed. And change two paths in the script as instructed.(I’m a python beginner, and I learnt regex few hours ago, so my code might be ugly… )
import re
attachment_folder = r"D:\\Important\\Obsidian\\My notes\\_resources"
file_path = "C:\\Users\\Frank\\Desktop\\test.md"
'''
replace above two paths with yours.
Windows User:BACKSLASH NEEDS TO BE DOUBLED!!! No need to change code below.
Linux and MacOS user: use single slash '/' instead of double backslash '\\' in your two paths and change line 20's '\\' to '/'
'''
with open(file_path, 'r+', encoding='utf-8') as md:
orig_text = md.read()
text = re.sub("!\[\[((.*)\.\w+)]]", r"", orig_text)
with open(file_path, 'w+', encoding='utf-8') as md:
md.write(text)
If you did not open markdown link format in Obsidian, link is [[pic.png]], this will not render correctly in typora. So you need to convert it to pic. This is what this script do for you.
import re
import os
source_file_name =""
# source_file_name = "CNN"
source_folder = r"F:\\ObsidianVault\\Arsene\\AI\\Tensorflow"
attachment_folder = rf'{source_folder}\\attach'
output_folder = r"F:\\MDPrint"
def transfer_md(mdfile):
with open(f'{source_folder}\\{mdfile}.md', 'r+', encoding='utf-8') as md:
orig_text = md.read()
# let ![[pic.png]] ==> 
text = re.sub("!\[\[((.*)\.\w+)\]\]", r"", orig_text)
# let  ==> 
text = re.sub("!\[\]\(((.*)\.\w+)\)", r"", text)
# let [[Link Name]] ==> Link Name, [[Link Name|Altr Name]] ==> Altr Name
text = re.sub("\[(?:\[|\[[^\]]*\|)([^\]\|]+)\]\]", r"\1", text)
with open(f'{output_folder}\\{mdfile}.md', 'w+', encoding='utf-8') as md:
md.write(text)
def trasfer_all_md(mddir):
for file in [md[:-3] for md in os.listdir(mddir) if re.match('.*\.md',md)]:
print(f'process file: {file}')
transfer_md(file)
if __name__ == '__main__':
if len(source_file_name)>0: # For one file
transfer_md(source_file_name)
else: # For entire folder
trasfer_all_md(source_folder)
Sorry, but I’m not a programmer and have no clue how to do the task with Typora. Do I have to save the code in a .py file and need to run it as a command in Typora (added to the PDF export)?
Any support is appreciated
And has anyone an idea how to convert the markdown file to a markdown file without the links? I tested this plugin, but I use internal links to headers in files and it didn’t work for that purpose.
I need the “clean” markdown for a glossary, which I use in a latex file for a thesis.