Use a more standard flavor of markdown

sharing this script as a temporary workaround to convert from logseq to more standard md for obsidian/typora/etc :

# convert logseq to md
for file in *.md **/*.md **/**/*.md 
do
	# filepath="$file"
	file_name=$(basename "$file")
	echo "PROCESSING $file..."
	queryb='#+BEGIN_QUERY'
	querye='#+END_QUERY'
	sed -i 's/##########/\t\t\t\t\t\t\t-/' $file
	sed -i 's/#########/\t\t\t\t\t\t-/' $file
	sed -i 's/########/\t\t\t\t\t-/' $file
	sed -i 's/#######/\t\t\t\t-/' $file
	sed -i 's/######/\t\t\t-/' $file
	sed -i 's/#####/\t\t-/' $file
	sed -i 's/####/\t-/' $file
	sed -i 's/###/-/' $file
	# sed -i 's/##//' $file
	sed -i 's/:PROPERTIES:/<!--/' $file
	sed -i 's/:END:/-->\n/' $file
	sed -i 's/{{{embed /#relink-embed <!--/' $file
	sed -i 's/((/#relink-block [[/' $file
	sed -i 's/))/]]/' $file
	sed -i 's/{{{/#relink <!--/' $file
	sed -i 's/}}}/-->/' $file
	sed -i 's/{{/#relink <!--/' $file
	sed -i 's/}}/-->/' $file
	sed -i "s/$queryb/<!--$queryb/" $file
	sed -i "s/$querye/$query-->\n\n/" $file
done

I’m using it with zsh in Windows WSL but I suppose it should work in bash too.

  • it transforms: ### to tab+- and subsequents # add more tabs.
  • the base ## is untouched so it will look like a <H2>, depending on your workflow, you might want to uncomment the sed line
  • :PROPERTIES: .... :END: are replaced by comments <!-- (...) --->
  • embeds are replaced by a tag #relink-embed + comments to preserve the id for manual relinking
  • block refs : added #relink-block tag and turned into [[id]] : it needs manual relinking
  • queries are converted to comments (enclosed in <!-- -->)

!! warning: don’t run on your repo - make a copy first (this is not a 2-way converter) !!

usage:

. save the code as convertlogseq.sh
. create a \process folder and copy your logseq md files into \process
. put the script convertlogseq.sh in the \process folder
. open terminal, go to \process, run ./convertlogseq.sh
. it should process all .md files in \process + subdirectories recursively (it will throw error messages if there are no subfolders but it should be ok)

PS: the script is very crude, if you know how tyo improve it, please share

5 Likes