logseq / mldoc

Another Emacs Org-mode and Markdown parser.
GNU Affero General Public License v3.0
233 stars 20 forks source link

Org convert to Markdown has wrong URL link format #124

Open heptaspirit opened 2 years ago

heptaspirit commented 2 years ago

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.

Lionade commented 7 months ago

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 {} \;