From f2fba2c3cc12e5b0b905ac1f1d8c8f1809983303 Mon Sep 17 00:00:00 2001 From: Liu Kehong Date: Fri, 21 Jul 2023 13:35:51 +0800 Subject: [PATCH] Allow Chinese characters in tags --- lua/telekasten.lua | 17 ++++++----------- lua/telekasten/utils/tags.lua | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 0dbbb17..00d36a9 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -2081,29 +2081,24 @@ local function FollowLink(opts) local filename_part = "" -- first: check if we're in a tag or a link - local kind, atcol, tag + local kind local globArg = "" if opts.follow_tag ~= nil then kind = "tag" - tag = opts.follow_tag if opts.templateDir ~= nil then globArg = "--glob=!" .. "**/" .. opts.templateDir .. "/*.md" end else - kind, atcol = check_for_link_or_tag() + kind, _ = check_for_link_or_tag() end if kind == "tag" then - if atcol ~= nil then - tag = taglinks.get_tag_at( - vim.api.nvim_get_current_line(), - atcol, - M.Cfg - ) - end search_mode = "tag" - title = tag + local saved_reg = vim.fn.getreg('"0') + vim.cmd("normal yiw") + title = vim.fn.getreg('"0') + vim.fn.setreg('"0', saved_reg) else local saved_reg = vim.fn.getreg('"0') if kind == "link" then diff --git a/lua/telekasten/utils/tags.lua b/lua/telekasten/utils/tags.lua index faf39e8..e1c2708 100644 --- a/lua/telekasten/utils/tags.lua +++ b/lua/telekasten/utils/tags.lua @@ -1,17 +1,20 @@ local Job = require("plenary.job") local M = {} -local hashtag_re = "(^|\\s|'|\")#[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*" --- PCRE hashtag allows to remove the hex color codes from hastags -local hashtag_re_pcre = - "(^|\\s|'|\")((?!(#[a-fA-F0-9]{3})(\\W|$)|(#[a-fA-F0-9]{6})(\\W|$))#[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*)" -local atsign_re = "(^|\\s|'|\")@[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*" -local atsign_re_pcre = - "(^|\\s|'|\")((?!(@[a-fA-F0-9]{3})(\\W|$)|(@[a-fA-F0-9]{6})(\\W|$))@[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*)" -local colon_re = "(^|\\s):[a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*:" -local yaml_re = - "(^|\\s)tags:\\s*\\[\\s*([a-zA-ZÀ-ÿ]+[a-zA-ZÀ-ÿ0-9/\\-_]*(,\\s*)*)*\\s*]" +local hashtag_re = + "(^|\\s|'|\")#[a-zA-ZÀ-ÿ\\p{Script=Han}]+[a-zA-ZÀ-ÿ0-9/\\-_\\p{Script=Han}]*" +-- PCRE hashtag allows to remove the hex color codes from hastags +local hashtag_re_pcre = "(^|\\s|'|\")((?!(#[a-fA-F0-9]{3})(\\W|$)|(#[a-fA-F0-9]{6})(\\W|$))" + .. "#[a-zA-ZÀ-ÿ\\p{Script=Han}]+[a-zA-ZÀ-ÿ0-9/\\-_\\p{Script=Han}]*)" +local atsign_re = + "(^|\\s|'|\")@[a-zA-ZÀ-ÿ\\p{Script=Han}]+[a-zA-ZÀ-ÿ0-9/\\-_\\p{Script=Han}]*" +local atsign_re_pcre = "(^|\\s|'|\")((?!(@[a-fA-F0-9]{3})(\\W|$)|(@[a-fA-F0-9]{6})(\\W|$))" + .. "@[a-zA-ZÀ-ÿ\\p{Script=Han}]+[a-zA-ZÀ-ÿ0-9/\\-_\\p{Script=Han}]*)" +local colon_re = + "(^|\\s):[a-zA-ZÀ-ÿ\\p{Script=Han}]+[a-zA-ZÀ-ÿ0-9/\\-_\\p{Script=Han}]*:" +local yaml_re = + "(^|\\s)tags:\\s*\\[\\s*([a-zA-ZÀ-ÿ\\p{Script=Han}]+[a-zA-ZÀ-ÿ0-9/\\-_\\p{Script=Han}]*(,\\s*)*)*\\s*]" local function command_find_all_tags(opts) opts = opts or {} opts.cwd = opts.cwd or "."