mldoc icon indicating copy to clipboard operation
mldoc copied to clipboard

Org convert to Markdown has wrong URL link format

Open heptaspirit opened this issue 2 years ago • 1 comments

I try to use this tool to convert my logseq org-mode file into MD, all things right, but URL has broken.

This is original org-mode file

* Blog.Agency
:PROPERTIES:
:collapsed: true
:END:
** [[https://sylvainmenguy.com/en/][Sylvain Menguy - blog]]
** Minecraft 国家建筑师
:PROPERTIES:
:collapsed: true
:END:
*** [[https://space.bilibili.com/24323][国家建筑师Cthuwork]]
** [[https://gamediscover.co/][GameDiscoverCo]]

And after converting, there is MD file

- Blog.Agency  
:PROPERTIES:
:collapsed: true
:END:
	- [[https://sylvainmenguy.com/en/][Sylvain Menguy - blog]]  
	- Minecraft 国家建筑师  
:PROPERTIES:
	  :collapsed: true
:END:
		- [[https://space.bilibili.com/24323][国家建筑师Cthuwork]]  
	- [[https://gamediscover.co/][GameDiscoverCo]]  

The URLs in the converted MD file are still org-mode format, so they can’t be rendered correctly.

heptaspirit avatar Jul 27 '22 02:07 heptaspirit

For anyone having the same issue and seeking a quit solution: I created a small zsh script to find all occurrences (in a directory and all its subdirectories) of the org-mode link syntax and converted it to the markdown one. Just change the SEARCH_DIR var to your Logseq directory.

#!/bin/zsh

export LC_ALL=C

# Directory to search for files
SEARCH_DIR="*LOGSEQ DIR*"

# Find and convert all files in the directory and subdirectories
find "$SEARCH_DIR" -type f -exec zsh -c '
    # Function to convert string format
    convert_string_format() {
        local file=$1

        # Use sed to replace the string format
        sed -i "" -E "s/\[\[([^][]*)\]\[([^][]*)\]\]/[\2](\1)/g" "$file"
    }

    # Call the function with the current file
    convert_string_format "$1"
' zsh-shell {} \;

Lionade avatar Jan 07 '24 16:01 Lionade