From cc6d4b2ee434cde559f73f6353f1b38e10e97912 Mon Sep 17 00:00:00 2001 From: lovelife_lizhe <513278236@qq.com> Date: Thu, 13 Mar 2025 00:53:30 +0800 Subject: [PATCH 1/4] Fix issue not remove Chinese Anchor --- lua/obsidian/util.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/obsidian/util.lua b/lua/obsidian/util.lua index 1db3d044..47d780d6 100644 --- a/lua/obsidian/util.lua +++ b/lua/obsidian/util.lua @@ -1125,7 +1125,7 @@ util.get_icon = function(path) end -- We are very loose here because obsidian allows pretty much anything -util.ANCHOR_LINK_PATTERN = "#[%w%d][^#]*" +util.ANCHOR_LINK_PATTERN = "#[^%s]+" util.BLOCK_PATTERN = "%^[%w%d][%w%d-]*" @@ -1139,11 +1139,12 @@ util.strip_anchor_links = function(line) local anchor while true do - local anchor_match = string.match(line, util.ANCHOR_LINK_PATTERN .. "$") - if anchor_match then + local start_pos, end_pos = string.find(line, util.ANCHOR_LINK_PATTERN .. "$") + if start_pos then + local anchor_match = string.sub(line, start_pos, end_pos) anchor = anchor or "" anchor = anchor_match .. anchor - line = string.sub(line, 1, -anchor_match:len() - 1) + line = string.sub(line, 1, start_pos - 1) else break end From f65b9f9e00e5c3be210129d31e1e3c14c77f8c5f Mon Sep 17 00:00:00 2001 From: lovelife_lizhe <513278236@qq.com> Date: Thu, 13 Mar 2025 01:07:16 +0800 Subject: [PATCH 2/4] Fixed `util.strip_anchor_links` to properly handle Chinese/non-ASCII characters in anchor links. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b585ed0e..87a1d8c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an edge case with collecting backlinks. - Fixed typo in `ObsidianPasteImg`'s command description - Fixed the case when `opts.attachments` is `nil`. +- Fixed `util.strip_anchor_links` to properly handle Chinese/non-ASCII characters in anchor links. ## [v3.9.0](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.9.0) - 2024-07-11 From 16233354dc112843d5263166211e9da6b155ab55 Mon Sep 17 00:00:00 2001 From: lovelife_lizhe <513278236@qq.com> Date: Thu, 13 Mar 2025 03:27:53 +0800 Subject: [PATCH 3/4] Update the neovim download url in workflow --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 11692f71..e9a0a9bf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,12 +7,12 @@ concurrency: on: pull_request: branches: - - '*' + - "*" push: branches: - main tags: - - 'v*.*.*' + - "v*.*.*" jobs: style: @@ -57,7 +57,7 @@ jobs: include: - os: ubuntu-latest - nvim_url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz + nvim_url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-x86_64.tar.gz packages: luarocks ripgrep manager: sudo apt-get @@ -136,7 +136,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: "3.10" - name: Install requirements run: | From f2adb638b1d2bce4af8853fd5d16cfbffda457fa Mon Sep 17 00:00:00 2001 From: lovelife_lizhe <513278236@qq.com> Date: Fri, 14 Mar 2025 01:26:01 +0800 Subject: [PATCH 4/4] location Chinese heading right --- lua/obsidian/client.lua | 1 + lua/obsidian/util.lua | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lua/obsidian/client.lua b/lua/obsidian/client.lua index 00c09c77..e2db6e54 100644 --- a/lua/obsidian/client.lua +++ b/lua/obsidian/client.lua @@ -850,6 +850,7 @@ end ---@param link string|? ---@param opts { open_strategy: obsidian.config.OpenStrategy|? }|? Client.follow_link_async = function(self, link, opts) + print("follow_link_async: ", link) opts = opts and opts or {} self:resolve_link_async(link, function(...) diff --git a/lua/obsidian/util.lua b/lua/obsidian/util.lua index 47d780d6..bba0adc5 100644 --- a/lua/obsidian/util.lua +++ b/lua/obsidian/util.lua @@ -1238,8 +1238,14 @@ util.standardize_anchor = function(anchor) anchor = string.lower(anchor) -- Replace whitespace with "-". anchor = string.gsub(anchor, "%s", "-") - -- Remove every non-alphanumeric character. - anchor = string.gsub(anchor, "[^#%w_-]", "") + -- Remove every non-alphanumeric character except Chinese characters. + -- Keep: + -- - # (for anchor links) + -- - word characters (%w) + -- - underscore (_) + -- - hyphen (-) + -- - Chinese characters (UTF-8 byte ranges) + anchor = string.gsub(anchor, "[^#%w_%-\xe4-\xef\x80-\xbf]", "") return anchor end